feat(ui): 管理后台新增权限及部分组合式函数优化

This commit is contained in:
廖彦棋
2024-03-14 10:27:09 +08:00
parent 5d4dd1e66f
commit 306cd2f945
16 changed files with 308 additions and 34 deletions

View File

@@ -1,14 +1,27 @@
import { createRouter, createWebHashHistory } from 'vue-router'
import { useAuthStore } from "@/stores/auth";
import CustomLayout from '@/components/CustomLayout.vue'
import { hasPermission } from "@/directives/permission";
import menu from './menu'
declare module 'vue-router' {
interface RouteMeta {
title?: string
permission?: string
}
}
const whiteListRoutes = [
{
path: "/login",
name: "Login",
component: () => import("@/views/LoginView.vue"),
},
{
path: "/403",
name: "403",
component: () => import("@/views/NoPermission.vue"),
},
{
path: "/:pathMatch(.*)*",
name: "404",
@@ -44,9 +57,13 @@ router.beforeEach((to, _, next) => {
return;
}
if (!authStore.token) {
authStore.$reset();
next({ name: "Login" });
return;
}
if (to.meta.permission) {
next(!hasPermission(to.meta.permission) ? { name: "403" } : undefined);
}
next();
});