refactor: 重构超管相关

This commit is contained in:
2026-07-28 15:16:45 +08:00
parent 095efa4e64
commit 8a424f6121
36 changed files with 265 additions and 331 deletions
@@ -19,8 +19,8 @@ export namespace SuperAccountDTO {
departmentId?: number;
/** 岗位ID */
positionId?: number;
/** 角色 */
role: string;
/** 是否超级管理员(0-否 1-是) */
isSuper: number;
/** 头像图片ID */
avatarImageId?: number;
/** 备注 */
@@ -41,8 +41,8 @@ export namespace SuperAccountDTO {
departmentId?: number;
/** 岗位ID */
positionId?: number;
/** 角色 */
role?: string;
/** 是否超级管理员(0-否 1-是) */
isSuper?: number;
/** 头像图片ID */
avatarImageId?: number;
/** 状态(0-正常 1-删除 2-停用 3-冻结) */
@@ -65,8 +65,8 @@ export namespace SuperAccountDTO {
departmentId?: number;
/** 岗位ID */
positionId?: number;
/** 角色 */
role?: string;
/** 是否超级管理员(0-否 1-是) */
isSuper?: number;
/** 状态(0-正常 1-删除 2-停用 3-冻结) */
status?: number;
}
@@ -29,10 +29,10 @@ export namespace SuperAccountVO {
avatar?: string;
/** 头像图片ID */
avatarImageId?: number;
/** 角色 */
role?: string;
/** 角色名称 */
roleName?: string;
/** 是否超级管理员(0-否 1-是) */
isSuper?: number;
/** 是否超级管理员名称 */
isSuperName?: string;
/** 密码安全级别 */
pwdSecurityLevel?: number;
/** 密码最后更新时间 */
@@ -26,8 +26,8 @@ export namespace UserVO {
realName: string;
/** 头像路径 */
avatar?: string;
/** 关联角色(user-普通账户 company-公司账户 super-超管账户) */
role: string;
/** 是否超级管理员(0-否 1-是) */
isSuper?: number;
/** 密码安全级别(0-初始 1-很弱 2-弱 3-安全 4-很安全) */
pwdSecurityLevel?: number;
/** 密码最后更新时间 */
@@ -120,7 +120,7 @@ const menus = computed(() => {
}
// 只有超级管理员才显示切换账户功能
if (accessStore.userRole === 'super') {
if (accessStore.isSuper) {
menuItems.push({
handler: () => {
switchAccountModalRef.value?.open();
@@ -51,7 +51,7 @@ const formData = ref<
companyId: 0,
departmentId: undefined,
positionId: undefined,
role: '',
isSuper: 0,
avatarImageId: undefined,
remark: '',
status: 1,
@@ -73,7 +73,7 @@ function resetForm() {
companyId: presetCompany.value?.id ?? 0,
departmentId: undefined,
positionId: undefined,
role: '',
isSuper: 0,
avatarImageId: undefined,
remark: '',
status: 1,
@@ -104,7 +104,7 @@ function open(
companyId: accountData.companyId || presetCompany.value?.id || 0,
departmentId: accountData.departmentId,
positionId: accountData.positionId,
role: accountData.role || '',
isSuper: accountData.isSuper ?? 0,
avatarImageId: accountData.avatarImageId,
remark: accountData.remark || '',
status: accountData.status ?? 1,
@@ -253,17 +253,16 @@ defineExpose({
</Form.Item>
<Form.Item
label="角色"
name="role"
:rules="[{ required: true, message: '请输入角色' }]"
label="是否超管"
name="isSuper"
:rules="[{ required: true, message: '请选择是否超管' }]"
>
<Select
v-model:value="formData.role"
placeholder="请选择角色"
v-model:value="formData.isSuper"
placeholder="请选择是否超管"
:options="[
{ label: '超级管理员', value: 'super' },
{ label: '拥有者', value: 'admin' },
{ label: '普通用户', value: 'user' },
{ label: '否', value: 0 },
{ label: '是', value: 1 },
]"
/>
</Form.Item>
@@ -122,8 +122,8 @@ const gridOptions: VxeGridProps<SuperAccountVO.AccountInfoVO> = {
showOverflow: 'tooltip' as const,
},
{
field: 'role',
title: '角色',
field: 'isSuperName',
title: '超管',
minWidth: 100,
showOverflow: 'tooltip' as const,
},
@@ -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,
}),
});