20260809223428
This commit is contained in:
1 parent
d72ca4193d
commit
c4891538a7
466 files changed
+21000
-3339
No files matched your search
@@ -1,64 +0,0 @@
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import NProgress from "nprogress";
|
||||
import { message } from "antdv-next";
|
||||
import "nprogress/nprogress.css";
|
||||
import routes from "./routes";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { usePermissionStore } from "@/stores/permissions";
|
||||
|
||||
NProgress.configure({ showSpinner: false });
|
||||
|
||||
function getRedirectPath(value) {
|
||||
return typeof value === "string" && value.startsWith("/") && !value.startsWith("//")
|
||||
? value
|
||||
: "/dashboard";
|
||||
}
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
scrollBehavior: () => ({ top: 0 }),
|
||||
});
|
||||
|
||||
router.beforeEach(async (to) => {
|
||||
NProgress.start();
|
||||
document.title = to.meta.title
|
||||
? `${to.meta.title} - FMS 货代物流管理系统`
|
||||
: "FMS 货代物流管理系统";
|
||||
|
||||
const authStore = useAuthStore();
|
||||
if (to.meta.requiresAuth && !authStore.isAuthenticated) {
|
||||
return { name: "login", query: { redirect: to.fullPath } };
|
||||
}
|
||||
if (to.name === "login" && authStore.isAuthenticated) {
|
||||
return getRedirectPath(to.query.redirect);
|
||||
}
|
||||
|
||||
if (to.meta.moduleId) {
|
||||
const permissionStore = usePermissionStore();
|
||||
try {
|
||||
await permissionStore.load();
|
||||
if (!permissionStore.canAccess(to.meta.moduleId)) {
|
||||
message.warning("没有该模块的访问权限");
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
message.error(error.message || "权限加载失败,请重新登录");
|
||||
permissionStore.clear();
|
||||
authStore.clearSession();
|
||||
return { name: "login", query: { redirect: to.fullPath } };
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
router.afterEach(() => {
|
||||
NProgress.done();
|
||||
});
|
||||
|
||||
router.onError(() => {
|
||||
NProgress.done();
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,126 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import DefaultLayout from '@/layouts/DefaultLayout.vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const PlaceholderPage = () => import('@/views/base/PlaceholderPage.vue')
|
||||
|
||||
// Demo pages
|
||||
const TablePage = () => import('@/views/demo/TableDemo.vue')
|
||||
const FormPage = () => import('@/views/demo/FormDemo.vue')
|
||||
const CardPage = () => import('@/views/demo/CardDemo.vue')
|
||||
const SettingsPage = () => import('@/views/demo/SettingsDemo.vue')
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: () => import('@/views/login/LoginView.vue'),
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
component: DefaultLayout,
|
||||
redirect: '/dashboard',
|
||||
meta: { requiresAuth: true },
|
||||
children: [
|
||||
{
|
||||
path: '/dashboard',
|
||||
name: 'dashboard',
|
||||
component: () => import('@/views/dashboard/index.vue'),
|
||||
meta: { title: '工作台' },
|
||||
},
|
||||
// Demo pages
|
||||
{
|
||||
path: '/demo/table',
|
||||
name: 'demo-table',
|
||||
component: TablePage,
|
||||
meta: { title: '表格示例', section: 'Demo 页面' },
|
||||
},
|
||||
{
|
||||
path: '/demo/form',
|
||||
name: 'demo-form',
|
||||
component: FormPage,
|
||||
meta: { title: '表单示例', section: 'Demo 页面' },
|
||||
},
|
||||
{
|
||||
path: '/demo/cards',
|
||||
name: 'demo-cards',
|
||||
component: CardPage,
|
||||
meta: { title: '卡片示例', section: 'Demo 页面' },
|
||||
},
|
||||
{
|
||||
path: '/demo/settings',
|
||||
name: 'demo-settings',
|
||||
component: SettingsPage,
|
||||
meta: { title: '设置示例', section: 'Demo 页面' },
|
||||
},
|
||||
// Business pages
|
||||
{
|
||||
path: '/base/othercompany',
|
||||
name: 'base-othercompany',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '合作伙伴' },
|
||||
},
|
||||
{
|
||||
path: '/base/contact',
|
||||
name: 'base-contact',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '联系人' },
|
||||
},
|
||||
{
|
||||
path: '/base/otherdata',
|
||||
name: 'base-otherdata',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '其他数据' },
|
||||
},
|
||||
{
|
||||
path: '/system/module-management',
|
||||
name: 'system-module-management',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '模块管理' },
|
||||
},
|
||||
{
|
||||
path: '/system/i18n-type',
|
||||
name: 'system-i18n-type',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '多语言类型' },
|
||||
},
|
||||
{
|
||||
path: '/system/login-log',
|
||||
name: 'system-login-log',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '登录日志' },
|
||||
},
|
||||
{
|
||||
path: '/system/user',
|
||||
name: 'system-user',
|
||||
component: PlaceholderPage,
|
||||
meta: { title: '用户管理' },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
redirect: '/dashboard',
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
// Auth guard
|
||||
router.beforeEach((to) => {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
if (to.path === '/login') {
|
||||
if (authStore.isAuthenticated) return '/dashboard'
|
||||
return
|
||||
}
|
||||
|
||||
if (to.matched.some(r => r.meta.requiresAuth)) {
|
||||
if (!authStore.isAuthenticated) {
|
||||
return { path: '/login', query: { redirect: to.fullPath } }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -1,128 +0,0 @@
|
||||
const routes = [
|
||||
{
|
||||
path: "/",
|
||||
component: () => import("@/layouts/DefaultLayout.vue"),
|
||||
meta: { requiresAuth: true },
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
redirect: "/dashboard",
|
||||
},
|
||||
{
|
||||
path: "dashboard",
|
||||
name: "dashboard",
|
||||
component: () => import("@/views/dashboard/index.vue"),
|
||||
meta: { title: "工作台", menuKey: "/dashboard" },
|
||||
},
|
||||
{
|
||||
path: "base/othercompany",
|
||||
name: "base-othercompany",
|
||||
component: () => import("@/views/base/othercompany/index.vue"),
|
||||
meta: {
|
||||
title: "合作伙伴",
|
||||
section: "基础数据",
|
||||
menuKey: "/base/othercompany",
|
||||
moduleId: "v_b_othercompany",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "base/othercompany/detail",
|
||||
name: "base-othercompany-detail",
|
||||
component: () => import("@/views/base/othercompany/detail.vue"),
|
||||
meta: {
|
||||
title: "合作伙伴详情",
|
||||
section: "基础数据",
|
||||
menuKey: "/base/othercompany",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "base/contact",
|
||||
name: "base-contact",
|
||||
component: () => import("@/views/base/contact/index.vue"),
|
||||
meta: {
|
||||
title: "联系人",
|
||||
section: "基础数据",
|
||||
menuKey: "/base/contact",
|
||||
moduleId: "v_b_contact",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "base/contact/detail",
|
||||
name: "base-contact-detail",
|
||||
component: () => import("@/views/base/contact/detail.vue"),
|
||||
meta: {
|
||||
title: "联系人详情",
|
||||
section: "基础数据",
|
||||
menuKey: "/base/contact",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "base/otherdata",
|
||||
name: "base-otherdata",
|
||||
component: () => import("@/views/base/otherdata/index.vue"),
|
||||
meta: {
|
||||
title: "其他数据",
|
||||
section: "基础数据",
|
||||
menuKey: "/base/otherdata",
|
||||
moduleId: "base_otherdata",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "system/module-management",
|
||||
name: "system-module-management",
|
||||
component: () => import("@/views/module-management/index.vue"),
|
||||
meta: {
|
||||
title: "模块管理",
|
||||
section: "系统管理",
|
||||
menuKey: "/system/module-management",
|
||||
moduleId: "m_metadata",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "system/i18n-type",
|
||||
name: "system-i18n-type",
|
||||
component: () => import("@/views/system/i18n-type/index.vue"),
|
||||
meta: {
|
||||
title: "多语言类型",
|
||||
section: "系统管理",
|
||||
menuKey: "/system/i18n-type",
|
||||
moduleId: "b_i18n_type",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "system/login-log",
|
||||
name: "system-login-log",
|
||||
component: () => import("@/views/system/login-log/index.vue"),
|
||||
meta: {
|
||||
title: "登录日志",
|
||||
section: "系统管理",
|
||||
menuKey: "/system/login-log",
|
||||
moduleId: "s_login_log",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "system/user",
|
||||
name: "system-user",
|
||||
component: () => import("@/views/system/user/index.vue"),
|
||||
meta: {
|
||||
title: "用户管理",
|
||||
section: "系统管理",
|
||||
menuKey: "/system/user",
|
||||
moduleId: "b_user",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "/login",
|
||||
name: "login",
|
||||
component: () => import("@/views/login/index.vue"),
|
||||
meta: { title: "登录" },
|
||||
},
|
||||
{
|
||||
path: "/:pathMatch(.*)*",
|
||||
redirect: "/dashboard",
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
Reference in new issue
Block a user