index.js
5.7 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user'
import internship from './modules/internship'
Vue.use(Vuex)
const appNameData = {
'2021004125649367': '智用工',
'wx2a515776284cae17': '新华实习',
}
let lifeData = {};
let appId = '2021004125649367';
// 新华网
// let appId = 'wx2a515776284cae17';
try {
// 尝试获取本地是否存在lifeData变量,第一次启动APP时是不存在的
lifeData = uni.getStorageSync('lifeData');
} catch (e) {
}
// 需要永久存储,且下次APP启动需要取出的,在state中的变量名
let saveStateKeys = [
'vuex_user',
'vuex_tenant',
'vuex_token',
'workai_vuex_token',
'vuex_phone',
'vuex_weixinUserInfo',
'vuex_role',
'vuex_userid',
'vuex_refresh_token',
'vuex_baseImgUrl',
'vuex_theme',
'vuex_expect_job'
];
// 保存变量到本地存储中
const saveLifeData = function (key, value) {
// 判断变量名是否在需要存储的数组中
if (saveStateKeys.indexOf(key) != -1) {
// 获取本地存储的lifeData对象,将变量添加到对象中
let tmp = uni.getStorageSync('lifeData');
// 第一次打开APP,不存在lifeData变量,故放一个{}空对象
tmp = tmp ? tmp : {};
tmp[key] = value;
// 执行这一步后,所有需要存储的变量,都挂载在本地的lifeData对象中
uni.setStorageSync('lifeData', tmp);
}
}
const handleTabBars = function(type) {
const tabBars = [
{
"pagePath": "/pages/student/tabBar/home/home",
"iconPath": "/static/img/common/home.png",
"selectedIconPath": `https://yxlypublic.oss-cn-beijing.aliyuncs.com/WeChat/wx84b71301436652ce/homeHL.png`,
"text": "首页"
},
// {
// "pagePath": "/pages/student/tabBar/internship/internship",
// "iconPath": "/static/img/common/internship.png",
// "selectedIconPath": `https://yxlypublic.oss-cn-beijing.aliyuncs.com/WeChat/${appId}/internshipHL.png`,
// "text": "实习"
// },
// {
// "pagePath": "/pages/student/tabBar/promote/promote",
// "iconPath": "/static/img/common/promote.png",
// "selectedIconPath": `https://yxlypublic.oss-cn-beijing.aliyuncs.com/WeChat/${appId}/promoteHL.png`,
// "text": "提升"
// },
// {
// "pagePath": "/pages/student/tabBar/message/message",
// "iconPath": "/static/img/common/message.png",
// "selectedIconPath": `https://yxlypublic.oss-cn-beijing.aliyuncs.com/WeChat/${appId}/messageHL.png`,
// "text": "消息",
// 'isDot': true,
// 'count': 0,
// },
{
"pagePath": "/pages/student/tabBar/my/my",
"iconPath": "/static/img/common/my.png",
"selectedIconPath": `https://yxlypublic.oss-cn-beijing.aliyuncs.com/WeChat/wx84b71301436652ce/myHL.png`,
"text": "我的"
}
]
// if (appId == 'wx2a515776284cae17') {
// tabBars.splice(2, 1)
// }
// if (type == 'worker') {
// tabBars.splice(1, 1)
// return tabBars
// }
// if (type == 'student') {
// return tabBars
// }
return tabBars
}
const store = new Vuex.Store({
modules: {
user,
internship,
},
state: {
vuex_appId: appId,
vuex_appName: appNameData[appId],
// 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量
// 加上vuex_前缀,是防止变量名冲突,也让人一目了然
vuex_user: lifeData.vuex_user ? lifeData.vuex_user : {},
vuex_tenant: lifeData.vuex_tenant ? lifeData.vuex_tenant : {},
vuex_weixinUserInfo: lifeData.vuex_weixinUserInfo ? lifeData.vuex_weixinUserInfo : {},
vuex_token: lifeData.vuex_token ? lifeData.vuex_token : '',
workai_vuex_token: lifeData.workai_vuex_token ? lifeData.workai_vuex_token : '',
vuex_phone: lifeData.vuex_phone ? lifeData.vuex_phone : '',
vuex_role: lifeData.vuex_role ? lifeData.vuex_role : '',
vuex_userid: lifeData.vuex_userid ? lifeData.vuex_userid : '',
vuex_refresh_token: lifeData.vuex_refresh_token ? lifeData.vuex_refresh_token : '',
// 如果vuex_version无需保存到本地永久存储,无需lifeData.vuex_version方式
vuex_version: '1.0.0',
vuex_noAuth: true,
vuex_demo: '绛紫',
vuex_baseImgUrl: "",
vuex_ossUrl: "https://yxly.oss-cn-beijing.aliyuncs.com",
vuex_ossUrlPubilc: "https://yxlypublic.oss-cn-beijing.aliyuncs.com",
// vuex_ossUrl: "https://oss.workai.com.cn",
vuex_OssInit: {},
vuex_area: {},
vuex_theme: '',
// vuex_theme: this.theme,
// 自定义tabbar数据
vuex_tabbar: handleTabBars('worker'),
vuex_tabbar_inter: handleTabBars('student'),
vuex_expect_job: lifeData.vuex_expect_job ? lifeData.vuex_expect_job : '全部职位',
},
getters: {
doneTenantType: state => {
return state.vuex_tenant && state.vuex_tenant.type ? String(state.vuex_tenant.type) : '';
}
},
mutations: {
$uStore(state, payload) {
// 判断是否多层级调用,state中为对象存在的情况,诸如user.info.score = 1
let nameArr = payload.name.split('.');
let saveKey = '';
let len = nameArr.length;
if (len >= 2) {
let obj = state[nameArr[0]];
for (let i = 1; i < len - 1; i++) {
obj = obj[nameArr[i]];
}
obj[nameArr[len - 1]] = payload.value;
saveKey = nameArr[0];
} else {
// 单层级变量,在state就是一个普通变量的情况
state[payload.name] = payload.value;
saveKey = payload.name;
}
// 保存变量到本地,见顶部函数定义
saveLifeData(saveKey, state[saveKey])
},
setWenxinUserInfo(state, result) {
state.vuex_weixinUserInfo = result.userInfo;
uni.$u.vuex('vuex_weixinUserInfo', result.userInfo);
},
}
})
export default store