commonStore.js 1.55 KB
import router from '@/router'
export default {
  state: {
    verificationCount: null,
    verificationFlag: null,
    lastPath: '',
  },
  mutations: {
    setUserInfo(state, newVal) {
      Object.keys(newVal).map(key => {
        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 == 'common/index') {
              route = ''
            } else {
              if (!newVal.phone && route != 'device/index') {
                router.replace({ name: 'common.phoneLogin' })
                return
              }
            }
            window.location.href = `${window.location.href.split('?')[0]}#/${route}`
            return
          }
        }
      }
    },
    setVerificationCount(state, newVal) {
      state.verificationCount = newVal
    },
    setVerificationFlag(state, newVal) {
      state.verificationFlag = newVal
    },
    jumpPath(state, newVal) {
      state.lastPath = newVal
    },
    clearSessionId(state) {
      state.sessionId = ''
      router.replace({ name: 'common.index' })
    },
    reload(state) {
      router.replace({ name: 'common.nothing' })
      setTimeout(() => {
        router.replace({ name: state.lastPath })
      }, 100)
    }
  },
}