mirror of
https://github.com/ccmjga/zhilu-admin
synced 2026-03-30 07:43:44 +08:00
add assistant
This commit is contained in:
@@ -2,6 +2,7 @@ import useUserStore from "@/composables/store/useUserStore";
|
||||
import type { NavigationGuard, Router } from "vue-router";
|
||||
import type { RouteMeta } from "../types/router";
|
||||
import { RoutePath } from "./constants";
|
||||
import useAlertStore from "@/composables/store/useAlertStore";
|
||||
|
||||
export const authGuard: NavigationGuard = (to) => {
|
||||
const userStore = useUserStore();
|
||||
@@ -18,13 +19,17 @@ export const authGuard: NavigationGuard = (to) => {
|
||||
|
||||
export const permissionGuard: NavigationGuard = (to) => {
|
||||
const userStore = useUserStore();
|
||||
const { showAlert } = useAlertStore();
|
||||
const routeMeta: RouteMeta = to.meta;
|
||||
if (routeMeta.hasPermission) {
|
||||
const hasPermission = userStore.permissionCodes?.includes(
|
||||
routeMeta.hasPermission,
|
||||
);
|
||||
if (!hasPermission) {
|
||||
console.error(`您没有请求页面的相关权限:${to.path}`);
|
||||
showAlert({
|
||||
content: `没有访问页面所需的 ${routeMeta.hasPermission} 权限`,
|
||||
level: "error",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -32,11 +37,15 @@ export const permissionGuard: NavigationGuard = (to) => {
|
||||
|
||||
export const roleGuard: NavigationGuard = (to) => {
|
||||
const userStore = useUserStore();
|
||||
const { showAlert } = useAlertStore();
|
||||
const routeMeta: RouteMeta = to.meta;
|
||||
if (routeMeta.hasRole) {
|
||||
const hasRole = userStore.roleCodes?.includes(routeMeta.hasRole);
|
||||
if (!hasRole) {
|
||||
console.error(`您没有请求页面的相关角色:${to.path}`);
|
||||
showAlert({
|
||||
content: `没有访问页面所需的 ${routeMeta.hasRole} 角色`,
|
||||
level: "error",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user