add assistant

This commit is contained in:
ccmjga
2025-06-01 16:37:54 +08:00
parent eec1039b1e
commit 65c96abf9d
6 changed files with 84 additions and 139 deletions

View File

@@ -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;
}
}