app.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { CHANGE_IS_IN_MINIPROGRAM, CHANGE_SYSTERM_INFO, CHANGE_SYSTERM_TERMINAL } from './type'
  2. import { isInWx, isH5InWebview } from '../../utils'
  3. export default {
  4. namespaced: true,
  5. state() {
  6. return {
  7. isInMiniProgram: false, // 是否套壳的
  8. systermInfo: {},
  9. terminal: 0,
  10. platformOperationShopId: 186
  11. }
  12. },
  13. mutations: {
  14. [CHANGE_IS_IN_MINIPROGRAM](state, tag) {
  15. if (tag) {
  16. state.isInMiniProgram = tag
  17. }
  18. },
  19. [CHANGE_SYSTERM_INFO](state, system) {
  20. state.systermInfo = system
  21. console.log(system)
  22. },
  23. [CHANGE_SYSTERM_TERMINAL](state, terminal) {
  24. state.terminal = terminal
  25. }
  26. },
  27. actions: {
  28. getUserSystermInfo({ commit }) {
  29. return new Promise((resolve, reject) => {
  30. uni.getSystemInfo({
  31. success: (systermInfo) => {
  32. commit(CHANGE_SYSTERM_INFO, systermInfo)
  33. resolve()
  34. },
  35. fail: () => {
  36. commit(CHANGE_SYSTERM_INFO, {})
  37. resolve()
  38. }
  39. })
  40. })
  41. },
  42. getSystermTerminal({ state, dispatch, commit }) {
  43. return new Promise((resolve, reject) => {
  44. if (isInWx()) {
  45. if (state.isInMiniProgram || isH5InWebview()) {
  46. commit(CHANGE_SYSTERM_TERMINAL, 6)
  47. } else {
  48. commit(CHANGE_SYSTERM_TERMINAL, 3)
  49. }
  50. } else {
  51. // #ifdef H5
  52. commit(CHANGE_SYSTERM_TERMINAL, 5) // H5包含pc和移动端浏览器和微信浏览器的可能
  53. // #endif
  54. // #ifdef APP
  55. commit(CHANGE_SYSTERM_TERMINAL, 1)
  56. // #endif
  57. // #ifdef MP-WEIXIN
  58. commit(CHANGE_SYSTERM_TERMINAL, 2)
  59. // #endif
  60. // #ifdef MP-ALIPAY
  61. commit(CHANGE_SYSTERM_TERMINAL, 4)
  62. // #endif
  63. }
  64. })
  65. }
  66. }
  67. }