mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-12 04:03:42 +08:00
feat(ui): 管理后台新增权限及部分组合式函数优化
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user