Files
frontend_hmi_station/src/router/index.ts

121 lines
3.1 KiB
TypeScript
Raw Normal View History

2025-12-17 17:00:29 +08:00
import { createRouter, createWebHistory } from 'vue-router';
2025-12-23 13:27:03 +08:00
import { getToken } from "@/utils/auth";
2025-12-17 17:00:29 +08:00
const whiteList = ["/login"];
const routes = [
2025-12-23 13:27:03 +08:00
{
path: "/",
name: "Index",
component: () => import("@/views/index.vue"),
},
{
path: "/login",
name: "Login",
component: () => import("@/views/login.vue"),
},
{
2026-01-12 17:28:57 +08:00
path: "/traceOrderManage",
name: "TraceOrderManage",
component: () => import("@/views/traceOrderManage/layout.vue"),
redirect: { name: "TraceOrderManageIndex" },
2025-12-23 13:27:03 +08:00
children: [
{
path: "",
2026-01-12 17:28:57 +08:00
name: "TraceOrderManageIndex",
component: () => import("@/views/traceOrderManage/index.vue"),
2025-12-23 13:27:03 +08:00
},
{
path: "infeed",
name: "Infeed",
2026-01-12 17:28:57 +08:00
component: () => import("@/views/traceOrderManage/infeed/layout.vue"),
2025-12-23 13:27:03 +08:00
redirect: { name: "PrimaryMaterial" },
children: [
{
path: "primaryMaterial",
name: "PrimaryMaterial",
component: () =>
2026-01-12 17:28:57 +08:00
import("@/views/traceOrderManage/infeed/primaryMaterial/index.vue"),
2025-12-23 13:27:03 +08:00
},
{
path: "rawMaterial",
name: "RawMaterial",
component: () =>
2026-01-12 17:28:57 +08:00
import("@/views/traceOrderManage/infeed/rawMaterial/index.vue"),
2025-12-23 13:27:03 +08:00
},
{
path: "mask",
name: "Mask",
2026-01-12 17:28:57 +08:00
component: () => import("@/views/traceOrderManage/infeed/mask/index.vue"),
2025-12-29 08:59:07 +08:00
},
{
path: "equipment",
name: "Equipment",
2025-12-23 13:27:03 +08:00
component: () =>
2026-01-12 17:28:57 +08:00
import("@/views/traceOrderManage/infeed/equipment/index.vue"),
2025-12-23 13:27:03 +08:00
},
],
},
{
path: "outfeed",
name: "Outfeed",
2026-01-12 17:28:57 +08:00
component: () => import("@/views/traceOrderManage/outfeed/layout.vue"),
2025-12-29 08:59:07 +08:00
redirect: { name: "JobReport" },
children: [
{
path: "jobReport",
name: "JobReport",
component: () =>
2026-01-12 17:28:57 +08:00
import("@/views/traceOrderManage/outfeed/jobReport/index.vue"),
2025-12-29 08:59:07 +08:00
},
{
path: "parameterConfiguration",
name: "ParameterConfiguration",
component: () =>
import(
2026-01-12 17:28:57 +08:00
"@/views/traceOrderManage/outfeed/parameterConfiguration/index.vue"
2025-12-29 08:59:07 +08:00
),
},
{
path: "processGuidance",
name: "ProcessGuidance",
component: () =>
2026-01-12 17:28:57 +08:00
import("@/views/traceOrderManage/outfeed/processGuidance/index.vue"),
2025-12-29 08:59:07 +08:00
},
],
2025-12-23 13:27:03 +08:00
},
],
},
2025-12-17 17:00:29 +08:00
];
const router = createRouter({
history: createWebHistory(),
routes
});
router.beforeEach(async (to, from, next) => {
2025-12-23 13:27:03 +08:00
const token = getToken();
// 已登录,访问 login → 跳首页
if (token && to.path === "/login") {
return next("/");
}
2025-12-17 17:00:29 +08:00
// 白名单放行
if (whiteList.includes(to.path)) {
return next();
}
// 未登录,访问受保护路由
if (!token) {
return next({
path: "/login",
query: { redirect: to.fullPath },
});
}
// 已登录,正常访问
next();
});
2025-12-23 13:27:03 +08:00
export default router;