From e6f81e19dc06013760c30359566cd2d276ff3fea Mon Sep 17 00:00:00 2001 From: Harry-zklcdc Date: Sun, 6 Jul 2025 15:32:39 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20=F0=9F=90=9B=20Page=20Router=20Permissi?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/router/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js index 9b47874..4e11b15 100644 --- a/frontend/src/router/index.js +++ b/frontend/src/router/index.js @@ -1,4 +1,5 @@ import AppLayout from '@/layout/AppLayout.vue'; +import { useProfileStore } from '@/stores/profile'; import { createRouter, createWebHistory } from 'vue-router'; import Forget from '@/views/Forget.vue'; @@ -100,4 +101,19 @@ const router = createRouter({ ] }); +router.beforeEach((to, from, next) => { + const profileStore = useProfileStore(); + if (to.path.startsWith('/admin')) { + if (!profileStore.isAdmin && !profileStore.isSuperAdmin) { + next({ name: 'not-found' }); + return; + } + if ((to.path.endsWith('servers') || to.path.endsWith('settings')) && !profileStore.isSuperAdmin) { + next({ name: 'not-found' }); + return; + } + } + next(); +}); + export default router;