|
|
|
import { constantRoutes } from '@/router'
|
|
|
|
import { getRouters } from '@/api/menu'
|
|
|
|
import Layout from '@/layout/index'
|
|
|
|
|
|
|
|
const permission = {
|
|
|
|
state: {
|
|
|
|
routes: [],
|
|
|
|
addRoutes: []
|
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
SET_ROUTES: (state, routes) => {
|
|
|
|
state.addRoutes = routes
|
|
|
|
state.routes = constantRoutes.concat(routes)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
// 生成路由
|
|
|
|
GenerateRoutes({ commit }) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
// 向后端请求路由数据
|
|
|
|
getRouters().then(res => {
|
|
|
|
// 临时手动添加路由
|
|
|
|
res.data.push(
|
|
|
|
{
|
|
|
|
component: "Layout",
|
|
|
|
alwaysShow: true,
|
|
|
|
hidden: false,
|
|
|
|
meta: { title: "运行管护", icon: "icon-yxgh" },
|
|
|
|
name: "RunManage",
|
|
|
|
path: "/runManage",
|
|
|
|
redirect: "noRedirect",
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
component: "runManage/engineering",
|
|
|
|
alwaysShow: true,
|
|
|
|
hidden: false,
|
|
|
|
meta: { title: "工程巡查", icon: "icon-gcxc" },
|
|
|
|
name: "Engineering",
|
|
|
|
path: "/engineering",
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
component: "runManage/engineering/inspectionItems",
|
|
|
|
hidden: false,
|
|
|
|
meta: { title: "巡查项目管理", icon: "icon-xcxmgl" },
|
|
|
|
name: "InspectionItems",
|
|
|
|
path: "/inspectionItems"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: "runManage/engineering/inspectionPlan",
|
|
|
|
hidden: false,
|
|
|
|
meta: { title: "巡查计划管理", icon: "icon-xcjhgl" },
|
|
|
|
name: "InspectionPlan",
|
|
|
|
path: "/inspectionPlan"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: "runManage/engineering/patrolRouteSettings",
|
|
|
|
hidden: true,
|
|
|
|
meta: { title: "巡查路线设置", icon: "" },
|
|
|
|
name: "PatrolRouteSettings",
|
|
|
|
path: "/patrolRouteSettings"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: "runManage/engineering/inspectionRecords",
|
|
|
|
hidden: false,
|
|
|
|
meta: { title: "巡查记录", icon: "icon-xcjl" },
|
|
|
|
name: "InspectionRecords",
|
|
|
|
path: "/inspectionRecords"
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: "runManage/maintenance",
|
|
|
|
alwaysShow: true,
|
|
|
|
hidden: false,
|
|
|
|
meta: { title: "维修养护", icon: "icon-wxyh" },
|
|
|
|
name: "Maintenance",
|
|
|
|
path: "/maintenance",
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
component: "runManage/maintenance/maintenancePlan",
|
|
|
|
hidden: false,
|
|
|
|
meta: { title: "维修计划管理", icon: "icon-wxjhgl" },
|
|
|
|
name: "MaintenancePlan",
|
|
|
|
path: "/maintenancePlan"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: "runManage/maintenance/maintenanceRecords",
|
|
|
|
hidden: false,
|
|
|
|
meta: { title: "维修记录", icon: "icon-wxjl" },
|
|
|
|
name: "MaintenanceRecords",
|
|
|
|
path: "/maintenanceRecords"
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
const accessedRoutes = filterAsyncRouter(res.data)
|
|
|
|
accessedRoutes.push({ path: '*', redirect: '/404', hidden: true })
|
|
|
|
commit('SET_ROUTES', accessedRoutes)
|
|
|
|
resolve(accessedRoutes)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 遍历后台传来的路由字符串,转换为组件对象
|
|
|
|
function filterAsyncRouter(asyncRouterMap) {
|
|
|
|
return asyncRouterMap.filter(route => {
|
|
|
|
if (route.component) {
|
|
|
|
// Layout组件特殊处理
|
|
|
|
if (route.component === 'Layout') {
|
|
|
|
route.component = Layout
|
|
|
|
} else {
|
|
|
|
route.component = loadView(route.component)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (route.children != null && route.children && route.children.length) {
|
|
|
|
route.children = filterAsyncRouter(route.children)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const loadView = (view) => { // 路由懒加载
|
|
|
|
return (resolve) => require([`@/views/${view}`], resolve)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default permission
|