Files
frontend_hmi_station/src/router/index.ts

121 lines
3.0 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"),
},
{
path: "/pwoManage",
name: "PwoManage",
component: () => import("@/views/pwoManage/layout.vue"),
redirect: { name: "PwoManageIndex" },
children: [
{
path: "",
name: "PwoManageIndex",
component: () => import("@/views/pwoManage/index.vue"),
},
{
path: "infeed",
name: "Infeed",
component: () => import("@/views/pwoManage/infeed/layout.vue"),
redirect: { name: "PrimaryMaterial" },
children: [
{
path: "primaryMaterial",
name: "PrimaryMaterial",
component: () =>
import("@/views/pwoManage/infeed/primaryMaterial/index.vue"),
},
{
path: "rawMaterial",
name: "RawMaterial",
component: () =>
import("@/views/pwoManage/infeed/rawMaterial/index.vue"),
},
{
path: "mask",
name: "Mask",
2025-12-29 08:59:07 +08:00
component: () => import("@/views/pwoManage/infeed/mask/index.vue"),
},
{
path: "equipment",
name: "Equipment",
2025-12-23 13:27:03 +08:00
component: () =>
2025-12-29 08:59:07 +08:00
import("@/views/pwoManage/infeed/equipment/index.vue"),
2025-12-23 13:27:03 +08:00
},
],
},
{
path: "outfeed",
name: "Outfeed",
2025-12-29 08:59:07 +08:00
component: () => import("@/views/pwoManage/outfeed/layout.vue"),
redirect: { name: "JobReport" },
children: [
{
path: "jobReport",
name: "JobReport",
component: () =>
import("@/views/pwoManage/outfeed/jobReport/index.vue"),
},
{
path: "parameterConfiguration",
name: "ParameterConfiguration",
component: () =>
import(
"@/views/pwoManage/outfeed/parameterConfiguration/index.vue"
),
},
{
path: "processGuidance",
name: "ProcessGuidance",
component: () =>
import("@/views/pwoManage/outfeed/processGuidance/index.vue"),
},
],
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;