123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import { RouteRecordRaw, createRouter, createWebHashHistory } from "vue-router";
- import { gHeaders } from "./request/state";
- const history = createWebHashHistory();
- const routes: RouteRecordRaw[] = [
- {
- path: "",
- name: "down-vision",
- component: () => import("@/view/down-vision.vue"),
- },
- {
- path: "/login",
- name: "login",
- meta: { title: "登录" },
- component: () => import("@/view/login.vue"),
- },
- {
- path: "/",
- name: "main-layout",
- component: () => import("@/view/layout/nav.vue"),
- children: [
- {
- path: "relics",
- name: "relics",
- meta: { title: "文物管理" },
- component: () => import("@/view/relics.vue"),
- },
- {
- path: "relics/:relicsId",
- children: [
- {
- path: "",
- name: "map",
- meta: { title: "文物", navClass: "map" },
- component: () => import("@/view/map/map.vue"),
- },
- {
- path: "pano/:pid",
- name: "pano",
- meta: { title: "点位", navClass: "pano" },
- component: () => import("@/view/pano/pano.vue"),
- },
- ],
- },
- {
- path: "scene",
- name: "scene",
- meta: { title: "场景管理" },
- component: () => import("@/view/scene.vue"),
- },
- {
- path: "device",
- name: "device",
- meta: { title: "设备管理" },
- component: () => import("@/view/device.vue"),
- },
- ],
- },
- {
- path: "/query",
- name: "query-main-layout",
- component: () => import("@/view/layout/nav.vue"),
- children: [
- {
- path: "relics/:relicsId",
- children: [
- {
- path: "",
- name: "query-map",
- meta: { title: "文物", navClass: "map" },
- component: () => import("@/view/map/map.vue"),
- },
- {
- path: "pano/:pid",
- name: "query-pano",
- meta: { title: "点位", navClass: "pano" },
- component: () => import("@/view/pano/pano.vue"),
- },
- ],
- },
- ],
- },
- ];
- export const findRoute = (
- routeName: string,
- fullPath = false,
- routeAll = routes
- ): RouteRecordRaw | null => {
- for (const route of routeAll) {
- if (route.name === routeName) {
- return route;
- } else if (route.children) {
- const childRoute = findRoute(routeName, fullPath, route.children);
- if (childRoute) {
- return fullPath ? { ...route, children: [childRoute] } : childRoute;
- }
- }
- }
- return null;
- };
- export const router = createRouter({ history, routes });
- export const setDocTitle = (title: string) => {
- document.title = title + "-不移动动文物管理平台";
- };
- router.beforeEach((to, _, next) => {
- if (!to.name || to.name === "main-layout") {
- if (gHeaders.token) {
- router.replace({ name: "relics" });
- } else {
- router.replace({ name: "login" });
- }
- return;
- }
- if (to.meta?.title) {
- setDocTitle(to.meta.title as string);
- }
- next();
- });
|