@skyfox2000/webui 1.2.6 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +441 -91
- package/lib/assets/modules/{file-upload-Cf9uxE2y.js → file-upload-D4bA7go8.js} +1 -1
- package/lib/assets/modules/{form-excel-DnROEQ0w.js → form-excel-DL2_SNiS.js} +1 -1
- package/lib/assets/modules/{index-BkbOMv2e.js → index-BZvwPKou.js} +1 -1
- package/lib/assets/modules/{index-D4mESG0b.js → index-CKMDsqve.js} +683 -661
- package/lib/assets/modules/{index-DvbJb5Ha.js → index-D16E7UbH.js} +2 -2
- package/lib/assets/modules/{menuTabs-DgX7pUbX.js → menuTabs-izaFx0kk.js} +196 -175
- package/lib/assets/modules/{toolIcon-C0bp66dj.js → toolIcon-66dclHit.js} +1 -1
- package/lib/assets/modules/{uploadList-CWhqNLX9.js → uploadList-Dw6eRrJT.js} +3 -3
- package/lib/components/common/icon/index.vue.d.ts +1 -1
- package/lib/es/AceEditor/index.js +3 -3
- package/lib/es/BasicLayout/index.js +3 -3
- package/lib/es/Error403/index.js +1 -1
- package/lib/es/Error404/index.js +1 -1
- package/lib/es/ExcelForm/index.js +4 -4
- package/lib/es/UploadForm/index.js +4 -4
- package/lib/stores/userInfo.d.ts +3 -1
- package/lib/webui.css +1 -1
- package/lib/webui.es.js +279 -290
- package/package.json +2 -2
- package/src/components/layout/header/headerExits.vue +5 -4
- package/src/components/layout/header/index.vue +4 -2
- package/src/components/layout/header/user.vue +4 -1
- package/src/directives/permission.ts +6 -2
- package/src/stores/appInfo.ts +64 -26
- package/src/stores/pageInfo.ts +1 -0
- package/src/stores/settingInfo.ts +1 -7
- package/src/stores/userInfo.ts +77 -52
- package/src/utils/main-openapis.ts +1 -9
package/package.json
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
import { ref } from 'vue';
|
|
3
3
|
import { Modal, Flex } from 'ant-design-vue';
|
|
4
4
|
import { mainAppApis } from '@skyfox2000/microbase';
|
|
5
|
-
import { ToolIcon } from '../../common';
|
|
5
|
+
import { ToolIcon, Tooltip } from '../../common';
|
|
6
6
|
import { useUserInfo } from '@/index';
|
|
7
7
|
|
|
8
8
|
const userInfoStore = useUserInfo();
|
|
9
|
-
|
|
10
9
|
const open = ref(false);
|
|
11
10
|
const confirmExit = () => {
|
|
12
11
|
open.value = false;
|
|
@@ -18,11 +17,13 @@ const confirmExit = () => {
|
|
|
18
17
|
};
|
|
19
18
|
</script>
|
|
20
19
|
<template>
|
|
21
|
-
<
|
|
20
|
+
<Tooltip title="退出平台">
|
|
21
|
+
<ToolIcon icon="icon-logout" @click="open = true" clickable class="w-5 h-5" title="退出系统" />
|
|
22
|
+
</Tooltip>
|
|
22
23
|
<Modal v-model:open="open" title="确定退出?" ok-text="确定" cancel-text="取消" :width="380" @ok="confirmExit">
|
|
23
24
|
<Flex align="center" justify="flex-start" :style="{ padding: '0 32px', margin: '20px 0' }">
|
|
24
25
|
<ToolIcon icon="icon-question-circle" color="orange" class="w-[60px] h-[60px]" />
|
|
25
|
-
<div style="margin: 0 0 0 20px; font-weight: 400; font-size: 16px"
|
|
26
|
+
<div style="margin: 0 0 0 20px; font-weight: 400; font-size: 16px">是否退出平台,<br />清除用户缓存信息?</div>
|
|
26
27
|
</Flex>
|
|
27
28
|
</Modal>
|
|
28
29
|
</template>
|
|
@@ -5,6 +5,7 @@ import { ToolIcon } from '../../common';
|
|
|
5
5
|
import Breadcrumb from '../breadcrumb/index.vue';
|
|
6
6
|
import HeaderExits from './headerExits.vue';
|
|
7
7
|
import User from './user.vue';
|
|
8
|
+
import DateTime from '../datetime/index.vue';
|
|
8
9
|
|
|
9
10
|
const { useToken } = theme;
|
|
10
11
|
const { token } = useToken();
|
|
@@ -21,7 +22,7 @@ const onCollapseClick = () => {
|
|
|
21
22
|
height: '40px',
|
|
22
23
|
lineHeight: '1',
|
|
23
24
|
paddingLeft: '10px',
|
|
24
|
-
paddingRight: '
|
|
25
|
+
paddingRight: '20px',
|
|
25
26
|
backgroundColor: token.colorBgContainer,
|
|
26
27
|
}"
|
|
27
28
|
>
|
|
@@ -37,7 +38,8 @@ const onCollapseClick = () => {
|
|
|
37
38
|
</div>
|
|
38
39
|
<div>
|
|
39
40
|
<Space size="middle" class="flex items-center">
|
|
40
|
-
<
|
|
41
|
+
<DateTime />
|
|
42
|
+
<User />
|
|
41
43
|
<HeaderExits />
|
|
42
44
|
</Space>
|
|
43
45
|
</div>
|
|
@@ -6,6 +6,9 @@ const userInfo = useUserInfo().userInfo;
|
|
|
6
6
|
</script>
|
|
7
7
|
<template>
|
|
8
8
|
<Tooltip :title="userInfo.Name">
|
|
9
|
-
<
|
|
9
|
+
<div class="flex items-center flex-nowrap">
|
|
10
|
+
<span class="mr-2 text-sm whitespace-nowrap">{{ userInfo.Name }}</span>
|
|
11
|
+
<AppIcon icon="icon-account" />
|
|
12
|
+
</div>
|
|
10
13
|
</Tooltip>
|
|
11
14
|
</template>
|
|
@@ -93,8 +93,12 @@ const checkPermission = (params: PermissionParams): boolean => {
|
|
|
93
93
|
let hasPermitPermission = false;
|
|
94
94
|
|
|
95
95
|
// 检查角色权限
|
|
96
|
-
if (!isEmpty(role)
|
|
97
|
-
hasRolePermission = userInfoStore.hasRole(role);
|
|
96
|
+
if (!isEmpty(role)) {
|
|
97
|
+
hasRolePermission = userInfoStore.hasRole(role!);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (userInfoStore.isAdmin()) {
|
|
101
|
+
return hasRolePermission;
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
// 检查功能权限
|
package/src/stores/appInfo.ts
CHANGED
|
@@ -8,16 +8,18 @@ import {
|
|
|
8
8
|
isMicroApp,
|
|
9
9
|
mainAppApis,
|
|
10
10
|
RouteRecord,
|
|
11
|
+
EnvConfig,
|
|
11
12
|
} from '@skyfox2000/microbase';
|
|
12
13
|
import AppRouter, { addAppRoutes, continueNavigation, flattenRoute, LOGIN_PATH } from '@/router';
|
|
13
14
|
import { usePageInfo } from './pageInfo';
|
|
15
|
+
import { isEmpty } from '@/utils/isEmpty';
|
|
14
16
|
|
|
15
17
|
import { Component, h, nextTick } from 'vue';
|
|
16
18
|
import { useUserInfo } from './userInfo';
|
|
17
19
|
import { ApiResponse, httpPost, IUrlInfo, ResStatus } from '@skyfox2000/fapi';
|
|
18
20
|
import message from 'vue-m-message';
|
|
19
21
|
|
|
20
|
-
const APPINFO_STORE_KEY = 'appInfoStore';
|
|
22
|
+
// const APPINFO_STORE_KEY = 'appInfoStore';
|
|
21
23
|
|
|
22
24
|
/** 授权应用相关接口 */
|
|
23
25
|
const AppUrlList: {
|
|
@@ -35,31 +37,68 @@ const AppUrlList: {
|
|
|
35
37
|
// 定义一个映射,用于存储不同路由路径对应的组件包装器
|
|
36
38
|
const wrapperMap = new Map<string, Component>();
|
|
37
39
|
|
|
40
|
+
/**
|
|
41
|
+
* 检查路由权限
|
|
42
|
+
* @param route 路由信息
|
|
43
|
+
* @returns 是否有权限访问
|
|
44
|
+
*/
|
|
45
|
+
const checkRoutePermission = (route: RouteRecord): boolean => {
|
|
46
|
+
const userInfoStore = useUserInfo();
|
|
47
|
+
const { roles, permission }: { roles?: string | string[]; permission?: string } = route.meta || {};
|
|
48
|
+
// 如果都没有配置,默认允许访问
|
|
49
|
+
if (isEmpty(roles) && isEmpty(permission)) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (EnvConfig.VITE_PERMISSION_MODE === 'role') {
|
|
54
|
+
// 仅判断角色权限
|
|
55
|
+
if (!isEmpty(roles) && roles) {
|
|
56
|
+
return userInfoStore.hasRole(roles);
|
|
57
|
+
}
|
|
58
|
+
// 如果没有配置角色,默认允许访问
|
|
59
|
+
return true;
|
|
60
|
+
} else if (EnvConfig.VITE_PERMISSION_MODE === 'permit') {
|
|
61
|
+
// 角色和权限任意一个有效即可
|
|
62
|
+
let hasRolePermission = false;
|
|
63
|
+
let hasPermitPermission = false;
|
|
64
|
+
|
|
65
|
+
// 检查角色权限
|
|
66
|
+
if (!isEmpty(roles) && roles) {
|
|
67
|
+
hasRolePermission = userInfoStore.hasRole(roles);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 如果是管理员,只需要检查角色权限
|
|
71
|
+
if (userInfoStore.isAdmin()) {
|
|
72
|
+
return hasRolePermission;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 检查功能权限
|
|
76
|
+
if (!isEmpty(permission) && permission) {
|
|
77
|
+
hasPermitPermission = userInfoStore.hasPermit(route.path, permission);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 任意一个有权限即可
|
|
81
|
+
return hasRolePermission || hasPermitPermission;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 默认不允许访问
|
|
85
|
+
return false;
|
|
86
|
+
};
|
|
87
|
+
|
|
38
88
|
// 根据用户权限过滤路由
|
|
39
|
-
const filterRoutes = (routes: RouteRecord[]
|
|
89
|
+
const filterRoutes = (routes: RouteRecord[]) => {
|
|
40
90
|
return routes
|
|
41
91
|
.map((route) => {
|
|
42
92
|
// 创建路由对象的副本
|
|
43
93
|
const routeCopy = { ...route };
|
|
44
94
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
if (routeCopy.children) {
|
|
48
|
-
routeCopy.children = filterRoutes(routeCopy.children, userInfoStore);
|
|
49
|
-
}
|
|
50
|
-
return routeCopy;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// 如果配置了角色或权限,满足任意一个条件即可
|
|
54
|
-
const hasRole = routeCopy.meta?.roles?.length ? userInfoStore.hasRole(routeCopy.meta.roles) : false;
|
|
55
|
-
const hasPermission = routeCopy.meta?.permission?.length
|
|
56
|
-
? userInfoStore.hasPermit(routeCopy.meta.permission, ':page')
|
|
57
|
-
: false;
|
|
95
|
+
// 检查路由权限
|
|
96
|
+
const hasPermission = checkRoutePermission(routeCopy);
|
|
58
97
|
|
|
59
98
|
// 如果当前路由有权限访问
|
|
60
|
-
if (
|
|
99
|
+
if (hasPermission) {
|
|
61
100
|
if (routeCopy.children) {
|
|
62
|
-
routeCopy.children = filterRoutes(routeCopy.children
|
|
101
|
+
routeCopy.children = filterRoutes(routeCopy.children);
|
|
63
102
|
}
|
|
64
103
|
return routeCopy;
|
|
65
104
|
}
|
|
@@ -262,8 +301,8 @@ export const useAppInfo = defineStore('appInfo', {
|
|
|
262
301
|
|
|
263
302
|
if (!isMicroApp() || !isBaseMicroApp()) {
|
|
264
303
|
/// 非基座应用,获取用户应用权限
|
|
304
|
+
const userInfoStore = useUserInfo();
|
|
265
305
|
/// 获取用户应用权限
|
|
266
|
-
const userInfoStore = await useUserInfo();
|
|
267
306
|
await userInfoStore.getRolePermits(appInfo.Id);
|
|
268
307
|
|
|
269
308
|
if (this.appInfo.Routes.length) this.setAppRoutes(this.appInfo.Routes);
|
|
@@ -304,13 +343,16 @@ export const useAppInfo = defineStore('appInfo', {
|
|
|
304
343
|
});
|
|
305
344
|
|
|
306
345
|
/// 根据用户权限过滤菜单
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const filteredRoutes = filterRoutes(this.appInfo.Routes, userInfoStore as any);
|
|
346
|
+
if (useUserInfo().isLogin) {
|
|
347
|
+
const filteredRoutes = filterRoutes(this.appInfo.Routes);
|
|
310
348
|
addAppRoutes(filteredRoutes);
|
|
311
349
|
this.appInfo.defaultPage = findFirstPage(filteredRoutes) || '';
|
|
312
350
|
if (this.appInfo.defaultPage) {
|
|
313
351
|
this.menuLoaded = true;
|
|
352
|
+
if (mainAppApis.value && mainAppApis.value.mainAppPush) {
|
|
353
|
+
const fullPath = this.formatRoute(this.appInfo.defaultPage);
|
|
354
|
+
mainAppApis.value.mainAppPush(fullPath);
|
|
355
|
+
}
|
|
314
356
|
continueNavigation(this.appInfo.defaultPage);
|
|
315
357
|
}
|
|
316
358
|
}
|
|
@@ -457,9 +499,5 @@ export const useAppInfo = defineStore('appInfo', {
|
|
|
457
499
|
}
|
|
458
500
|
},
|
|
459
501
|
},
|
|
460
|
-
persist:
|
|
461
|
-
key: APPINFO_STORE_KEY,
|
|
462
|
-
storage: localStorage,
|
|
463
|
-
pick: ['appList'],
|
|
464
|
-
},
|
|
502
|
+
persist: false,
|
|
465
503
|
});
|
package/src/stores/pageInfo.ts
CHANGED
|
@@ -2,8 +2,6 @@ import { SettingInfo } from '@skyfox2000/microbase';
|
|
|
2
2
|
|
|
3
3
|
import { defineStore } from 'pinia';
|
|
4
4
|
|
|
5
|
-
const SETTINGINFO_STORE_KEY = 'settingInfoStore';
|
|
6
|
-
|
|
7
5
|
export const useSettingInfo = defineStore('settingInfo', {
|
|
8
6
|
state: (): SettingInfo => ({
|
|
9
7
|
fullscreen: false,
|
|
@@ -45,9 +43,5 @@ export const useSettingInfo = defineStore('settingInfo', {
|
|
|
45
43
|
});
|
|
46
44
|
},
|
|
47
45
|
},
|
|
48
|
-
persist:
|
|
49
|
-
key: SETTINGINFO_STORE_KEY,
|
|
50
|
-
storage: localStorage,
|
|
51
|
-
pick: ['fullscreen', 'menuCollapse', 'tableColumns'],
|
|
52
|
-
},
|
|
46
|
+
persist: false,
|
|
53
47
|
});
|
package/src/stores/userInfo.ts
CHANGED
|
@@ -5,8 +5,6 @@ import { LoginInfo, UserInfo } from '@skyfox2000/microbase';
|
|
|
5
5
|
import { ref } from 'vue';
|
|
6
6
|
import { useAppInfo } from './appInfo';
|
|
7
7
|
|
|
8
|
-
const USERINFO_STORE_KEY = 'userInfoStore';
|
|
9
|
-
|
|
10
8
|
const TokenError = 'Token解析失败';
|
|
11
9
|
const LoginExpired = '登录过期,请重新登录';
|
|
12
10
|
|
|
@@ -45,7 +43,9 @@ const LoginUrlList: {
|
|
|
45
43
|
*/
|
|
46
44
|
const loginApi = <T>(loginInfo: LoginInfo): Promise<ApiResponse<T> | null | undefined> => {
|
|
47
45
|
let loginParams: ReqParams = {
|
|
48
|
-
Option: {
|
|
46
|
+
Option: {
|
|
47
|
+
Mode: 'MicroApp',
|
|
48
|
+
},
|
|
49
49
|
Query: loginInfo,
|
|
50
50
|
};
|
|
51
51
|
|
|
@@ -57,20 +57,6 @@ const loginApi = <T>(loginInfo: LoginInfo): Promise<ApiResponse<T> | null | unde
|
|
|
57
57
|
});
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
/**
|
|
61
|
-
* 界面授权信息接口
|
|
62
|
-
*/
|
|
63
|
-
interface AuthInfo {
|
|
64
|
-
/** 应用ID */
|
|
65
|
-
appId: string;
|
|
66
|
-
/** 用户角色级别 */
|
|
67
|
-
level: string;
|
|
68
|
-
/** 权限信息 */
|
|
69
|
-
permits: Record<string, string[]>;
|
|
70
|
-
/** 最后更新时间 */
|
|
71
|
-
lastTime: number;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
60
|
/**
|
|
75
61
|
* 获取用户界面授权
|
|
76
62
|
* @param appId 应用ID
|
|
@@ -180,8 +166,26 @@ interface UserState {
|
|
|
180
166
|
refreshToken?: string;
|
|
181
167
|
}
|
|
182
168
|
|
|
169
|
+
/**
|
|
170
|
+
* 界面授权信息接口
|
|
171
|
+
*/
|
|
172
|
+
interface AuthInfo {
|
|
173
|
+
/** 应用ID */
|
|
174
|
+
appId: string;
|
|
175
|
+
/** 权限信息 */
|
|
176
|
+
permits: Record<string, string[]>;
|
|
177
|
+
/** 最后更新时间 */
|
|
178
|
+
lastTime: number;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** 用户角色级别 */
|
|
182
|
+
const userLevel = ref<string>('');
|
|
183
183
|
/** 授权信息(私有) */
|
|
184
|
+
/** 应用ID
|
|
185
|
+
* 这是子应用,不可能有多个应用
|
|
186
|
+
*/
|
|
184
187
|
const auth = ref<AuthInfo | null>(null);
|
|
188
|
+
|
|
185
189
|
/**
|
|
186
190
|
* 当前登录用户信息
|
|
187
191
|
*/
|
|
@@ -193,23 +197,12 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
193
197
|
Name: '',
|
|
194
198
|
Code: '',
|
|
195
199
|
TenantId: null,
|
|
196
|
-
UserLevel: '
|
|
200
|
+
UserLevel: '',
|
|
197
201
|
},
|
|
198
202
|
token: '',
|
|
199
203
|
refreshToken: '',
|
|
200
204
|
}),
|
|
201
205
|
actions: {
|
|
202
|
-
/**
|
|
203
|
-
* 启动时初始化用户信息
|
|
204
|
-
*/
|
|
205
|
-
init() {
|
|
206
|
-
if (this.token && this.isLogin) {
|
|
207
|
-
checkToken(this.token, () => this.clean());
|
|
208
|
-
setToken(this.token);
|
|
209
|
-
} else {
|
|
210
|
-
this.clean();
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
206
|
/**
|
|
214
207
|
* 登录操作
|
|
215
208
|
* @param loginInfo 登录信息
|
|
@@ -228,10 +221,12 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
228
221
|
this.isLogin = true;
|
|
229
222
|
|
|
230
223
|
if (expandUser(loginInfo)) {
|
|
224
|
+
// 用户信息不显示用户级别,必须通过接口获取
|
|
231
225
|
this.userInfo = {
|
|
232
226
|
...this.userInfo,
|
|
233
227
|
...loginInfo.UserInfo!,
|
|
234
228
|
};
|
|
229
|
+
userLevel.value = loginInfo.UserInfo!.UserLevel;
|
|
235
230
|
} else {
|
|
236
231
|
message.error('用户信息解析失败');
|
|
237
232
|
return;
|
|
@@ -239,7 +234,7 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
239
234
|
|
|
240
235
|
// 加载子应用
|
|
241
236
|
if (redirect) {
|
|
242
|
-
const appInfoStore =
|
|
237
|
+
const appInfoStore = useAppInfo();
|
|
243
238
|
appInfoStore.toDefaultApp();
|
|
244
239
|
}
|
|
245
240
|
}
|
|
@@ -262,14 +257,13 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
262
257
|
}
|
|
263
258
|
|
|
264
259
|
try {
|
|
265
|
-
const result = await getRolePermitsApi<AuthInfo>(appId);
|
|
260
|
+
const result: AuthInfo | null | undefined = await getRolePermitsApi<AuthInfo>(appId);
|
|
266
261
|
if (result) {
|
|
267
262
|
// 保存授权信息到内存中
|
|
268
263
|
auth.value = {
|
|
269
264
|
appId: appId,
|
|
270
|
-
level: this.userInfo.UserLevel,
|
|
271
265
|
permits: (result as AuthInfo).permits || [],
|
|
272
|
-
lastTime:
|
|
266
|
+
lastTime: result.lastTime,
|
|
273
267
|
};
|
|
274
268
|
|
|
275
269
|
return true;
|
|
@@ -288,25 +282,27 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
288
282
|
* @returns 是否有角色权限
|
|
289
283
|
*/
|
|
290
284
|
hasRole(role: string | string[]): boolean {
|
|
291
|
-
if (!
|
|
285
|
+
if (!userLevel.value) {
|
|
292
286
|
return false;
|
|
293
287
|
}
|
|
294
288
|
if (Array.isArray(role)) {
|
|
295
|
-
return role.includes(
|
|
289
|
+
return role.includes(userLevel.value);
|
|
296
290
|
}
|
|
297
|
-
return
|
|
291
|
+
return userLevel.value === role;
|
|
298
292
|
},
|
|
299
293
|
|
|
300
294
|
/**
|
|
301
295
|
* 检查功能权限
|
|
296
|
+
* @param url 所在页面
|
|
302
297
|
* @param permitCode 资源权限编码
|
|
303
298
|
* @returns 是否有功能权限
|
|
304
299
|
*/
|
|
305
300
|
hasPermit(url: string, permitCode: string): boolean {
|
|
306
|
-
|
|
301
|
+
const authInfo = auth.value;
|
|
302
|
+
if (!authInfo || !authInfo.permits) {
|
|
307
303
|
return false;
|
|
308
304
|
}
|
|
309
|
-
return
|
|
305
|
+
return authInfo.permits[url]?.includes(permitCode) ?? false;
|
|
310
306
|
},
|
|
311
307
|
|
|
312
308
|
/**
|
|
@@ -317,19 +313,29 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
317
313
|
return this.userInfo;
|
|
318
314
|
},
|
|
319
315
|
|
|
316
|
+
/**
|
|
317
|
+
* 设置用户信息
|
|
318
|
+
* 仅允许设置一次,启动时设置,避免通过其它方式设置
|
|
319
|
+
* @param userInfo 用户信息
|
|
320
|
+
* @param token 用户Token
|
|
321
|
+
*/
|
|
320
322
|
setUserInfo(userInfo: UserInfo, token: string) {
|
|
321
323
|
if (!checkToken(token)) {
|
|
322
324
|
this.clean();
|
|
323
325
|
return;
|
|
324
326
|
}
|
|
325
327
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
328
|
+
if (!userLevel.value) {
|
|
329
|
+
// 仅允许设置一次,启动时设置,避免通过其它方式设置
|
|
330
|
+
userLevel.value = userInfo.UserLevel;
|
|
331
|
+
this.userInfo = {
|
|
332
|
+
...this.userInfo,
|
|
333
|
+
...userInfo,
|
|
334
|
+
};
|
|
335
|
+
this.token = token;
|
|
336
|
+
setToken(this.token);
|
|
337
|
+
this.isLogin = true;
|
|
338
|
+
}
|
|
333
339
|
},
|
|
334
340
|
|
|
335
341
|
/**
|
|
@@ -348,6 +354,28 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
348
354
|
return '';
|
|
349
355
|
},
|
|
350
356
|
|
|
357
|
+
/**
|
|
358
|
+
* 是否超级管理员
|
|
359
|
+
*/
|
|
360
|
+
isSuperAdmin(): boolean {
|
|
361
|
+
return userLevel.value === 'Super';
|
|
362
|
+
},
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* 是否管理员
|
|
366
|
+
*/
|
|
367
|
+
isAdmin(): boolean {
|
|
368
|
+
return userLevel.value === 'Super' || userLevel.value === 'Admin';
|
|
369
|
+
},
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* 获取用户级别
|
|
373
|
+
* @returns 用户级别
|
|
374
|
+
*/
|
|
375
|
+
getUserLevel(): string {
|
|
376
|
+
return userLevel.value;
|
|
377
|
+
},
|
|
378
|
+
|
|
351
379
|
/*
|
|
352
380
|
* 清理登录信息
|
|
353
381
|
*/
|
|
@@ -365,9 +393,10 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
365
393
|
this.isLogin = false;
|
|
366
394
|
// 清理授权信息
|
|
367
395
|
auth.value = null;
|
|
396
|
+
userLevel.value = '';
|
|
368
397
|
|
|
369
398
|
// 动态导入并使用appInfo
|
|
370
|
-
const appInfoStore =
|
|
399
|
+
const appInfoStore = useAppInfo();
|
|
371
400
|
appInfoStore.clean();
|
|
372
401
|
return Promise.resolve();
|
|
373
402
|
},
|
|
@@ -391,7 +420,7 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
391
420
|
message.success('已退出登录');
|
|
392
421
|
}, 1000);
|
|
393
422
|
setTimeout(async () => {
|
|
394
|
-
const appInfoStore =
|
|
423
|
+
const appInfoStore = useAppInfo();
|
|
395
424
|
appInfoStore.logout();
|
|
396
425
|
}, 2000);
|
|
397
426
|
}
|
|
@@ -399,9 +428,5 @@ export const useUserInfo = defineStore('userInfo', {
|
|
|
399
428
|
return Promise.resolve();
|
|
400
429
|
},
|
|
401
430
|
},
|
|
402
|
-
persist:
|
|
403
|
-
key: USERINFO_STORE_KEY,
|
|
404
|
-
storage: localStorage,
|
|
405
|
-
pick: ['isLogin', 'userInfo', 'token', 'refreshToken'],
|
|
406
|
-
},
|
|
431
|
+
persist: false,
|
|
407
432
|
});
|
|
@@ -61,12 +61,4 @@ export const getUserInfo = (): UserInfo => {
|
|
|
61
61
|
if (mainAppApis.value && mainAppApis.value.getUserInfo) return mainAppApis.value.getUserInfo();
|
|
62
62
|
const userInfoStore = useUserInfo();
|
|
63
63
|
return userInfoStore.getUserInfo();
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 子应用推送路由变更
|
|
68
|
-
*/
|
|
69
|
-
export const mainAppPush = (subPath: string) => {
|
|
70
|
-
const appInfoStore = useAppInfo();
|
|
71
|
-
appInfoStore.push(subPath);
|
|
72
|
-
};
|
|
64
|
+
};
|