城阳pc工作端前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1247 lines
41 KiB

import Vue from "vue";
import Router from "vue-router";
import http from "@/utils/request";
import { isURL } from "@/utils/validate";
import store from "@/js/store";
import { message } from "@/utils/message.js";
Vue.use(Router);
const CUSTOMER = process.env.VUE_APP_CUSTOMER;
// 页面路由(独立页面)
export const pageRoutes = [
{
path: "/login",
component: () => import("@/views/pages/login"),
name: "login",
meta: {
title: "登录",
},
},
{
path: "/",
name: "index",
// component: () => import("@/views/pages/index"),
redirect: {
path: "/main/home",
},
},
{
path: "/404",
component: () => import("@/views/pages/404"),
name: "404",
meta: {
title: "404未找到",
},
beforeEnter(to, from, next) {
// 拦截处理特殊业务场景
// 如果, 重定向路由包含__双下划线, 为临时添加路由
if (/__.*/.test(to.redirectedFrom)) {
return next(to.redirectedFrom.replace(/__.*/, ""));
}
next();
},
},
];
// 模块路由(基于主入口布局页面)
export const moduleRoutes = {
path: "/main",
component: () => import("@/views/main"),
name: "main",
redirect: {
path: "/main/home",
},
meta: {
title: "主入口布局",
isTab: false,
},
children: [
{
path: "suggestionList",
props: true,
name: "suggestionList",
component: () => import("@/views/modules/solicitationSpecial/cpts/suggestionList"),
meta: {
isTab: true,
title: "专题征集列表",
},
},
{
path: "home",
component: () => import("@/views/modules/home/index"),
name: "home",
meta: {
title: "首页",
isTab: true,
},
},
{
path: "unopen",
component: () => import("@/views/modules/unopen"),
name: "unopen",
meta: {
title: "未开放功能",
isTab: true,
},
},
{
path: "404",
props: true,
component: () => import("@/views/modules/404"),
name: "main-404",
meta: {
title: "页面未找到或无权访问",
isTab: false,
},
},
{
path: "home-notice",
props: true,
name: "home-notice",
component: () => import("@/views/modules/home/notice"),
meta: {
isTab: true,
title: "智能提醒",
parent: [
{
title: "首页",
path: "/main/home-index",
},
],
},
},
{
path: "notice-version",
props: true,
name: "notice-version",
component: () => import("@/views/modules/home/cpts/notice_version_update"),
meta: {
isTab: true,
title: "版本更新",
},
},
{
path: "base-nonIntResi",
props: true,
name: "base-nonIntResi",
component: () => import("@/views/modules/base/nonIntResi/nonIntResi"),
meta: {
isTab: true,
title: "信息不完整",
},
},
{
path: "shequ-chaxun",
props: true,
name: "shequ-chaxun",
component: () => import("@/views/modules/shequ/chaxun"),
meta: {
isTab: true,
title: "社区查询",
},
},
{
path: "smartImport",
props: true,
name: "smartImport",
component: () => import("@/views/modules/base/smartImport"),
meta: {
isTab: true,
title: "智能导出",
},
},
{
path: "jumin-huaxiang",
props: true,
name: "jumin-huaxiang",
component: () => import("@/views/modules/portrayal/jumin/index"),
meta: {
isTab: true,
title: "",
},
},
{
path: "house-huaxiang",
props: true,
name: "house-huaxiang",
component: () => import("@/views/modules/portrayal/house/index"),
meta: {
isTab: true,
title: "",
},
},
{
path: "loudong-huaxiang",
props: true,
name: "loudong-huaxiang",
component: () => import("@/views/modules/portrayal/loudong/index"),
meta: {
isTab: true,
title: "",
},
},
{
path: "add-resi",
props: true,
name: "add-resi",
component: () => import("@/views/components/addResi"),
meta: {
isTab: true,
title: "新增居民",
},
},
{
path: "edit-resi",
props: true,
name: "edit-resi",
component: () => import("@/views/components/editResi"),
meta: {
isTab: true,
title: "编辑居民",
},
}
],
};
// pc端菜单的 如果没有配置 默认的 或者配置了默认的 但没有权限 默认选中第一
function cookApiDataItem(item) {
function n2one(v) {
let ret = [];
for (let i = 0; i < v.length; i++) {
ret.push(v[i]);
if (Array.isArray(v[i].children) && v[i].children.length > 0) {
ret.push(...n2one(v[i].children));
}
}
return ret;
}
let allChildrenUrl = n2one(item.children)
.filter((i) => i.url != "" && i.showFlag == 1)
.map((i) => i.url);
if (item.children.length > 0) {
if (item.url == "" || !allChildrenUrl.find((i) => i.url == item.url)) {
item.url = allChildrenUrl[0];
}
}
return item;
}
// 把按钮都化为页面内部的权限
function cookApiDataItem2(item) {
let { children } = item;
if (children && Array.isArray(children) && children.length > 0) {
let btns = item.children.filter((item) => item.type == 1);
item.btns = btns;
item.children = item.children.filter((val) => val.type == 0).map((val) => cookApiDataItem2(val));
}
return item;
}
// 把父级拼到子集
function cookApiDataItem3(item, parent = []) {
item.parent = parent;
let { children } = item;
if (children && Array.isArray(children) && children.length > 0) {
item.children = children.map((val) =>
cookApiDataItem3(val, [
...parent,
{
title: item.name || "",
path: (item.url || "").replace(/{{([^}}]+)?}}/g, (s1, s2) => eval(s2)),
},
])
);
}
return item;
}
// 新数据模块
export const dataBoardRoutes = {
path: "/dataBoard",
component: () => import("@/views/dataBoardMain/main"),
name: "dataBoard",
redirect: {
path: "/dataBoard/overView/index",
},
meta: {
title: "主入口布局",
},
children: [
{
path: "renfang/index",
props: true,
component: () => import("@/views/dataBoard/renfang/index"),
name: "dataBoard-renfang-index",
meta: {
title: "人房总览",
isTab: false,
},
},
{
path: "home/index",
props: true,
component: () => import("@/views/dataBoard/home/index"),
name: "dataBoard-home-index",
meta: {
title: "首页",
isTab: false,
},
},
{
path: "IoTPerception/index",
props: true,
component: () => import("@/views/dataBoard/IoTPerception/index"),
name: "dataBoard-IoTPerception-index",
meta: {
title: "物联感知",
isTab: false,
},
},
{
path: "renfang/resi-list",
props: true,
component: () => import("@/views/dataBoard/renfang/resi/list"),
name: "dataBoard-renfang-resi-list",
meta: {
title: "居民列表",
isTab: false,
},
},
{
path: "renfang/resi-class",
props: true,
component: () => import("@/views/dataBoard/renfang/resi/class"),
name: "dataBoard-renfang-resi-class",
meta: {
title: "居民分类列表",
isTab: false,
},
},
{
path: "renfang/resi-class-new",
props: true,
component: () => import("@/views/dataBoard/renfang/resi/classNew"),
name: "dataBoard-renfang-resi-class",
meta: {
title: "居民分类列表",
isTab: false,
},
},
{
path: "renfang/resi-analyze",
props: true,
component: () => import("@/views/dataBoard/renfang/resi/analyze"),
name: "dataBoard-renfang-resi-analyze",
meta: {
title: "居民分析列表",
isTab: false,
},
},
{
path: "renfang/house-list",
props: true,
component: () => import("@/views/dataBoard/renfang/house/list"),
name: "dataBoard-renfang-house-list",
meta: {
title: "房屋列表",
isTab: false,
},
},
{
path: "renfang/visualizing",
props: true,
component: () => import("@/views/dataBoard/renfang/visualizing/index"),
name: "dataBoard-visualizing-index",
meta: {
title: "可视化数据",
isTab: false,
keepAlive: false,
},
},
{
path: "renfang/resident",
props: true,
component: () => import("@/views/dataBoard/renfang/resident/index"),
name: "dataBoard-renfang-resident",
meta: {
title: "居民画像",
isTab: false,
},
},
,
{
path: "overview/familyPortrait",
props: true,
component: () => import("@/views/dataBoard/overview/familyPortrait/index"),
name: "dataBoard-overview-familyPortrait",
meta: {
title: "家庭画像",
isTab: false,
},
},
{
path: "renfang/warn-building",
props: true,
component: () => import("@/views/dataBoard/renfang/warn/building"),
name: "dataBoard-renfang-warn-building",
meta: {
title: "预警楼栋列表",
isTab: false,
},
},
{
path: "renfang/warn-resi",
props: true,
component: () => import("@/views/dataBoard/renfang/warn/resi"),
name: "dataBoard-renfang-warn-resi",
meta: {
title: "预警楼栋居民",
isTab: false,
},
},
{
path: "sida/index",
props: true,
component: () => import("@/views/dataBoard/sida/index"),
name: "dataBoard-sida-index",
meta: {
title: "四大清单",
isTab: false,
},
},
{
path: "sida/xq/list",
props: true,
component: () => import("@/views/dataBoard/sida/xq/list"),
name: "dataBoard-sida-xq-list",
meta: {
title: "需求清单列表",
isTab: false,
},
},
{
path: "sida/wt/eventList",
props: true,
component: () => import("@/views/dataBoard/sida/wt/eventList"),
name: "dataBoard-sida-wt-eventList",
meta: {
title: "治理事件列表",
isTab: false,
},
},
{
path: "sida/wt/hiddenDangerList",
props: true,
component: () => import("@/views/dataBoard/sida/wt/hiddenDangerList"),
name: "dataBoard-sida-wt-hiddenDangerList",
meta: {
title: "安全隐患列表",
isTab: false,
},
},
{
path: "sida/wt/specialCategoryList",
props: true,
component: () => import("@/views/dataBoard/sida/wt/specialCategoryList"),
name: "dataBoard-sida-wt-specialCategoryList",
meta: {
title: "综治人群列表",
isTab: false,
},
},
{
path: "sida/zy/peopleResList",
props: true,
component: () => import("@/views/dataBoard/sida/zy/peopleResList"),
name: "dataBoard-sida-zy-peopleResList",
meta: {
title: "人资源列表",
isTab: false,
},
},
{
path: "sida/zy/goodsResList",
props: true,
component: () => import("@/views/dataBoard/sida/zy/goodsResList"),
name: "dataBoard-sida-zy-goodsResList",
meta: {
title: "物资源列表",
isTab: false,
},
},
{
path: "sida/zy/placeResList",
props: true,
component: () => import("@/views/dataBoard/sida/zy/placeResList"),
name: "dataBoard-sida-zy-placeResList",
meta: {
title: "场所隐患列表",
isTab: false,
},
},
{
path: "sida/fw",
props: true,
component: () => import("@/views/dataBoard/sida/fw"),
name: "dataBoard-sida-fw",
meta: {
title: "四大清单-服务清单查看更多",
isTab: false,
},
},
{
path: "fifteen/index",
props: true,
component: () => import("@/views/dataBoard/fifteen/index"),
name: "dataBoard-fifteen-index",
meta: {
title: "十五分钟生活圈",
isTab: false,
},
},
{
path: "overview/index",
props: true,
component: () => import("@/views/dataBoard/overview/index"),
name: "dataBoard-overview-index",
meta: {
title: "概览",
isTab: false,
},
},
{
path: "overview/dissatisfiedProblemNumber/12345Hotline",
props: true,
component: () => import("@/views/dataBoard/overview/dissatisfiedProblemNumber/12345Hotline"),
name: "dataBoard-overview-dissatisfiedProblemNumber-12345Hotline",
meta: {
title: "12345热线不满意数",
isTab: false,
},
},
{
path: "overview/dissatisfiedProblemNumber/provinceSatisfaction",
props: true,
component: () => import("@/views/dataBoard/overview/dissatisfiedProblemNumber/provinceSatisfaction"),
name: "dataBoard-overview-dissatisfiedProblemNumber-provinceSatisfaction",
meta: {
title: "满意度调查不满意数",
isTab: false,
},
},
{
path: "overview/dissatisfiedProblemNumber/selfInspect",
props: true,
component: () => import("@/views/dataBoard/overview/dissatisfiedProblemNumber/selfInspect"),
name: "dataBoard-overview-selfInspect",
meta: {
title: "社区自查不满意数",
isTab: false,
},
},
{
path: "overview/resident",
props: true,
component: () => import("@/views/dataBoard/overview/resident/index"),
name: "dataBoard-overview-resident",
meta: {
title: "居民画像",
isTab: false,
},
},
{
path: "overview/residents",
props: true,
component: () => import("@/views/dataBoard/overview/residents/index"),
name: "dataBoard-overview-residents",
meta: {
title: "居民画像",
isTab: false,
},
},
{
path: "/organizational",
props: true,
component: () => import("@/views/dataBoard/organizational/index"),
name: "Organizational",
meta: {
title: "治理架构",
isTab: false,
},
children: [
{
path: "/organizational/dangTree",
props: true,
component: () => import("@/views/dataBoard/organizational/dangTree/index"),
name: "DangTree",
meta: {
title: "动力主轴",
isTab: false,
},
},
{
path: "/organizational/jwTree",
props: true,
component: () => import("@/views/dataBoard/organizational/jwTree/index"),
name: "JwTree",
meta: {
title: "居委架构",
isTab: false,
},
},
{
path: "/organizational/gridTree",
props: true,
component: () => import("@/views/dataBoard/organizational/gridTree/index"),
name: "GridTree",
meta: {
title: "微网格治理",
isTab: false,
},
},
],
},
{
path: "/homeDetails/index",
props: true,
component: () => import("@/views/dataBoard/cpts/homeDetails/index"),
name: "HomeDetails",
meta: {
title: "单元",
isTab: false,
keepAlive: false,
},
},
{
path: "/organizational/orgPersonnel/:name",
props: true,
component: () => import("@/views/dataBoard/organizational/personalPage/index"),
name: "OrgPersonnel",
meta: {
title: "居民画像",
isTab: false,
},
},
{
path: "/organizational/microgrid/:id/:pid/:name",
props: true,
component: () => import("@/views/dataBoard/organizational/microgrid/index"),
name: "Microgrid",
meta: {
title: "微网格",
isTab: false,
},
},
{
path: "humanData/index",
props: true,
component: () => import("@/views/dataBoard/humanData/index"),
name: "dataBoard-humanData-index",
meta: {
title: "人房数据",
isTab: false,
},
},
{
path: "satisfactionEval/index",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/index"),
name: "dataBoard-satisfactionEval-index",
meta: {
title: "群众满意度",
isTab: false,
},
},
{
path: "satisfactionEval/dissatisfied/:id/:type/:timeType",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/dissatisfied/index"),
name: "dataBoard-satisfactionEval-dissatisfied",
meta: {
title: "不满意事项列表",
isTab: false,
},
},
{
path: "satisfactionEval/dissatisfieReason",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/dissatisfieReason/index"),
name: "dataBoard-dissatisfieReason-index",
meta: {
title: "社区自查不满意数原因列表",
isTab: false,
},
},
{
path: "satisfactionEval/dissatisfiedPersonnel",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/dissatisfiedPersonnel/index"),
name: "dataBoard-satisfactionEval-dissatisfiedPersonnel",
meta: {
title: "画像匹配同类潜在不满意人员 ",
isTab: false,
},
},
{
path: "satisfactionEval/dissatisfiedPersonnel/detail",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/dissatisfiedPersonnel/detail"),
name: "dataBoard-satisfactionEval-dissatisfiedPersonnel-detail",
meta: {
title: "画像匹配同类潜在不满意人员 ",
isTab: false,
},
},
{
path: "satisfactionEval/potentialPeople",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/potentialPeople/index"),
name: "dataBoard-satisfactionEval-potentialPeople-index",
meta: {
title: "潜在不满意人数",
isTab: false,
},
},
{
path: "satisfactionEval/potentialPeople/yxwxfw",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/potentialPeople/yxwxfw"),
name: "dataBoard-satisfactionEval-potentialPeople-yxwxfw",
meta: {
title: "应享未享服务人数",
isTab: false,
},
},
{
path: "satisfactionEval/potentialPeople/sjwjj",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/potentialPeople/sjwjj"),
name: "dataBoard-satisfactionEval-potentialPeople-sjwjj",
meta: {
title: "事件未解决上报人数",
isTab: false,
},
},
{
path: "satisfactionEval/potentialPeople/xqwmz",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/potentialPeople/xqwmz"),
name: "dataBoard-satisfactionEval-potentialPeople-xqwmz",
meta: {
title: "需求未满足人数",
isTab: false,
},
},
{
path: "overview/potentialPeople",
props: true,
component: () => import("@/views/dataBoard/overview/potentialPeople/index"),
name: "dataBoard-overview-potentialPeople-index",
meta: {
title: "潜在不满意人数",
isTab: false,
},
},
{
path: "overview/potentialPeople/yxwxfw",
props: true,
component: () => import("@/views/dataBoard/overview/potentialPeople/yxwxfw"),
name: "dataBoard-overview-potentialPeople-yxwxfw",
meta: {
title: "应享未享服务人数",
isTab: false,
},
},
{
path: "overview/potentialPeople/sjwjj",
props: true,
component: () => import("@/views/dataBoard/overview/potentialPeople/sjwjj"),
name: "dataBoard-overview-potentialPeople-sjwjj",
meta: {
title: "事件未解决上报人数",
isTab: false,
},
},
{
path: "overview/potentialPeople/xqwmz",
props: true,
component: () => import("@/views/dataBoard/overview/potentialPeople/xqwmz"),
name: "dataBoard-overview-potentialPeople-xqwmz",
meta: {
title: "需求未满足人数",
isTab: false,
},
},
{
path: "overview/potentialPeople/12345",
props: true,
component: () => import("@/views/dataBoard/overview/potentialPeople/12345"),
name: "dataBoard-overview-potentialPeople-12345",
meta: {
title: "12345人员事件",
isTab: false,
},
},
{
path: "overview/potentialPeople/province",
props: true,
component: () => import("@/views/dataBoard/overview/potentialPeople/province"),
name: "dataBoard-overview-potentialPeople-province",
meta: {
title: "上级满意度调查不满意列表",
isTab: false,
},
},
{
path: "overview/potentialPeople/selfInspect",
props: true,
component: () => import("@/views/dataBoard/overview/potentialPeople/selfInspect"),
name: "dataBoard-overview-potentialPeople-selfInspect",
meta: {
title: "社区自查不满意列表",
isTab: false,
},
},
{
path: "satisfactionEval/Problem/tddtlxsj",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/Problem/tddtlxsj/list"),
name: "dataBoard-satisfactionEval-Problem-tddtlxsj-list",
meta: {
title: "同地点同类型重复投诉问题列表",
isTab: false,
},
},
{
path: "satisfactionEval/Problem/tddtlxsj/detail",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/Problem/tddtlxsj/detail"),
name: "dataBoard-satisfactionEval-Problem-tddtlxsj-detail",
meta: {
title: "同地点同类型重复投诉问题详情",
isTab: false,
},
},
{
path: "satisfactionEval/Problem/tyqybtlx",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/Problem/tyqybtlx/list"),
name: "dataBoard-satisfactionEval-Problem-tyqybtlx-list",
meta: {
title: "同一区域不同类型重复投诉问题列表",
isTab: false,
},
},
{
path: "satisfactionEval/Problem/tyqybtlx/detail",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/Problem/tyqybtlx/detail"),
name: "dataBoard-satisfactionEval-Problem-tyqybtlx-detail",
meta: {
title: "同一区域不同类型重复投诉问题详情",
isTab: false,
},
},
{
path: "satisfactionEval/Problem/tyry",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/Problem/tyry/list"),
name: "dataBoard-satisfactionEval-Problem-tyry-list",
meta: {
title: "同一人员重复投诉问题列表",
isTab: false,
},
},
{
path: "satisfactionEval/Problem/tyry/detail",
props: true,
component: () => import("@/views/dataBoard/satisfactionEval/Problem/tyry/detail"),
name: "dataBoard-satisfactionEval-Problem-xqwmz-detail",
meta: {
title: "同一人员重复投诉问题详情",
isTab: false,
},
},
{
path: "organizational/index",
props: true,
component: () => import("@/views/dataBoard/organizational/index"),
name: "dataBoard-organizational-index",
meta: {
title: "治理架构",
isTab: false,
},
},
{
path: "404",
props: true,
component: () => import("@/views/dataBoard/404"),
name: "dataBoard-404",
meta: {
title: "页面未找到或无权访问",
isTab: false,
},
beforeEnter(to, from, next) {
// 拦截处理特殊业务场景
// 如果, 重定向路由包含__双下划线, 为临时添加路由
if (/__.*/.test(to.redirectedFrom)) {
return next(to.redirectedFrom.replace(/__.*/, ""));
}
next();
},
},
],
};
// 模块路由(基于主入口布局页面) 可视化数据
export const moduleShujuRoutes = {
path: "/main-shuju",
component: () => import("@/views/main-shuju/main"),
name: "main-shuju",
redirect: {
path: "/main-shuju/visual-basicinfo-basicInfoMain",
},
meta: {
title: "主入口布局",
},
children: [
{
path: "/main-shuju/visual-basicinfo-people/:uid",
props: true,
component: () => import("@/views/modules/visual/basicinfo/people"),
name: "visual-basicinfo-people",
meta: {
title: "个人详情",
isTab: false,
},
},
{
path: "/main-shuju/visual-basicinfo-people-list",
props: true,
component: () => import("@/views/modules/visual/basicinfo/peopleList"),
name: "visual-basicinfo-people-list",
meta: {
title: "人员列表",
isTab: false,
},
},
{
path: "404",
props: true,
component: () => import("@/views/modules/visual/404"),
name: "main-shuju-404",
meta: {
title: "页面未找到或无权访问",
isTab: false,
},
},
],
};
export function addDynamicRoute(routeParams, router) {
// 组装路由名称, 并判断是否已添加, 如是: 则直接跳转
var routeName = routeParams.routeName;
var dynamicRoute = window.SITE_CONFIG["dynamicRoutes"].filter((item) => item.name === routeName)[0];
if (dynamicRoute) {
return router.push({
name: routeName,
params: routeParams.params,
});
}
// 否则: 添加并全局变量保存, 再跳转
dynamicRoute = {
path: routeName,
component: () => import(`@/views/modules/${routeParams.path}`),
name: routeName,
meta: {
...window.SITE_CONFIG["contentTabDefault"],
menuId: routeParams.menuId,
title: `${routeParams.title}`,
},
};
router.matcher = new Router().matcher;
router.addRoutes([
{
...moduleRoutes,
name: `main-dynamic__${dynamicRoute.name}`,
children: [dynamicRoute],
},
]);
window.SITE_CONFIG["dynamicRoutes"].push(dynamicRoute);
router.push({
name: dynamicRoute.name,
params: routeParams.params,
});
}
const router = new Router({
mode: "hash",
scrollBehavior: () => ({
y: 0,
}),
routes: pageRoutes.concat(moduleRoutes, moduleShujuRoutes, dataBoardRoutes),
});
router.beforeEach((to, from, next) => {
// 添加动态(菜单)路由
// 已添加或者当前路由为页面路由, 可直接访问
let toUrl = to.meta.iframeURL
if (toUrl && toUrl.indexOf("ticket=") != -1) {
// 此处请求后端,获取一个ticket票据
http.get("/auth/sso/getTicket")
.then(({ data: res }) => {
let ticket = res.data
window.open(toUrl + ticket)
})
return null;
}
const match = location.href.match(/[?&]ticket=([^&#]+)/);
if (match && to.name == 'login') {
http.get(`/auth/xiaZhuangLogin/dealUserInfo?ticket=${match[1]}`)
.then(({ data: res }) => {
localStorage.setItem('token', res.data.token)
next({
name: 'home'
})
})
}
if (to.name === "caiji") {
return next();
}
if (to.name === 'jumin-huaxiang') {
to.meta.title = store.state.huaXiang.userInfo.name
return next();
}
if (to.name === 'house-huaxiang') {
to.meta.title = store.state.huaXiang.houseInfo.houseName
return next();
}
if (to.name === 'fangwu-huaxiang') {
to.meta.title = store.state.huaXiang.houseInfo.doorName
return next();
}
if (to.name === 'loudong-huaxiang') {
to.meta.title = store.state.huaXiang.buildingInfo.fullName
return next();
}
if (window.SITE_CONFIG["dynamicMenuRoutesHasAdded"] || fnCurrentRouteIsPageRoute(to, pageRoutes)) {
return next();
}
const customerId = localStorage.getItem("customerId");
http
.get("gov/access/menu/navDigitalCommunityNew?tableName=data_menu")
.then(({ data: res }) => {
if (res.code == 10005 || res.code == 10006 || res.code == 10007) {
message({
message: res.msg || "未知错误",
type: "error",
duration: 2 * 1000,
});
return next({
name: "login",
query: { redirect: to.fullPath }
});
}
window.SITE_CONFIG["menuShujuList"] = res.data;
fnAddDynamicMenuRoutes2(window.SITE_CONFIG["menuShujuList"]);
next({
...to,
replace: true,
});
})
.catch((err) => {
next({
name: "login",
query: { redirect: to.fullPath }
});
});
http
.get("gov/access/menu/navDigitalCommunityNew")
.then(({ data: res }) => {
if (res.code == 10005 || res.code == 10006 || res.code == 10007) {
message({
message: res.msg || "未知错误",
type: "error",
duration: 2 * 1000,
});
return next({ name: "login" });
}
window.SITE_CONFIG["menuList"] = res.data
.map((item) => cookApiDataItem3(item))
.map((item) => cookApiDataItem2(item))
.map((item) => cookApiDataItem(item));
fnAddDynamicMenuRoutes(window.SITE_CONFIG["menuList"]);
// next({ ...to, replace: true })
next({
...to,
replace: true,
});
})
.catch((err) => {
next({
name: "login",
query: { redirect: to.fullPath }
});
});
});
/**
* 判断当前路由是否为页面路由
* @param {*} route 当前路由
* @param {*} pageRoutes 页面路由
*/
function fnCurrentRouteIsPageRoute(route, pageRoutes = []) {
var temp = [];
for (var i = 0; i < pageRoutes.length; i++) {
if (route.path === pageRoutes[i].path) {
return true;
}
if (pageRoutes[i].children && pageRoutes[i].children.length >= 1) {
temp = temp.concat(pageRoutes[i].children);
}
}
return temp.length >= 1 ? fnCurrentRouteIsPageRoute(route, temp) : false;
}
/**
* 添加动态(菜单)路由
* @param {*} menuList 菜单列表
* @param {*} routes 递归创建的动态(菜单)路由
*/
function fnAddDynamicMenuRoutes(menuList = [], routes = []) {
var temp = [];
for (var i = 0; i < menuList.length; i++) {
if (menuList[i].children && menuList[i].children.length >= 1) {
temp = temp.concat(menuList[i].children);
// continue;
}
// 组装路由
var route = {
path: "",
component: null,
name: "",
meta: {
...window.SITE_CONFIG["contentTabDefault"],
menuId: menuList[i].id,
title: menuList[i].name,
btns: menuList[i].btns || [],
parent: menuList[i].parent || [],
},
};
// eslint-disable-next-line
let URL = (menuList[i].url || "").replace(/{{([^}}]+)?}}/g, (s1, s2) => eval(s2)); // URL支持{{ window.xxx }}占位符变量
if (isURL(URL)) {
if (menuList[i].children && menuList[i].children.length >= 1) {
let item = menuList[i].children.find((subMenu) => subMenu.url == menuList[i].url);
if (item) {
route["path"] = route["name"] = `i-${menuList[i].id}`;
route["redirect"] = `i-${item.id}`;
} else {
route["path"] = route["name"] = `i-${menuList[i].id}`;
route["meta"]["iframeURL"] = URL;
}
} else {
route["path"] = route["name"] = `i-${menuList[i].id}`;
route["meta"]["iframeURL"] = URL;
}
} else {
URL = URL.replace(/^\//, "").replace(/_/g, "-");
if (URL.startsWith("unopen")) {
route["path"] = route["name"] = URL.replace(/\//g, "-");
route["component"] = () => import(`@/views/modules/unopen`);
} else if (menuList[i].children && menuList[i].children.length >= 1) {
route["path"] = route["name"] = URL;
route["redirect"] = URL.replace(/\//g, "-");
} else {
route["path"] = route["name"] = URL.replace(/\//g, "-");
route["component"] = () => import(`@/views/modules/${URL}`);
}
}
routes.push(route);
}
if (temp.length >= 1) {
return fnAddDynamicMenuRoutes(temp, routes);
}
// routers.reverse();
// 添加路由
router.addRoutes([
{
...moduleRoutes,
name: "main-dynamic-menu",
children: routes,
},
{
path: "/main/*",
redirect: {
path: "/main/404",
},
},
]);
window.SITE_CONFIG["dynamicMenuRoutes"] = routes;
window.SITE_CONFIG["dynamicMenuRoutesHasAdded"] = true;
}
function fnAddDynamicMenuRoutes2(menuList = [], routes = []) {
var temp = [];
for (var i = 0; i < menuList.length; i++) {
if (menuList[i].children && menuList[i].children.length >= 1) {
temp = temp.concat(menuList[i].children);
continue;
}
// 组装路由
var route = {
path: "",
component: null,
name: "",
meta: {
// ...window.SITE_CONFIG["contentTabDefault"],
menuId: menuList[i].id,
title: menuList[i].name,
},
};
// eslint-disable-next-line
let URL = (menuList[i].url || "").replace(/{{([^}}]+)?}}/g, (s1, s2) => eval(s2)); // URL支持{{ window.xxx }}占位符变量
if (isURL(URL)) {
if (menuList[i].children && menuList[i].children.length >= 1) {
let item = menuList[i].children.find((subMenu) => subMenu.url == menuList[i].url);
if (item) {
route["path"] = route["name"] = `i-${menuList[i].id}`;
route["redirect"] = `i-${item.id}`;
} else {
route["path"] = route["name"] = `i-${menuList[i].id}`;
route["meta"]["iframeURL"] = URL;
}
} else {
route["path"] = route["name"] = `i-${menuList[i].id}`;
route["meta"]["iframeURL"] = URL;
}
} else {
URL = URL.replace(/^\//, "").replace(/_/g, "-");
if (URL.startsWith("unopen")) {
route["path"] = route["name"] = URL.replace(/\//g, "-");
route["component"] = () => import(`@/views/modules/unopen`);
} else if (menuList[i].children && menuList[i].children.length >= 1) {
route["path"] = route["name"] = URL;
route["redirect"] = URL.replace(/\//g, "-");
} else {
route["path"] = route["name"] = URL.replace(/\//g, "-");
route["component"] = () => import(`@/views/modules/${URL}`);
}
}
routes.push(route);
}
if (temp.length >= 1) {
return fnAddDynamicMenuRoutes2(temp, routes);
}
// 添加路由
router.addRoutes([
{
...moduleShujuRoutes,
name: "main-dynamic-menu-shuju",
children: routes,
},
{
path: "/main-shuju/*",
redirect: {
path: "/main-shuju/404",
},
},
]);
window.SITE_CONFIG["dynamicMenuRoutesShuju"] = routes;
window.SITE_CONFIG["dynamicMenuRoutesShujuHasAdded"] = true;
}
export default router;