import Vue from "vue"; import Router from "vue-router"; import store from "@/store"; import { getSession, removeSession, message } from "./../util/item"; const routerPush = Router.prototype.push; Router.prototype.push = function push(location) { return routerPush.call(this, location).catch(error => error); }; Vue.use(Router); import axios from "axios"; import qs from "qs"; Vue.prototype.$axios = axios; //全局注册,使用方法为:this.$axios Vue.prototype.qs = qs; //全局注册,使用方法为:this.qs const router = new Router({ routes: [ { path: "/index", name: "index", component: resolve => require(["@/components/index.vue"], resolve), children: [ { path: "/welcome", name: "welcome", component: resolve => require(["@/components/welcome"], resolve) }, { path: "/overview", name: "overview", component: resolve => require(["@/components/overview"], resolve) }, { path: "/site/previewOfSiteStatus", //站点状况预览图--站点状况预览图 name: "PreviewOfSiteStatus", component: resolve => require(["@/components/site/previewOfSiteStatus"], resolve) }, { path: "/newFiber/NewFiberSearch", //新烽查询系统 name: "NewFiberSearch", component: resolve => require(["@/components/newFiber/NewFiberSearch"], resolve) }, { path: "/configure/AlarmConfiguration", // 配置中心--报警配置 name: "AlarmConfiguration", component: resolve => require(["@/components/configure/AlarmConfiguration"], resolve) }, { path: "/configure/RtuConfig", // 配置中心--rtu配置 name: "RtuConfig", component: () => import("@/components/configure/RtuConfig") }, { path: "/configure/PushRules", // 配置中心--推送规则 name: "PushRules", component: resolve => require(["@/components/configure/PushRules"], resolve) }, { path: "/configure/AlarmLog", // 配置中心--报警日志 name: "AlarmLog", component: resolve => require(["@/components/configure/AlarmLog"], resolve) }, { path: "/configure/PatrolConfiguration", // 配置中心--巡检配置 name: "PatrolConfiguration", component: resolve => require(["@/components/configure/PatrolConfiguration"], resolve) }, { path: "/ConfigManager/project", // 配置管理--项目设置 name: "ProjectConfigManager", component: resolve => require(["@/components/ConfigManager/project"], resolve) }, { path: "/ConfigManager/SiteManagement", // 配置管理--站点设置 name: "SiteManagement", component: resolve => require(["@/components/ConfigManager/SiteManagement"], resolve) }, { path: "/ConfigManager/device", // 配置管理--设备管理 name: "DeviceConfigManager", component: resolve => require(["@/components/ConfigManager/device"], resolve) }, { path: "/ConfigManager/factor", // 配置管理--因子管理 name: "FactorConfigManager", component: resolve => require(["@/components/ConfigManager/factor"], resolve) }, { path: "/MessageManagement/MessageQuery", // 消息管理--消息查询 name: "MessageQuery", component: resolve => require(["@/components/MessageManagement/MessageQuery"], resolve) }, { path: "/MessageManagement/MessageStatistics", // 消息管理--消息统计 name: "MessageStatistics", component: resolve => require([ "@/components/MessageManagement/MessageStatistics" ], resolve) }, { path: "/DataAnalysis/dataScreening", // 数据分析--数据总览 name: "DataScreening", component: resolve => require(["@/components/DataAnalysis/dataScreening"], resolve) }, { path: "/DataAnalysis/StatisticalReport", // 数据分析--统计报表 name: "StatisticalReport", component: resolve => require(["@/components/DataAnalysis/StatisticalReport"], resolve) }, { path: "/Engineering/Nowfault", // 查询实时故障数据 name: "Nowfault", component: resolve => require(["@/components/Engineering/Nowfault"], resolve) }, { path: "/Engineering/HistoricalFault", // 查询历史故障数据 name: "HistoricalFault", component: resolve => require(["@/components/Engineering/HistoricalFault"], resolve) }, { path: "/Engineering/MyHomework", // 查询历史故障数据 name: "MyHomework", component: resolve => require(["@/components/Engineering/MyHomework"], resolve) }, { path: "/LED/LEDConfig", //LED屏 name: "LEDConfig", component: resolve => require(["@/components/LED/LEDConfig"], resolve) }, { path: "/sys/user", //用户管理 name: "user", component: resolve => require(["@/components/sys/user"], resolve) }, { path: "/sys/menu", //菜单管理 name: "menu", component: resolve => require(["@/components/sys/menu"], resolve) }, { path: "/sys/org", //组织信息 name: "org", component: resolve => require(["@/components/sys/org"], resolve) }, { path: "/sys/role", //角色管理 name: "role", component: resolve => require(["@/components/sys/role"], resolve) } ] }, { path: "/Login", name: "login", component: resolve => require(["@/components/login"], resolve) }, { path: "/", redirect: "/Login" }, { path: "*", redirect: "/" } ] }); router.beforeEach((to, from, next) => { /* 使用过程为, 先判断vuex里面一条数据, 判断是否登陆 */ if (to.name === "login") { next(); } else if (JSON.parse(getSession("logins")) === "true") { if (!store.state.common.allDept.length) { store .dispatch("common/getAllDept") .then(res => { store.dispatch("common/getAllCity").then(() => { // store.dispatch("common/getAllCity"); }); }) .catch(e => { console.log(777, e); removeSession("logins"); next("/Login"); }); } next(); } else { message({ data: { code: 1, message: "登录已过期,请重新登录!" } }); next(`/Login`); } }); export default router;