mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 05:49:20 +08:00
refactor: 重构超管相关
This commit is contained in:
@@ -52,9 +52,9 @@ interface AccessState {
|
||||
*/
|
||||
refreshTokenExpiresAt: number | null;
|
||||
/**
|
||||
* 用户角色
|
||||
* 是否平台超级管理员(来自 JWT claim: super)
|
||||
*/
|
||||
userRole: string | null;
|
||||
isSuper: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,22 +153,22 @@ export const useAccessStore = defineStore('core-access', {
|
||||
this.refreshTokenExpiresAt = refreshTokenExpiresAt;
|
||||
}
|
||||
|
||||
// 从accessToken中提取用户角色
|
||||
// 从 accessToken 中提取是否超管
|
||||
if (accessToken) {
|
||||
try {
|
||||
const parts = accessToken.split('.');
|
||||
if (parts.length === 3 && parts[1]) {
|
||||
const payload = JSON.parse(atob(parts[1]));
|
||||
this.userRole = payload.role || null;
|
||||
this.isSuper = payload.super === true || payload.super === 1;
|
||||
} else {
|
||||
this.userRole = null;
|
||||
this.isSuper = false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('解析token失败:', error);
|
||||
this.userRole = null;
|
||||
this.isSuper = false;
|
||||
}
|
||||
} else {
|
||||
this.userRole = null;
|
||||
this.isSuper = false;
|
||||
}
|
||||
},
|
||||
unlockScreen() {
|
||||
@@ -186,7 +186,7 @@ export const useAccessStore = defineStore('core-access', {
|
||||
'accessCodes',
|
||||
'isLockScreen',
|
||||
'lockScreenPassword',
|
||||
'userRole',
|
||||
'isSuper',
|
||||
],
|
||||
},
|
||||
state: (): AccessState => ({
|
||||
@@ -201,7 +201,7 @@ export const useAccessStore = defineStore('core-access', {
|
||||
loginExpired: false,
|
||||
refreshToken: null,
|
||||
refreshTokenExpiresAt: null,
|
||||
userRole: null,
|
||||
isSuper: false,
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user