commonStore.js
2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import router from '@/router'
export default {
state: {
verificationCount: null,
verificationFlag: null,
lastPath: '',
prevPath: '',
goodsInfo: {},
merchantId: null,
order: {},
address: {}
},
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))
console.log(state.lastPath);
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') {
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)
// router.replace({ name: 'common.nothing' })
// setTimeout(() => {
// state.lastPath?router.replace({ name: state.lastPath }):router.replace({name: 'equity.index'})
// }, 1000)
}
},
}