From 23876aa396143bf77cb5c86af8d6023d9ff6555a Mon Sep 17 00:00:00 2001 From: hxr <1490493387@qq.com> Date: Sat, 8 Jun 2024 12:45:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20:sparkles:=20=E9=A1=B5=E7=AD=BEtitle?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8A=A8=E6=80=81=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/permission.ts | 43 +++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/plugins/permission.ts b/src/plugins/permission.ts index a09b6f4b..b6da9120 100644 --- a/src/plugins/permission.ts +++ b/src/plugins/permission.ts @@ -4,24 +4,6 @@ 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"]; @@ -43,6 +25,13 @@ export function setupPermission() { if (to.matched.length === 0) { from.name ? next({ name: from.name }) : next("/404"); } else { + // 如果路由参数中有 title,覆盖路由元信息中的 title + const title = + (to.params.title as string) || (to.query.title as string); + if (title) { + to.meta.title = title; + } + next(); } } else { @@ -77,3 +66,21 @@ export function setupPermission() { NProgress.done(); }); } + +// 是否有权限 +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); + }); +}