mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 13:49:20 +08:00
feat: 超管账户切换
This commit is contained in:
@@ -11,7 +11,7 @@ interface BasicUserInfo {
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
avatar: string;
|
||||
avatar?: string;
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { BasicUserInfo } from '@vben-core/typings';
|
||||
|
||||
/** 用户信息 */
|
||||
interface UserInfo extends BasicUserInfo {
|
||||
interface UserInfo extends Omit<BasicUserInfo, 'userId' | 'username'> {
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user