From e0ac3fd9acdf1086855f8a2e1fb2283a104f40eb Mon Sep 17 00:00:00 2001 From: p6s4t3fer <2644574964@qq.com> Date: Wed, 31 Dec 2025 12:10:31 +0800 Subject: [PATCH] ADD file via upload --- index.js | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..c16da3d --- /dev/null +++ b/index.js @@ -0,0 +1,80 @@ +import { createRouter, createWebHistory } from 'vue-router' +import { getToken, getUserInfo } from '@/utils/auth' + +const routes = [ + { + path: '/login', + name: 'Login', + component: () => import('@/views/Login.vue'), + meta: { requiresAuth: false } + }, + { + path: '/register', + name: 'Register', + component: () => import('@/views/Register.vue'), + meta: { requiresAuth: false } + }, + { + path: '/', + component: () => import('@/layouts/MainLayout.vue'), + redirect: '/certificates', + meta: { requiresAuth: true }, + children: [ + { + path: 'certificates', + name: 'Certificates', + component: () => import('@/views/Certificates.vue') + }, + { + path: 'certificate/register', + name: 'RegisterCertificate', + component: () => import('@/views/RegisterCertificate.vue') + }, + { + path: 'certificate/verify', + name: 'VerifyCertificate', + component: () => import('@/views/VerifyCertificate.vue') + }, + { + path: 'admin/requests', + name: 'AdminRequests', + component: () => import('@/views/admin/Requests.vue'), + meta: { requiresAdmin: true } + }, + { + path: 'admin/certificates', + name: 'AdminCertificates', + component: () => import('@/views/admin/Certificates.vue'), + meta: { requiresAdmin: true } + } + ] + } +] + +const router = createRouter({ + history: createWebHistory(), + routes +}) + +router.beforeEach((to, from, next) => { + const token = getToken() + const userInfo = getUserInfo() + + if (to.meta.requiresAuth && !token) { + next('/login') + } else if (!to.meta.requiresAuth && token && (to.path === '/login' || to.path === '/register')) { + next('/') + } else if (to.meta.requiresAdmin) { + // 检查管理员权限 + if (!userInfo || userInfo.authority !== 1) { + next('/certificates') // 非管理员跳转到证书列表 + } else { + next() + } + } else { + next() + } +}) + +export default router +