refactor: ♻️ 抽离权限判断代码
This commit is contained in:
@@ -4,6 +4,24 @@ import NProgress from "@/utils/nprogress";
|
||||
import { RouteRecordRaw } from "vue-router";
|
||||
import { TOKEN_KEY } from "@/enums/CacheEnum";
|
||||
|
||||
// 是否有权限
|
||||
export function hasAuth(
|
||||
value: string | string[],
|
||||
type: "button" | "role" = "button"
|
||||
) {
|
||||
const { roles, perms } = useUserStore().user;
|
||||
//「超级管理员」拥有所有的按钮权限
|
||||
if (type === "button" && roles.includes("ROOT")) {
|
||||
return true;
|
||||
}
|
||||
const auths = type === "button" ? perms : roles;
|
||||
return typeof value === "string"
|
||||
? auths.includes(value)
|
||||
: auths.some((perm) => {
|
||||
return value.includes(perm);
|
||||
});
|
||||
}
|
||||
|
||||
export function setupPermission() {
|
||||
// 白名单路由
|
||||
const whiteList = ["/login"];
|
||||
|
||||
Reference in New Issue
Block a user