修改布局,修复BUG
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / CI OK (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / CI OK (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
This commit is contained in:
@@ -10,7 +10,7 @@ import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores';
|
||||
import { notification } from 'ant-design-vue';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
import { getAccessCodesApi, getUserInfoApi, loginApi, logoutApi } from '#/api';
|
||||
import { getUserInfoApi, loginApi, logoutApi } from '#/api';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
@@ -44,24 +44,14 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
// 获取用户信息并存储到 accessStore 中
|
||||
try {
|
||||
const [fetchUserInfoResult, accessCodesResult] = await Promise.allSettled([
|
||||
fetchUserInfo(),
|
||||
getAccessCodesApi().catch(() => []), // 如果接口不存在,返回空数组
|
||||
]);
|
||||
|
||||
userInfo = fetchUserInfoResult.status === 'fulfilled'
|
||||
? fetchUserInfoResult.value
|
||||
: null;
|
||||
userInfo = await fetchUserInfo();
|
||||
|
||||
if (userInfo) {
|
||||
userStore.setUserInfo(userInfo);
|
||||
}
|
||||
|
||||
if (accessCodesResult.status === 'fulfilled') {
|
||||
accessStore.setAccessCodes(accessCodesResult.value);
|
||||
} else {
|
||||
accessStore.setAccessCodes([]);
|
||||
}
|
||||
// 设置权限码为空数组(不使用权限码接口)
|
||||
accessStore.setAccessCodes([]);
|
||||
|
||||
// 重置路由检查状态,让路由守卫重新生成路由
|
||||
accessStore.setIsAccessChecked(false);
|
||||
@@ -132,7 +122,28 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
async function fetchUserInfo() {
|
||||
let userInfo: null | UserInfo = null;
|
||||
userInfo = await getUserInfoApi();
|
||||
const rawUserInfo = await getUserInfoApi();
|
||||
|
||||
// 将后端的 role 字段转换为 roles 数组
|
||||
if (rawUserInfo) {
|
||||
const role = (rawUserInfo as any).role;
|
||||
if (role) {
|
||||
// 将 role: 'super' 转换为 roles: ['super_admin']
|
||||
// 将 role: 'branch' 转换为 roles: ['branch']
|
||||
const roleMap: Record<string, string> = {
|
||||
super: 'super_admin',
|
||||
branch: 'branch',
|
||||
};
|
||||
const mappedRole = roleMap[role] || role;
|
||||
userInfo = {
|
||||
...rawUserInfo,
|
||||
roles: [mappedRole],
|
||||
} as UserInfo;
|
||||
} else {
|
||||
userInfo = rawUserInfo;
|
||||
}
|
||||
}
|
||||
|
||||
userStore.setUserInfo(userInfo);
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user