|
@@ -1,20 +1,19 @@
|
|
|
// import Vue from 'vue'
|
|
|
-import App from './App'
|
|
|
-import store from './vuex/store'
|
|
|
-import routes from './routes'
|
|
|
-
|
|
|
// import VueRouter from 'vue-router'
|
|
|
// Vue.use(VueRouter)
|
|
|
-
|
|
|
// import ElementUI from 'element-ui'
|
|
|
// Vue.use(ElementUI)
|
|
|
-
|
|
|
// import Vuex from 'vuex'
|
|
|
// Vue.use(Vuex)
|
|
|
+// import echarts from 'echarts'
|
|
|
+// import 'element-ui/lib/theme-chalk/index.css'
|
|
|
+
|
|
|
+import App from './App'
|
|
|
+import store from './vuex/store'
|
|
|
+// import routes from './routes'
|
|
|
|
|
|
import http from './http'
|
|
|
import port from './port'
|
|
|
-// import echarts from 'echarts'
|
|
|
import $ from 'jquery'
|
|
|
|
|
|
Vue.prototype.http = http
|
|
@@ -24,17 +23,19 @@ Vue.prototype.echarts = echarts
|
|
|
import VueClipboard from 'vue-clipboard2'
|
|
|
Vue.use(VueClipboard)
|
|
|
|
|
|
-// import 'element-ui/lib/theme-chalk/index.css'
|
|
|
import 'font-awesome/css/font-awesome.min.css'
|
|
|
import './assets/iconfont/iconfont.css'
|
|
|
|
|
|
-const router = new VueRouter({
|
|
|
- routes
|
|
|
-})
|
|
|
+// const router = new VueRouter({
|
|
|
+// routes
|
|
|
+// })
|
|
|
+import { staffRouter, manageRouter, fixedRouter } from './routes'
|
|
|
+import router from './routes'
|
|
|
|
|
|
import NProgress from 'nprogress'
|
|
|
import 'nprogress/nprogress.css'
|
|
|
|
|
|
+var addRouFlag = false
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
NProgress.start();
|
|
|
if (to.path == '/register') {
|
|
@@ -50,10 +51,51 @@ router.beforeEach((to, from, next) => {
|
|
|
if (!user && to.path != '/login') {
|
|
|
next({ path: '/login' })
|
|
|
} else {
|
|
|
+ if (!addRouFlag) {
|
|
|
+ addRouFlag = true
|
|
|
+ if(user != null) {
|
|
|
+ if(user.role == 0) {
|
|
|
+ var getRoutes = baseRoleGetRouters(staffRouter, 1);
|
|
|
+ global.antRouter = fixedRouter.concat(getRoutes);
|
|
|
+ router.options.routes = fixedRouter.concat(getRoutes);
|
|
|
+ router.addRoutes(fixedRouter.concat(getRoutes));
|
|
|
+ router.push({ path: to.path })
|
|
|
+ } else {
|
|
|
+ var getRoutes = baseRoleGetRouters(manageRouter, 1);
|
|
|
+ global.antRouter = fixedRouter.concat(getRoutes);
|
|
|
+ router.options.routes = fixedRouter.concat(getRoutes);
|
|
|
+ router.addRoutes(fixedRouter.concat(getRoutes));
|
|
|
+ router.push({ path: to.path })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
next()
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+function baseRoleGetRouters(allRoutes, roles) {
|
|
|
+ // allRoutes是动态路由表
|
|
|
+ // roles是取到的用户角色,数组
|
|
|
+ let rightRoutes = allRoutes.filter((route, index) => {
|
|
|
+ if (true) {
|
|
|
+ if (route.children && route.children.length) {
|
|
|
+ route.children = baseRoleGetRouters(route.children, roles)
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ })
|
|
|
+ return rightRoutes
|
|
|
+}
|
|
|
+
|
|
|
+function hasPermission(route, roles) {
|
|
|
+ if (route.meta && route.meta.roles) {
|
|
|
+ return roles.some(role => route.meta.roles.indexOf(role) >= 0)
|
|
|
+ } else {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
router.afterEach(() => {
|
|
|
NProgress.done()
|
|
|
})
|