common.js
1.52 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
import { NativeApi } from '@/api/NativeApis'
const AppInfo = {
versionCode: 100,
versionName: '2.1',
statusBarHeight: 0,
sourceFlag: false,
}
export default {
namespaced: true,
state: {
AppInfo: { ...AppInfo },
keepAlives: ['Home']
},
mutations: {
MSetAppInfo(state, data) {
Object.assign(state.AppInfo, data)
},
MSaveKeepAlive(state, data) {
if (data) {
const index = state.keepAlives.indexOf(data)
if (index <= -1) {
state.keepAlives.push(data)
}
}
},
MRemoveKeepAlive(state, data) {
if (data) {
const index = state.keepAlives.indexOf(data)
if (index > -1) {
state.keepAlives.splice(index, 1)
}
}
},
},
actions: {
AGetAppInfo({ state, commit }) {
if (state.AppInfo.sourceFlag) {
return
}
NativeApi.nativeAppInfo({}).then(res => {
if (res.data) {
Object.assign(res.data, { sourceFlag: true })
}
commit('MSetAppInfo', res.data)
}).catch(e => {
commit('MSetAppInfo', AppInfo)
})
}
},
getters: {
GStatusBarHeight(state) {
return state.AppInfo.statusBarHeight
},
GKeepAlives(state) {
return state.keepAlives
}
}
}