mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 06:29:20 +08:00
feat: 超管账户切换
This commit is contained in:
@@ -51,6 +51,10 @@ interface AccessState {
|
||||
* refreshToken过期时间戳
|
||||
*/
|
||||
refreshTokenExpiresAt: number | null;
|
||||
/**
|
||||
* 用户角色
|
||||
*/
|
||||
userRole: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,6 +152,24 @@ export const useAccessStore = defineStore('core-access', {
|
||||
if (refreshTokenExpiresAt) {
|
||||
this.refreshTokenExpiresAt = refreshTokenExpiresAt;
|
||||
}
|
||||
|
||||
// 从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;
|
||||
} else {
|
||||
this.userRole = null;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('解析token失败:', error);
|
||||
this.userRole = null;
|
||||
}
|
||||
} else {
|
||||
this.userRole = null;
|
||||
}
|
||||
},
|
||||
unlockScreen() {
|
||||
this.isLockScreen = false;
|
||||
@@ -164,6 +186,7 @@ export const useAccessStore = defineStore('core-access', {
|
||||
'accessCodes',
|
||||
'isLockScreen',
|
||||
'lockScreenPassword',
|
||||
'userRole',
|
||||
],
|
||||
},
|
||||
state: (): AccessState => ({
|
||||
@@ -178,6 +201,7 @@ export const useAccessStore = defineStore('core-access', {
|
||||
loginExpired: false,
|
||||
refreshToken: null,
|
||||
refreshTokenExpiresAt: null,
|
||||
userRole: null,
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user