20260810223432

This commit is contained in:
oneao committed 2026-08-10 22:34:33 +08:00
1 parent ed5ab3885d
commit 5adbf59425
364 files changed
+7559 -4358

No files matched your search

+62 -62
View File
@@ -1,114 +1,114 @@
import { createRouter, createWebHistory } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import DefaultLayout from '@/layouts/DefaultLayout.vue'
import { useAuthStore } from '@/stores/auth'
import { usePermissionStore } from '@/stores/permissions'
import { createRouter, createWebHistory } from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
import DefaultLayout from "@/layouts/DefaultLayout.vue";
import { useAuthStore } from "@/stores/auth";
import { usePermissionStore } from "@/stores/permissions";
NProgress.configure({ showSpinner: false })
NProgress.configure({ showSpinner: false });
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/login',
name: 'login',
component: () => import('@/views/login/index.vue'),
path: "/login",
name: "login",
component: () => import("@/views/login/index.vue"),
},
{
path: '/',
path: "/",
component: DefaultLayout,
redirect: '/dashboard',
redirect: "/dashboard",
meta: { requiresAuth: true },
children: [
{
path: '/dashboard',
name: 'dashboard',
component: () => import('@/views/dashboard/index.vue'),
meta: { title: '工作台' },
path: "/dashboard",
name: "dashboard",
component: () => import("@/views/dashboard/index.vue"),
meta: { title: "工作台" },
},
// Base
{
path: '/base/othercompany',
name: 'base-othercompany',
component: () => import('@/views/base/OtherCompanyPage.vue'),
meta: { title: '合作伙伴', moduleId: 'v_b_othercompany' },
path: "/base/othercompany",
name: "base-othercompany",
component: () => import("@/views/base/othercompany/index.vue"),
meta: { title: "合作伙伴", moduleId: "v_b_othercompany" },
},
{
path: '/base/contact',
name: 'base-contact',
component: () => import('@/views/base/ContactPage.vue'),
meta: { title: '联系人', moduleId: 'v_b_contact' },
path: "/base/contact",
name: "base-contact",
component: () => import("@/views/base/contact/index.vue"),
meta: { title: "联系人", moduleId: "v_b_contact" },
},
{
path: '/base/otherdata',
name: 'base-otherdata',
component: () => import('@/views/base/OtherDataPage.vue'),
meta: { title: '其他数据', moduleId: 'v_b_otherdata' },
path: "/base/otherdata",
name: "base-otherdata",
component: () => import("@/views/base/otherdata/index.vue"),
meta: { title: "其他数据", moduleId: "v_b_otherdata" },
},
// System
{
path: '/system/module-management',
name: 'system-module-management',
component: () => import('@/views/system/ModuleManagementPage.vue'),
meta: { title: '模块管理', moduleId: 'm_metadata' },
path: "/system/module-management",
name: "system-module-management",
component: () => import("@/views/system/module-management/index.vue"),
meta: { title: "模块管理", moduleId: "m_metadata" },
},
{
path: '/system/i18n-type',
name: 'system-i18n-type',
component: () => import('@/views/system/I18nTypePage.vue'),
meta: { title: '多语言类型', moduleId: 'm_i18n' },
path: "/system/i18n-type",
name: "system-i18n-type",
component: () => import("@/views/system/i18n-type/index.vue"),
meta: { title: "多语言类型", moduleId: "m_i18n" },
},
{
path: '/system/login-log',
name: 'system-login-log',
component: () => import('@/views/system/LoginLogPage.vue'),
meta: { title: '登录日志', moduleId: 'd_login_log' },
path: "/system/login-log",
name: "system-login-log",
component: () => import("@/views/system/login-log/index.vue"),
meta: { title: "登录日志", moduleId: "d_login_log" },
},
{
path: '/system/user',
name: 'system-user',
component: () => import('@/views/system/UserPage.vue'),
meta: { title: '用户管理', moduleId: 'b_user' },
path: "/system/user",
name: "system-user",
component: () => import("@/views/system/user/index.vue"),
meta: { title: "用户管理", moduleId: "b_user" },
},
],
},
{
path: '/:pathMatch(.*)*',
redirect: '/dashboard',
path: "/:pathMatch(.*)*",
redirect: "/dashboard",
},
],
})
});
// Auth + permission guard
router.beforeEach(async (to) => {
NProgress.start()
const authStore = useAuthStore()
NProgress.start();
const authStore = useAuthStore();
if (to.path === '/login') {
if (authStore.isAuthenticated) return '/dashboard'
return
if (to.path === "/login") {
if (authStore.isAuthenticated) return "/dashboard";
return;
}
if (to.matched.some(r => r.meta.requiresAuth)) {
if (to.matched.some((r) => r.meta.requiresAuth)) {
if (!authStore.isAuthenticated) {
return { path: '/login', query: { redirect: to.fullPath } }
return { path: "/login", query: { redirect: to.fullPath } };
}
// Permission check
const moduleId = (to.meta as { moduleId?: string }).moduleId
const moduleId = (to.meta as { moduleId?: string }).moduleId;
if (moduleId) {
const permissionStore = usePermissionStore()
await permissionStore.load()
const permissionStore = usePermissionStore();
await permissionStore.load();
if (!permissionStore.canAccess(moduleId)) {
return '/dashboard'
return "/dashboard";
}
}
}
})
});
router.afterEach(() => {
NProgress.done()
})
NProgress.done();
});
export default router
export default router;