|
@@ -1,8 +1,7 @@
|
|
|
-import type { UserInfo, UserTenant } from '#/store';
|
|
|
|
|
|
|
+import { RoleInfo, UserInfo, UserTenant } from '#/store';
|
|
|
import type { ErrorMessageMode } from '#/axios';
|
|
import type { ErrorMessageMode } from '#/axios';
|
|
|
import { defineStore } from 'pinia';
|
|
import { defineStore } from 'pinia';
|
|
|
import { store } from '@/store';
|
|
import { store } from '@/store';
|
|
|
-import { RoleEnum } from '@/enums/roleEnum';
|
|
|
|
|
import { PageEnum } from '@/enums/pageEnum';
|
|
import { PageEnum } from '@/enums/pageEnum';
|
|
|
import { ROLES_KEY, TOKEN_KEY, USER_INFO_KEY } from '@/enums/cacheEnum';
|
|
import { ROLES_KEY, TOKEN_KEY, USER_INFO_KEY } from '@/enums/cacheEnum';
|
|
|
import { createPassword, getAuthCache, setAuthCache } from '@/utils/auth';
|
|
import { createPassword, getAuthCache, setAuthCache } from '@/utils/auth';
|
|
@@ -25,7 +24,7 @@ import { h } from 'vue';
|
|
|
interface UserState {
|
|
interface UserState {
|
|
|
userInfo: Nullable<UserInfo>;
|
|
userInfo: Nullable<UserInfo>;
|
|
|
token?: string;
|
|
token?: string;
|
|
|
- roleList: string[];
|
|
|
|
|
|
|
+ roleList: RoleInfo[];
|
|
|
sessionTimeout?: boolean;
|
|
sessionTimeout?: boolean;
|
|
|
lastUpdateTime: number;
|
|
lastUpdateTime: number;
|
|
|
}
|
|
}
|
|
@@ -51,8 +50,8 @@ export const useUserStore = defineStore({
|
|
|
getToken(state): string {
|
|
getToken(state): string {
|
|
|
return state.token || getAuthCache<string>(TOKEN_KEY);
|
|
return state.token || getAuthCache<string>(TOKEN_KEY);
|
|
|
},
|
|
},
|
|
|
- getRoleList(state): string[] {
|
|
|
|
|
- return state.roleList.length > 0 ? state.roleList : getAuthCache<RoleEnum[]>(ROLES_KEY);
|
|
|
|
|
|
|
+ getRoleList(state): RoleInfo[] {
|
|
|
|
|
+ return state.roleList.length > 0 ? state.roleList : getAuthCache<RoleInfo[]>(ROLES_KEY);
|
|
|
},
|
|
},
|
|
|
getSessionTimeout(state): boolean {
|
|
getSessionTimeout(state): boolean {
|
|
|
return !!state.sessionTimeout;
|
|
return !!state.sessionTimeout;
|
|
@@ -69,13 +68,20 @@ export const useUserStore = defineStore({
|
|
|
getIsPlatformTenant(): boolean {
|
|
getIsPlatformTenant(): boolean {
|
|
|
return this.getUserTenant?.platformYn || false;
|
|
return this.getUserTenant?.platformYn || false;
|
|
|
},
|
|
},
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 是否是超级管理员用户
|
|
|
|
|
+ * @param state
|
|
|
|
|
+ */
|
|
|
|
|
+ getIsSuperAdmin(state): boolean {
|
|
|
|
|
+ return state.roleList.some((role) => role.superAdminYn);
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
actions: {
|
|
actions: {
|
|
|
setToken(info: string | undefined) {
|
|
setToken(info: string | undefined) {
|
|
|
this.token = info ? info : ''; // for null or undefined value
|
|
this.token = info ? info : ''; // for null or undefined value
|
|
|
setAuthCache(TOKEN_KEY, info);
|
|
setAuthCache(TOKEN_KEY, info);
|
|
|
},
|
|
},
|
|
|
- setRoleList(roleList: string[]) {
|
|
|
|
|
|
|
+ setRoleList(roleList: RoleInfo[]) {
|
|
|
this.roleList = roleList;
|
|
this.roleList = roleList;
|
|
|
setAuthCache(ROLES_KEY, roleList);
|
|
setAuthCache(ROLES_KEY, roleList);
|
|
|
},
|
|
},
|