|
|
@ -2,6 +2,10 @@ import Vue from "vue"; |
|
|
|
import Router from "vue-router"; |
|
|
|
import Router from "vue-router"; |
|
|
|
import routes from "./routes"; |
|
|
|
import routes from "./routes"; |
|
|
|
import Setting from "@/setting"; |
|
|
|
import Setting from "@/setting"; |
|
|
|
|
|
|
|
import {get} from "@/plugins/requests/index.js"; |
|
|
|
|
|
|
|
import api from "@/api"; |
|
|
|
|
|
|
|
import util from "@/libs/util"; |
|
|
|
|
|
|
|
import { permission } from '@/router/permission'; |
|
|
|
|
|
|
|
|
|
|
|
Vue.use(Router); |
|
|
|
Vue.use(Router); |
|
|
|
|
|
|
|
|
|
|
@ -12,11 +16,61 @@ const createRouter = () => new Router({ |
|
|
|
routes |
|
|
|
routes |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function resetRouter() { |
|
|
|
export function resetRouter() { |
|
|
|
const newRouter = createRouter(); |
|
|
|
const newRouter = createRouter(); |
|
|
|
router.matcher = newRouter.matcher; |
|
|
|
router.matcher = newRouter.matcher |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let router = createRouter(); |
|
|
|
let router = createRouter(); |
|
|
|
|
|
|
|
|
|
|
|
export default router; |
|
|
|
|
|
|
|
|
|
|
|
export default router; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getPermission(){ |
|
|
|
|
|
|
|
get(api.getUserRolesPermissionMenu).then(res => { |
|
|
|
|
|
|
|
console.log(res,'权限的值') |
|
|
|
|
|
|
|
// 取得路由的值,使用addRouter添加进路由里
|
|
|
|
|
|
|
|
let permissionRouters = [] |
|
|
|
|
|
|
|
let data = res.permissionMenu[0].children
|
|
|
|
|
|
|
|
if(data.length>0){ |
|
|
|
|
|
|
|
data.forEach(e=>{ |
|
|
|
|
|
|
|
// 循环,取得主路由以及路由信息,重复循环,取得
|
|
|
|
|
|
|
|
let obj = { |
|
|
|
|
|
|
|
path:e.path, |
|
|
|
|
|
|
|
name:e.name, |
|
|
|
|
|
|
|
component:`../pages${e.path}`, |
|
|
|
|
|
|
|
meta:[], |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 取得页面内的次级路由以及页面按钮
|
|
|
|
|
|
|
|
if(e.children&&e.children.length>0){ |
|
|
|
|
|
|
|
// 先判断是否有path,有就是页面
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
// 其他的是按钮
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 权限
|
|
|
|
|
|
|
|
router.beforeEach((to,from,next)=>{ |
|
|
|
|
|
|
|
if(to.path == '/login'){ |
|
|
|
|
|
|
|
localStorage.removeItem(Setting.tokenKey) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(util.local.get(Setting.tokenKey)){ |
|
|
|
|
|
|
|
if(!sessionStorage.getItem('handelPermission')){ |
|
|
|
|
|
|
|
getPermission() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
if (to.path !== '/login') { |
|
|
|
|
|
|
|
next({ path: '/login', |
|
|
|
|
|
|
|
query:{redirect:to.path} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
next() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |