Commit 1dc7c8b2 by 吕海涛

增加业务配置

parent 654b6802
import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout'
import {routerMode} from '@/config/index'
import { routerMode } from '@/config/index'
import store from '@/store/index'
Vue.use(VueRouter)
......@@ -10,115 +10,153 @@ Vue.use(VueRouter)
* 静态路由
* @type {({path: string, component: (function(): *), hidden: boolean}|{path: string, component: (function(): *), hidden: boolean, name: string}|{path: string, component: (function(): *), hidden: boolean, name: string})[]}
*/
export const currencyRoutes = [
{
path: '/login',
component: () =>
import(/* webpackChunkName: "login" */ '@/views/login/index.vue'),
hidden: true
},
{
path: '/401',
name: '401',
component: () => import('@/views/401'),
hidden: true
},
{
path: '/404',
name: '404',
component: () => import('@/views/404'),
hidden: true
}
export const currencyRoutes = [{
path: '/login',
component: () =>
import ( /* webpackChunkName: "login" */ '@/views/login/index.vue'),
hidden: true
},
{
path: '/401',
name: '401',
component: () =>
import ('@/views/401'),
hidden: true
},
{
path: '/404',
name: '404',
component: () =>
import ('@/views/404'),
hidden: true
}
]
/**
* 动态路由
* @type {any}
*/
export const routes = [
{
path: '/',
name: 'Company',
component: Layout,
redirect: '/company',
meta: {
icon: 'el-icon-office-building',
title: '企业管理'
},
children: [{
path: '/',
name: 'CompanyInformation',
component: () =>
import('@/views/dashboard/index.vue'),
meta: {
title: '企业信息',
icon: 'el-icon-s-data'
}
}]
}
]
export const routes = [{
path: '/',
name: 'Company',
component: Layout,
redirect: '/company',
meta: {
icon: 'el-icon-office-building',
title: '企业管理'
},
children: [{
path: '/',
name: 'CompanyInformation',
component: () =>
import ('@/views/dashboard/index.vue'),
meta: {
title: '企业信息',
icon: 'el-icon-s-data'
}
},
{
path: 'department-information',
name: 'DepartmentInformation',
component: () =>
import ('@/views/DepartmentInformation/index.vue'),
meta: { title: '部门管理', icon: 'el-icon-user-solid' }
},
]
}, {
path: '/configure',
name: 'configure',
component: Layout,
redirect: '/configure',
meta: {
icon: 'el-icon-setting',
title: '业务配置'
},
children: [{
path: 'enclosure',
name: 'Enclosure',
component: () =>
import ('@/views/configure/enclosure.vue'),
meta: { title: '围栏管理', icon: 'el-icon-aim' }
},
{
path: 'CarModel',
name: 'CarModel',
component: () =>
import ('@/views/configure/CarModel.vue'),
meta: { title: '车型管理', icon: 'el-icon-s-data' }
},
{
path: 'site',
name: 'Site',
component: () =>
import ('@/views/configure/site.vue'),
meta: { title: '站点管理', icon: 'el-icon-s-home' }
},
]
}]
const router = new VueRouter({
base: '',
mode: routerMode,
scrollBehavior: () => ({
y: 0
}),
routes: currencyRoutes
base: '',
mode: routerMode,
scrollBehavior: () => ({
y: 0
}),
routes: currencyRoutes
})
// 解决addRoute不能删除动态路由问题
export function resetRouter() {
router.matcher = new VueRouter({
base: '',
mode: routerMode,
scrollBehavior: () => ({
y: 0
}),
routes: currencyRoutes
}).matcher
router.matcher = new VueRouter({
base: '',
mode: routerMode,
scrollBehavior: () => ({
y: 0
}),
routes: currencyRoutes
}).matcher
}
// 导航守卫 验证是否登录了 没有登录跳转到登录页面
router.beforeEach(async (to, from, next) => {
if (to.path === '/login') {
next()
} else {
let user = store.getters.token
let hasRoles = store.getters.roles
let roleType = store.state.user.roleType
if (user) {
if (hasRoles.length <= 0) {
try {
const {
roles
} = await store.dispatch('user/getRoutes')
let addRoutes;
// if (roleType == 2) {
addRoutes = await store.dispatch('permission/getRoutes', roles)
// } else {
// addRoutes = await store.dispatch('permission/getAsyncRoutes', roles)
// }
router.addRoutes(addRoutes)
next({
...to,
replace: true
})
} catch (error) {
// Message.error('此路不通')
}
} else {
next()
}
} else {
next({
path: '/login',
query: {
redirect: to.fullPath
}
})
}
}
router.beforeEach(async(to, from, next) => {
if (to.path === '/login') {
next()
} else {
let user = store.getters.token
let hasRoles = store.getters.roles
let roleType = store.state.user.roleType
if (user) {
if (hasRoles.length <= 0) {
try {
const {
roles
} = await store.dispatch('user/getRoutes')
let addRoutes;
// if (roleType == 2) {
addRoutes = await store.dispatch('permission/getRoutes', roles)
// } else {
// addRoutes = await store.dispatch('permission/getAsyncRoutes', roles)
// }
router.addRoutes(addRoutes)
next({
...to,
replace: true
})
} catch (error) {
// Message.error('此路不通')
}
} else {
next()
}
} else {
next({
path: '/login',
query: {
redirect: to.fullPath
}
})
}
}
})
export default router
export default router
\ No newline at end of file
<template xmlns="http://www.w3.org/1999/html">
<el-card style="text-align: left;" type="flex" justify="end" align="end">
车型
</el-card>
</template>
<script>
export default {
name: "CarModel",
data() {
return {
info: 'baaaaaaaaaaa'
}
}
}
</script>
<style scoped lang="scss">
div {
}
</style>
<template xmlns="http://www.w3.org/1999/html">
<el-card style="text-align: left;" type="flex" justify="end" align="end">
围栏
</el-card>
</template>
<script>
export default {
name: "enclosure",
data() {
return {
info: 'baaaaaaaaaaa'
}
}
}
</script>
<style scoped lang="scss">
div {
}
</style>
<template xmlns="http://www.w3.org/1999/html">
<el-card style="text-align: left;" type="flex" justify="end" align="end">
站点
</el-card>
</template>
<script>
export default {
name: "site",
data() {
return {
info: 'baaaaaaaaaaa'
}
}
}
</script>
<style scoped lang="scss">
div {
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment