初始化
This commit is contained in:
97
src/router/index.ts
Normal file
97
src/router/index.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { getToken } from "@/utils/auth";
|
||||
import {
|
||||
createRouter,
|
||||
createWebHashHistory,
|
||||
type RouteRecordRaw,
|
||||
} from "vue-router";
|
||||
|
||||
const dashboardDefaultPath = "/dashboard/integrated-center";
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: "/",
|
||||
redirect: () => (getToken() ? dashboardDefaultPath : "/login"),
|
||||
},
|
||||
{
|
||||
path: "/dashboard",
|
||||
component: () => import("@/views/dashboard1/index.vue"),
|
||||
redirect: dashboardDefaultPath,
|
||||
children: [
|
||||
{
|
||||
path: "integrated-center",
|
||||
name: "IntegratedCenter",
|
||||
component: () =>
|
||||
import("@/views/dashboard1/pages/IntegratedCenterPage.vue"),
|
||||
meta: { title: "监管中心", tabId: 1, },
|
||||
},
|
||||
{
|
||||
path: "equipment-management",
|
||||
name: "EquipmentManagement",
|
||||
component: () =>
|
||||
import("@/views/dashboard1/pages/EquipmentManagementPage.vue"),
|
||||
meta: { title: "设备管理", tabId: 2, },
|
||||
},
|
||||
{
|
||||
path: "video-center",
|
||||
name: "VideoCenter",
|
||||
component: () => import("@/views/dashboard1/pages/VideoCenterPage.vue"),
|
||||
meta: { title: "视频中心", tabId: 3, },
|
||||
},
|
||||
{
|
||||
path: "alarm-management",
|
||||
name: "AlarmManagement",
|
||||
component: () =>
|
||||
import("@/views/dashboard1/pages/AlarmManagementPage.vue"),
|
||||
meta: { title: "告警管理", tabId: 4, },
|
||||
},
|
||||
{
|
||||
path: "patrol-plan",
|
||||
name: "PatrolPlan",
|
||||
component: () => import("@/views/dashboard1/pages/PatrolPlanPage.vue"),
|
||||
meta: { title: "巡检记录", tabId: 5, },
|
||||
},
|
||||
{
|
||||
path: "data-report",
|
||||
name: "DataReport",
|
||||
component: () => import("@/views/dashboard1/pages/DataReportPage.vue"),
|
||||
meta: { title: "统计分析", tabId: 6, },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "/login",
|
||||
name: "Login",
|
||||
component: () => import("@/views/login/index.vue"),
|
||||
meta: { title: "登录" },
|
||||
},
|
||||
{
|
||||
path: "/:pathMatch(.*)*",
|
||||
redirect: dashboardDefaultPath,
|
||||
},
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes,
|
||||
});
|
||||
|
||||
const whiteList = ["/login"];
|
||||
|
||||
router.beforeEach((to) => {
|
||||
const hasToken = Boolean(getToken());
|
||||
|
||||
if (!hasToken && !whiteList.includes(to.path)) {
|
||||
return {
|
||||
path: "/login",
|
||||
query: { redirect: to.fullPath },
|
||||
};
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
export function resetRouter() {
|
||||
// 当前项目暂无动态 addRoute 路由,保留该方法兼容登出流程。
|
||||
}
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user