123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- import { RouteRecordRaw, createRouter, createWebHashHistory } from "vue-router";
- import { UserStatus, logintAuth, userStatus, isSuper } from "./store/user";
- import { watch, watchEffect } from "vue";
- export const COORD_NAME = "map-coord";
- export const POYS_NAME = "map-poy";
- export const QUERY_COORD_NAME = "query-map-coord";
- export const QUERY_POYS_NAME = "query-map-poy";
- const history = createWebHashHistory();
- const routes: RouteRecordRaw[] = [
- {
- path: "/no-persession",
- name: "no-persession",
- meta: { title: "无权限" },
- component: () => import("@/view/no-persession.vue"),
- },
- {
- path: "/down-vision",
- name: "down-vision",
- meta: { title: "" },
- component: () => import("@/view/down-vision.vue"),
- },
- {
- path: "/login",
- name: "login",
- meta: { title: "登录" },
- component: () => import("@/view/login.vue"),
- },
- {
- path: "/tree2",
- name: "query-tree-2",
- meta: { title: "登录" },
- component: () => import("@/view/step-tree-v2/example/example.vue"),
- },
- {
- path: "/tree",
- name: "query-tree",
- meta: { title: "登录" },
- component: () => import("@/view/step-tree/example/example.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-board.vue"),
- // },
- {
- path: "map",
- name: "map",
- meta: { title: "文物", navClass: "map" },
- component: () => import("@/view/map/layout.vue"),
- children: [
- {
- path: "coord",
- name: COORD_NAME,
- meta: { title: "文物", navClass: "map" },
- component: () => import("@/view/map/coord.vue"),
- },
- {
- path: "polygons",
- name: POYS_NAME,
- meta: { title: "文物", navClass: "map" },
- component: () => import("@/view/map/polygons.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: "organization",
- name: "organization",
- meta: { title: "单位管理" },
- component: () => import("@/view/organization.vue"),
- },
- {
- path: "users",
- name: "users",
- meta: { title: "用户管理" },
- component: () => import("@/view/users.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/layout.vue"),
- children: [
- {
- path: "query-coord",
- name: QUERY_COORD_NAME,
- meta: { title: "文物", navClass: "map" },
- component: () => import("@/view/map/coord.vue"),
- },
- {
- path: "query-polygons",
- name: QUERY_POYS_NAME,
- meta: { title: "文物", navClass: "map" },
- component: () => import("@/view/map/polygons.vue"),
- },
- ],
- },
- {
- path: "pano/:pid",
- name: "query-pano",
- meta: { title: "点位", navClass: "pano" },
- component: () => import("@/view/pano/pano.vue"),
- },
- ],
- },
- ],
- },
- { path: '/:pathMatch(.*)*', component: import("@/view/layout/nav.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 + "-不可移动文物管理平台";
- };
- watchEffect(() => {
- const routeName = router.currentRoute.value.name?.toString();
- if (routeName === "login" && userStatus.value === UserStatus.LOGINED) {
- router.replace({ name: "scene" });
- } else if (
- routeName &&
- routeName !== "login" &&
- !routeName.includes("query") &&
- userStatus.value === UserStatus.NOT_LOGIN
- ) {
- router.replace({ name: "login" });
- }
- });
- // 非登录页面校验是否等里
- watch(
- () => [router.currentRoute.value.name?.toString(), userStatus.value] as const,
- ([routeName, userStatus]) => {
- if (
- routeName &&
- !routeName.includes("query") &&
- userStatus === UserStatus.UNKNOWN
- ) {
- logintAuth();
- }
- },
- { immediate: true }
- );
- router.beforeEach((to, _, next) => {
- if (!to.name || to.name === "main-layout") {
- if (userStatus.value !== UserStatus.NOT_LOGIN) {
- router.replace({ name: "scene" });
- } else {
- router.replace({ name: "login" });
- }
- return;
- }
- // organization
- if (to.name === "organization") {
- console.log('isSuper-organization', isSuper.value)
- if (!isSuper.value) {
- router.replace({ name: "scene" });
- return
- }
- }
- if (to.name === "map") {
- router.replace({ name: COORD_NAME, params: to.params });
- } else if (to.name === "query-map") {
- router.replace({ name: QUERY_COORD_NAME, params: to.params });
- }
- if (to.meta?.title) {
- setDocTitle(to.meta.title as string);
- }
- next();
- });
|