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
|
| import storage from '@/utils/storage'
|
| export const state = {
| systemInfo: null
| }
|
| export const mutations = {
| SET_SYSTEM_INFO: (state, value) => {
| state.systemInfo = value
| },
| }
|
| export const actions = {
| // 获取用户终端系统信息
| SystemInfo ({ commit, state }) {
| return new Promise((resolve, reject) => {
| if (state.info) {
| resolve(res)
| } else {
| uni.getSystemInfo({
| success (res) {
| commit('SET_SYSTEM_INFO', res)
| // 信息存入缓存(有效期1天)
| storage.set('SYSTEM_INFO', res, 86400);
| resolve(res)
| },
| fail (err) {
| reject(err)
| }
| })
| }
| })
| },
| }
|
| export const getters = {
|
| getSystemInfo (state) {
| if (state.systemInfo) {
| return state.systemInfo
| } else if (storage.get('SYSTEM_INFO')) {
| return JSON.parse(storage.get('SYSTEM_INFO'))
| }
| return {}
| }
|
| }
|
|