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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
| import {setToken, setRefreshToken, removeToken, removeRefreshToken} from '@/util/auth'
| import {Message} from 'element-ui'
| import {setStore, getStore} from '@/util/store'
| import {isURL, validatenull} from '@/util/validate'
| import {deepClone} from '@/util/util'
| import website from '@/config/website'
| import {loginByUsername, loginBySocial, loginBySso, getUserInfo, logout, refreshToken, getButtons} from '@/api/user'
| import {getTopMenu, getRoutes} from '@/api/system/menu'
| import md5 from 'js-md5'
|
|
| function addPath(ele, first) {
| const menu = website.menu;
| const propsConfig = menu.props;
| const propsDefault = {
| label: propsConfig.label || 'name',
| path: 'code',
| icon: propsConfig.icon || 'icon',
| children: propsConfig.children || 'children'
| }
| const icon = ele[propsDefault.icon];
| ele[propsDefault.icon] = validatenull(icon) ? menu.iconDefault : icon;
| const isChild = ele[propsDefault.children] && ele[propsDefault.children].length !== 0;
| if (!isChild) ele[propsDefault.children] = [];
| if (!isChild && first && !isURL(ele[propsDefault.path])) {
| ele[propsDefault.path] = ele[propsDefault.path] + '/index'
| } else {
| ele[propsDefault.children].forEach(child => {
| addPath(child);
| })
| }
|
| }
|
|
|
| const user = {
| state: {
| tenantId: getStore({name: 'tenantId'}) || '',
| userInfo: getStore({name: 'userInfo'}) || [],
| permission: getStore({name: 'permission'}) || {},
| roles: [],
| menuId: {},
| menu: getStore({name: 'menu'}) || [],
| menuAll: getStore({name: 'menuAll'}) || [],
| token: getStore({name: 'token'}) || '',
| refreshToken: getStore({name: 'refreshToken'}) || '',
| },
| actions: {
| //根据用户名登录
| LoginByUsername({commit}, userInfo) {
| return new Promise((resolve, reject) => {
| loginByUsername(userInfo.tenantId, userInfo.deptId, userInfo.roleId, userInfo.username, md5(userInfo.password), userInfo.type, userInfo.key, ).then(res => {
| const data = res.data;
| if(data.success){
| debugger;
| commit('SET_TOKEN', data.obj.sessionInfo.token);
| commit('SET_REFRESH_TOKEN', data.obj.sessionInfo.token);
| commit('SET_TENANT_ID', data.tenant_id);
| commit('SET_USER_INFO', data.obj.sessionInfo);
| commit('DEL_ALL_TAG');
| commit('CLEAR_LOCK');
| }else {
| Message({
| message: data.msg,
| type: 'error'
| })
| }
| resolve();
| }).catch(error => {
| reject(error);
| })
| })
| },
| //根据手机号登录
| LoginByPhone({commit}, userInfo) {
| return new Promise((resolve) => {
| loginByUsername(userInfo.phone,
| ).then(res => {
| const data = res.data.data;
| commit('SET_TOKEN', data);
| commit('DEL_ALL_TAG');
| commit('CLEAR_LOCK');
| resolve();
| })
| })
| },
| //根据第三方信息登录
| LoginBySocial({commit}, userInfo) {
| return new Promise((resolve) => {
| loginBySocial(userInfo.tenantId, userInfo.source, userInfo.state).then(res => {
| const data = res.data;
| if (data.error_description) {
| Message({
| message: data.error_description,
| type: 'error'
| })
| } else {
| commit('SET_TOKEN', data.access_token);
| commit('SET_REFRESH_TOKEN', data.refresh_token);
| commit('SET_USER_INFO', data);
| commit('SET_TENANT_ID', data.tenant_id);
| commit('DEL_ALL_TAG');
| commit('CLEAR_LOCK');
| }
| resolve();
| })
| })
| },
| //根据单点信息登录
| LoginBySso({commit}, userInfo) {
| return new Promise((resolve) => {
| loginBySso(userInfo.state,).then(res => {
| const data = res.data;
| if (data.error_description) {
| Message({
| message: data.error_description,
| type: 'error'
| })
| } else {
| commit('SET_TOKEN', data.access_token);
| commit('SET_REFRESH_TOKEN', data.refresh_token);
| commit('SET_USER_INFO', data);
| commit('SET_TENANT_ID', data.tenant_id);
| commit('DEL_ALL_TAG');
| commit('CLEAR_LOCK');
| }
| resolve();
| })
| })
| },
| //获取用户信息
| GetUserInfo({commit}) {
| return new Promise((resolve, reject) => {
| getUserInfo().then((res) => {
| const data = res.data.data;
| commit('SET_ROLES', data.roles);
| resolve(data);
| }).catch(err => {
| reject(err);
| })
| })
| },
| //刷新token
| refreshToken({state, commit}, userInfo) {
| window.console.log('handle refresh token');
| return new Promise((resolve, reject) => {
| refreshToken(state.refreshToken, state.tenantId,
| !validatenull(userInfo) ? userInfo.deptId : state.userInfo.dept_id,
| !validatenull(userInfo) ? userInfo.roleId : state.userInfo.role_id
| ).then(res => {
| const data = res.data;
| commit('SET_TOKEN', data.access_token);
| commit('SET_REFRESH_TOKEN', data.refresh_token);
| commit('SET_USER_INFO', data);
| resolve();
| }).catch(error => {
| reject(error)
| })
| })
| },
| // 登出
| LogOut({commit}) {
| return new Promise((resolve, reject) => {
| logout().then(() => {
| commit('SET_TOKEN', '');
| commit('SET_MENU', []);
| commit('SET_MENU_ALL_NULL', []);
| commit('SET_ROLES', []);
| commit('SET_TAG_LIST', []);
| commit('DEL_ALL_TAG');
| commit('CLEAR_LOCK');
| removeToken();
| removeRefreshToken();
| resolve();
| }).catch(error => {
| reject(error)
| })
| })
| },
| //注销session
| FedLogOut({commit}) {
| return new Promise(resolve => {
| commit('SET_TOKEN', '');
| commit('SET_MENU_ALL_NULL', []);
| commit('SET_MENU', []);
| commit('SET_ROLES', []);
| commit('SET_TAG_LIST', []);
| commit('DEL_ALL_TAG');
| commit('CLEAR_LOCK');
| removeToken();
| removeRefreshToken();
| resolve();
| })
| },
| //获取顶部菜单
| GetTopMenu() {
| return new Promise(resolve => {
| getTopMenu().then((res) => {
| const data = res.data.data || [];
| resolve(data)
| })
| })
| },
| //获取系统菜单
| GetMenu({commit, dispatch}, topMenuId) {
| return new Promise(resolve => {
| getRoutes('modelManagmentNode').then((res) => {
| const list =[
| {
| "action": null,
| "actionName": null,
| "alias": "资源库",
| "category": null,
| "categoryName": null,
| "children": [
| {
| "action": null,
| "actionName": null,
| "alias": "知识库",
| "category": null,
| "categoryName": null,
| "children": [
| {
| "action": null,
| "actionName": null,
| "alias": "resourcelib",
| "category": null,
| "categoryName": null,
| "children": [],
| "code": "resourcelib",
| "hasChildren": false,
| "id": "2C5FABD2-535F-8568-8E61-C643BA7D77A1",
| "isOpen": null,
| "isOpenName": null,
| "meta": {
| "keepAlive": false
| },
| "name": "设备资源库",
| "parentId": "9B00AD2C-A407-7F71-B35C-58E466E53A33",
| "parentName": null,
| "path": "bs=test?image=resource&type=folder&context=resourcemanager&querytype=0&querytemplate=resourcelibroot",
| "remark": null,
| "sort": 1,
| "source": ""
| },
| {
| "action": null,
| "actionName": null,
| "alias": "工艺知识库",
| "category": null,
| "categoryName": null,
| "children": [],
| "code": "gongyi",
| "hasChildren": false,
| "id": "AC04E222-F14B-F4FF-11BB-DFE8917A2756",
| "isOpen": null,
| "isOpenName": null,
| "meta": {
| "keepAlive": false
| },
| "name": "工艺知识库",
| "parentId": "9B00AD2C-A407-7F71-B35C-58E466E53A33",
| "parentName": null,
| "path": "bs=UI?image=report&type=folder&context=knowledgemanager&querytype=0&querytemplate=knowledgelibroot",
| "remark": null,
| "sort": 2,
| "source": ""
| }
| ],
| "code": "zhishiku",
| "hasChildren": true,
| "id": "9B00AD2C-A407-7F71-B35C-58E466E53A33",
| "isOpen": null,
| "isOpenName": null,
| "meta": {
| "keepAlive": false
| },
| "name": "知识库",
| "parentId": "4EDC91B8-E3B2-D126-E75C-D2CEC59F53CE",
| "parentName": null,
| "path": "bs=/base",
| "remark": null,
| "sort": 1,
| "source": ""
| },
| {
| "action": null,
| "actionName": null,
| "alias": "TemplateLib",
| "category": null,
| "categoryName": null,
| "children": [
| {
| "action": null,
| "actionName": null,
| "alias": "CardTemplateLib",
| "category": null,
| "categoryName": null,
| "children": [],
| "code": "CardTemplateLib",
| "hasChildren": false,
| "id": "E6E963E7-2DF6-80EE-2A61-FA86E0F3D5F2",
| "isOpen": null,
| "isOpenName": null,
| "meta": {
| "keepAlive": false
| },
| "name": "卡片模板",
| "parentId": "8493A92A-13DA-8800-140D-9C0C4A722665",
| "parentName": null,
| "path": "bs=?image=card&type=folder&context=cardtemplatemanager&querytype=0&querytemplate=cardtemplateroot",
| "remark": null,
| "sort": 1,
| "source": ""
| }
| ],
| "code": "TemplateLib",
| "hasChildren": true,
| "id": "8493A92A-13DA-8800-140D-9C0C4A722665",
| "isOpen": null,
| "isOpenName": null,
| "meta": {
| "keepAlive": false
| },
| "name": "模板库",
| "parentId": "4EDC91B8-E3B2-D126-E75C-D2CEC59F53CE",
| "parentName": null,
| "path": "bs=mb",
| "remark": null,
| "sort": 2,
| "source": ""
| },
| {
| "action": null,
| "actionName": null,
| "alias": "典型数据库",
| "category": null,
| "categoryName": null,
| "children": [
| {
| "action": null,
| "actionName": null,
| "alias": "典型规程",
| "category": null,
| "categoryName": null,
| "children": [],
| "code": "guicheng",
| "hasChildren": false,
| "id": "B3EC1413-1A33-61E3-DDD1-CB4D0CFD0C6E",
| "isOpen": null,
| "isOpenName": null,
| "meta": {
| "keepAlive": false
| },
| "name": "典型规程",
| "parentId": "BDBD6CFA-2F4C-EEF7-C380-5E9BBF6A37B3",
| "parentName": null,
| "path": "bs=?image=typical&type=workorder&context=TypicalProcessLib",
| "remark": null,
| "sort": 1,
| "source": ""
| }
| ],
| "code": "dianxing",
| "hasChildren": true,
| "id": "BDBD6CFA-2F4C-EEF7-C380-5E9BBF6A37B3",
| "isOpen": null,
| "isOpenName": null,
| "meta": {
| "keepAlive": false
| },
| "name": "典型数据库",
| "parentId": "4EDC91B8-E3B2-D126-E75C-D2CEC59F53CE",
| "parentName": null,
| "path": "bs=dx",
| "remark": null,
| "sort": 3,
| "source": ""
| }
| ],
| "code": "ziyuanku",
| "hasChildren": true,
| "id": "4EDC91B8-E3B2-D126-E75C-D2CEC59F53CE",
| "isOpen": null,
| "isOpenName": null,
| "meta": {
| "keepAlive": false
| },
| "name": "资源库",
| "parentId": "modelManagmentNode",
| "parentName": null,
| "path": "bs=zy",
| "remark": null,
| "sort": 913,
| "source": ""
| }
| ];
| const data = res.data.obj;
| let menu = deepClone(list);
| menu.forEach(ele => {
| addPath(ele, true);
| });
| updateCode(menu)
| function updateCode(items) {
| items.forEach(item => {
| // 将字符串分割成数组,以'?'作为分隔符
| let parts = item.path.split("?");
| // 如果数组的长度大于1,表示有'?',则取第一个元素的第一个部分,否则直接取整个字符串
| let bsValue = parts.length > 1 ? parts[0].split("=")[1] : item.path.split("=")[1];
| if (bsValue ==='' || bsValue === undefined || bsValue === null) {
| bsValue = "UI";
| }
| item.path = bsValue === 'UI' ? '/base/UIContentViewer' : `/custom-ui/${bsValue}`;
| // 如果children不为空,递归调用这个函数
| if (item.children && item.children.length > 0) {
| updateCode(item.children);
| }
| });
| }
| commit('SET_MENU_ALL', menu)
| commit('SET_MENU', menu)
| //dispatch('GetButtons');s
| resolve(menu)
| })
| })
| },
| //获取系统按钮
| GetButtons({commit}) {
| return new Promise((resolve) => {
| getButtons().then(res => {
| const data = res.data.data;
| commit('SET_PERMISSION', data);
| resolve();
| })
| })
| },
| },
| mutations: {
| SET_TOKEN: (state, token) => {
| debugger;
| setToken(token);
| state.token = token;
| setStore({name: 'token', content: state.token})
| },
| SET_MENU_ID(state, menuId) {
| state.menuId = menuId;
| },
| SET_MENU_ALL: (state, menuAll) => {
| let menu = state.menuAll;
| menuAll.forEach(ele => {
| if (!menu.find(item => item.label === ele.label && item.path === ele.path)) {
| menu.push(ele);
| }
| })
| state.menuAll = menu
| setStore({ name: 'menuAll', content: state.menuAll })
| },
| SET_MENU_ALL_NULL: (state) => {
| state.menuAll = []
| setStore({ name: 'menuAll', content: state.menuAll })
| },
| SET_MENU: (state, menu) => {
| state.menu = menu
| setStore({ name: 'menu', content: state.menu })
| },
| SET_REFRESH_TOKEN: (state, refreshToken) => {
| setRefreshToken(refreshToken)
| state.refreshToken = refreshToken;
| setStore({name: 'refreshToken', content: state.refreshToken})
| },
| SET_TENANT_ID: (state, tenantId) => {
| state.tenantId = tenantId;
| setStore({name: 'tenantId', content: state.tenantId})
| },
| SET_USER_INFO: (state, userInfo) => {
| if (validatenull(userInfo.avatar)) {
| userInfo.avatar = "/img/bg/img-logo.png";
| }
| state.userInfo = userInfo;
| setStore({name: 'userInfo', content: state.userInfo})
| },
| SET_ROLES: (state, roles) => {
| state.roles = roles;
| },
|
| }
|
| }
| export default user
|
|