|
|
|
|
import Vue from 'vue'
|
|
|
|
|
import VueRouter from 'vue-router'
|
|
|
|
|
|
|
|
|
|
// const files = require.context('@/views', true, /-router\.js$/)
|
|
|
|
|
// let allRouter = [];
|
|
|
|
|
// // 匹配成功的名字数组
|
|
|
|
|
// files.keys().map(key => {
|
|
|
|
|
// allRouter = allRouter.concat(files(key).default)
|
|
|
|
|
// })
|
|
|
|
|
// allRouter.sort((a, b) => {
|
|
|
|
|
// return a.meta.sort - b.meta.sort
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
// console.log(allRouter)
|
|
|
|
|
|
|
|
|
|
Vue.use(VueRouter)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 避免冗余导航 (重复点击菜单栏报错问题)
|
|
|
|
|
const originalPush = VueRouter.prototype.push
|
|
|
|
|
VueRouter.prototype.push = function push(location) {
|
|
|
|
|
return originalPush.call(this, location).catch(err => err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const routes = [{
|
|
|
|
|
path: '/',
|
|
|
|
|
redirect: {
|
|
|
|
|
name: 'history'
|
|
|
|
|
},
|
|
|
|
|
component: () => import('@/views/index'),
|
|
|
|
|
children: [
|
|
|
|
|
// {
|
|
|
|
|
// path: 'realTime',
|
|
|
|
|
// name: 'realTime',
|
|
|
|
|
// meta: {
|
|
|
|
|
// icon: 'global',
|
|
|
|
|
// name: '实时监控'
|
|
|
|
|
// },
|
|
|
|
|
// component: () => import('@/views/realTime/index')
|
|
|
|
|
// },
|
|
|
|
|
{
|
|
|
|
|
path: 'history',
|
|
|
|
|
name: 'history',
|
|
|
|
|
meta: {
|
|
|
|
|
icon: 'desktop',
|
|
|
|
|
name: '历史监控'
|
|
|
|
|
},
|
|
|
|
|
component: () => import('@/views/historyMonitoring/index')
|
|
|
|
|
}, {
|
|
|
|
|
path: 'roadwayManage',
|
|
|
|
|
name: 'roadwayManage',
|
|
|
|
|
meta: {
|
|
|
|
|
icon: 'build',
|
|
|
|
|
name: '巷道管理'
|
|
|
|
|
},
|
|
|
|
|
component: () => import('@/views/roadwayManage/index')
|
|
|
|
|
}, {
|
|
|
|
|
path: 'cameraManage',
|
|
|
|
|
name: 'cameraManage',
|
|
|
|
|
meta: {
|
|
|
|
|
icon: 'video-camera',
|
|
|
|
|
name: '球机管理'
|
|
|
|
|
},
|
|
|
|
|
component: () => import('@/views/cameraManage/index')
|
|
|
|
|
},{
|
|
|
|
|
path: 'center',
|
|
|
|
|
name: 'center',
|
|
|
|
|
meta: {
|
|
|
|
|
name: '个人中心'
|
|
|
|
|
},
|
|
|
|
|
component: () => import('@/views/center')
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/guide',
|
|
|
|
|
name: 'guide',
|
|
|
|
|
component: () => import('../views/guide.vue')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '*',
|
|
|
|
|
name: '404',
|
|
|
|
|
component: () => import('../views/404.vue')
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const router = new VueRouter({
|
|
|
|
|
routes
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
|
next()
|
|
|
|
|
// let userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}')
|
|
|
|
|
// // 校验是否登录
|
|
|
|
|
// if (userInfo.id) {
|
|
|
|
|
// // 匹配不到 404
|
|
|
|
|
// if (!to.name) next();
|
|
|
|
|
// // 权限
|
|
|
|
|
// if (userInfo.permissionList.some((item) => {
|
|
|
|
|
// return item.rights === to.name
|
|
|
|
|
// })) {
|
|
|
|
|
// next()
|
|
|
|
|
// } else {
|
|
|
|
|
// if (to.name === 'login') {
|
|
|
|
|
// next()
|
|
|
|
|
// } else {
|
|
|
|
|
// Vue.prototype.$message.info('没有权限')
|
|
|
|
|
// next(false)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// if (to.name === 'login') {
|
|
|
|
|
// next()
|
|
|
|
|
// } else if (to.name !== 'login') {
|
|
|
|
|
// Vue.prototype.$message.info('请先登录')
|
|
|
|
|
// next('/login')
|
|
|
|
|
// } else {
|
|
|
|
|
// next('/login')
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default router
|