feat(access): 实现基于用户角色的路由权限控制

添加权限检查功能,包括用户角色定义、路由元信息扩展和权限验证逻辑
重构路由配置和用户存储,支持动态菜单过滤
更新构建配置以支持类型声明生成
This commit is contained in:
2025-11-15 20:11:05 +08:00
parent a98eae385f
commit 8aa1f313af
10 changed files with 144 additions and 24 deletions

View File

5
src/store/types.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
export interface LoginUesr {
userName: string;
userRole?: string;
}

View File

@@ -1,11 +1,34 @@
import { defineStore } from "pinia";
import ACCESS_ENUM from "../access/accessEnum";
import type { LoginUesr } from "../store/types";
/**
*
*/
export const useUserStore = defineStore("user", {
state: () => ({
loginUser: {
userName: "未登录",
userRole: ACCESS_ENUM.NOT_LOGIN,
},
} as LoginUesr,
}),
actions: {},
actions: {
// 获取登录用户
async getLoginUser() {
try {
// 从后端获取当前登录用户信息
}catch(e) {
console.error("获取登录用户失败", e);
// 网络错误情况也视为未登录
this.loginUser = {
...this.loginUser,
userRole: ACCESS_ENUM.NOT_LOGIN,
};
}
},
// 手动更新用户状态
updateUserLoginStatus(user: LoginUesr) {
this.loginUser = user;
}
},
});