更改校端权限
This commit is contained in:
+39
-8
@@ -10,6 +10,7 @@ import Apis from '@/api/index'
|
||||
import { alovaInstance } from "@/utils/alova/alova-iview";
|
||||
import useCurrentInstance from "@/utils/hook/useCurrentInstance";
|
||||
import { UserRoleEnum } from "./types";
|
||||
import { isRouteAllowed } from "@/router";
|
||||
const store = useDefaultStore();
|
||||
const router = useRouter();
|
||||
const { $bus } = useCurrentInstance();
|
||||
@@ -53,10 +54,9 @@ const layoutInit = (info: any, modList: any[], appList: Array<any>, baseHost: st
|
||||
};
|
||||
|
||||
/**
|
||||
* 角色判定
|
||||
* 现基于 GetUserInfo 返回的 user.type 判定角色:
|
||||
* type=1 → SuperAdmin,type=2 → School(不再有 Teacher 角色)
|
||||
* 同时写入 currentRole 供下游 Utils.getCurrentRoleInfo 读取(保持兼容)
|
||||
* 角色判定(降级兜底):GetUserScope 失败时按 GetUserInfo 的 user.type 推断——
|
||||
* type=1 → SuperAdmin,其余 → School。同时写入 currentRole 供下游
|
||||
* Utils.getCurrentRoleInfo 与请求头注入读取(保持兼容;正常路径以 GetUserScope 为准)。
|
||||
*/
|
||||
const setCurrentRole = (user: any) => {
|
||||
const userId = user?.id ?? null;
|
||||
@@ -87,12 +87,43 @@ onMounted(async () => {
|
||||
try {
|
||||
var user: any = await alovaInstance.Request(Apis.Base.getUserInfo());
|
||||
|
||||
// 系统字典 & 模块列表(模块当前写死,后续接入接口)
|
||||
await store.fetchSysDict();
|
||||
await store.fetchModules();
|
||||
|
||||
currentUser.value = user;
|
||||
|
||||
// 系统字典
|
||||
await store.fetchSysDict();
|
||||
|
||||
// 角色判定:优先 GetUserScope(后端单点判定四级访问级别,前端不重复实现规则),
|
||||
// 失败时降级走 setCurrentRole 的 type 推断
|
||||
setCurrentRole(user);
|
||||
try {
|
||||
const scope: any = await alovaInstance.Request(Apis.Base.getUserScope());
|
||||
if (scope && scope.level != null) {
|
||||
store.setUserRole(scope.level);
|
||||
store.setUserScope({
|
||||
bureauGroupId: scope.bureauGroupId ?? null,
|
||||
schoolGroupIds: scope.schoolGroupIds ?? null,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("获取访问范围失败,按用户类型降级判定角色", e);
|
||||
}
|
||||
|
||||
// NONE 级:整体「暂无权限」,不加载菜单(接口层已被后端 NONE 拦截器 403 双挡)
|
||||
store.setRoleLoaded(true);
|
||||
if (store.userRole === UserRoleEnum.None) {
|
||||
isNoAuthority.value = true;
|
||||
layoutInit(user, [], [], baseHost, ssoHost);
|
||||
isLogin.value = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// 首次导航早于角色落定被守卫放行:此处复核当前路由(直接敲 URL 场景),越权重定向 /no-auth
|
||||
if (!isRouteAllowed(router.currentRoute.value, store.userRole)) {
|
||||
router.replace("/no-auth");
|
||||
}
|
||||
|
||||
// 模块列表(按当前级别过滤菜单权限矩阵)
|
||||
await store.fetchModules();
|
||||
layoutInit(user, store.modules, store.modules, baseHost, ssoHost);
|
||||
|
||||
// 登录后直接跳转到左侧菜单第一个可用入口
|
||||
|
||||
Reference in New Issue
Block a user