commonStore.js 3.74 KB
import router from '@/router'
export default {
  state: {
    verificationCount: null,
    verificationFlag: null,
    lastPath: '',
    prevPath: '',
    goodsInfo: {},
    merchantId: null,
    order: {},
    address: {},
    //保存首页的数据-避免重复刷新
    //门店信息
    shopInfo: {},
    //金刚区
    menuInfo: [],
    //门店服务
    serverInfo: [],
    //分享链接
    shareInfo: {},
    //是否关注公众号
    concernInfo: null,
    //精选数据
    highInfo: [],
    //直充列表
    chargeList: [],
    //卡券列表
    cardList: []
  },
  mutations: {
    setUserInfo(state, newVal) {
      Object.keys(newVal).map(key => {
        if (key == 'sessionId' && newVal[key].indexOf('-') == -1) {
          return
        }
        if (newVal[key]) state[key] = newVal[key]
      })
      const ua = navigator.userAgent.toLowerCase()
      if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        let userInfo = sessionStorage.getItem('GL_EQUITY_USER_INFO')
        if (!userInfo) {
          sessionStorage.setItem('GL_EQUITY_USER_INFO', JSON.stringify(state))
          if (state.lastPath) {
            let route = state.lastPath.replace('.', '/')
            if (route == 'equity/index') {
              route = ''
              history.back() //去掉历史记录,重复页面
                //router.replace({ name: 'common.marketing' })
                //window.location.replace(`${window.location.href.split('?')[0]}#/${route}`)
              return
            } else {
              if (!newVal.phone && route != 'device/index') {
                if (window.__wxjs_environment == 'miniprogram') {
                  router.replace({ name: 'equity.index' })
                } else {
                  router.replace({ name: 'common.phoneLogin' })
                }
                return
              }
            }
            window.location.href = `${window.location.href.split('?')[0]}#/${route}`
            return
          } else {
            let route = state.lastPath.replace('.', '/')
            window.location.href = `${window.location.href.split('?')[0]}#/${route}`
          }
        }
      }
    },
    setMerchantId(state, newVal) {
      state.merchantId = newVal;
    },
    setOrder(state, newVal) {
      state.order = newVal;
    },
    setAddress(state, newVal) {
      state.address = newVal;
    },
    setGoodsInfo(state, newVal) {
      state.goodsInfo = newVal;
      sessionStorage.setItem('GL_GOODS_INFO', JSON.stringify(newVal))
    },
    setVerificationCount(state, newVal) {
      state.verificationCount = newVal
    },
    setVerificationFlag(state, newVal) {
      state.verificationFlag = newVal
    },
    jumpPath(state, newVal) {
      state.lastPath = newVal
    },
    findPrevPath(state, newVal) {
      state.prevPath = newVal
    },
    clearSessionId(state) {
      state.sessionId = ''
      router.replace({ name: 'common.marketing' })
    },
    reload(state) {
      console.log(state, 'storeRelod方法,已译注');
      // router.replace({ name: 'common.nothing' })
      // setTimeout(() => {
      //   state.lastPath?router.replace({ name: state.lastPath }):router.replace({name: 'equity.index'})
      // }, 1000)
    },
    setShopInfo(state, newVal) {
      state.shopInfo = newVal
    },
    setMenuInfo(state, newVal) {
      state.menuInfo = newVal
    },
    setServerInfo(state, newVal) {
      state.serverInfo = newVal
    },
    setShareInfo(state, newVal) {
      state.shareInfo = newVal
    },
    setConcernInfo(state, newVal) {
      state.concernInfo = newVal
    },
    setHighInfo(state, newVal) {
      state.highInfo = newVal
    },
    setchargeInfo(state, newVal) {
      state.chargeList = newVal
    },
    setcardsInfo(state, newVal) {
      state.cardList = newVal
    },
  },
}