dev_2022-05-11
e 3 years ago
parent 79371fd904
commit 3de4978093
  1. 1
      src/api/index.js
  2. 25
      src/router/index.js
  3. 46
      src/router/permission.js

@ -6,7 +6,6 @@ let host = 'http://192.168.31.137:9000/'; // 赓
// let host = "http://39.108.250.202:9000/"; // 测试服
let uploadURL = Setting.upload.apiURL;
let host1 = "http://39.108.250.202:8080/"; // 川大

@ -41,11 +41,30 @@ function getPermission(){
name:e.name,
component:`../pages${e.path}`,
meta:[],
children:[]
}
// 取得页面内的次级路由以及页面按钮
if(e.children&&e.children.length>0){
// 先判断是否有path,有就是页面
e
let meta = []
let children = []
e.children.forEach(i=>{
// 先判断是否有path,有就是页面,页面需要额外进入children,
if(i.path){
let obj = {
path:i.path,
name:i.name,
component:`../pages${i.path}`,
meta:[],
}
// 额外处理该页面的按钮,只有两级,懒得递归
if(i.children&&i.children.length>0){
}
children.push(obj)
}else{
meta.push(i.name)
}
})
// 其他的是按钮
}
@ -55,7 +74,7 @@ function getPermission(){
})
}
// 权限
router.beforeEach((to,from,next)=>{
router.beforeEach(function(to,from,next){
if(to.path == '/login'){
localStorage.removeItem(Setting.tokenKey)
}

@ -2,26 +2,26 @@ import router from "./index";
import Setting from "@/setting";
import util from "@/libs/util";
router.beforeEach((to, from, next) => {
document.title = Setting.titleSuffix;
const role = util.local.get(Setting.tokenKey);
if (!role && to.path !== "/login") {
next("/login");
} else if (role && to.path == "/login") {
next("/index");
} else {
let mg = from.query.mg;
if (mg) {
if (!to.query.mg) {
next({
path: to.path,
query: { mg }
});
} else {
next();
}
} else {
next();
}
}
});
// router.beforeEach((to, from, next) => {
// document.title = Setting.titleSuffix;
// const role = util.local.get(Setting.tokenKey);
// if (!role && to.path !== "/login") {
// next("/login");
// } else if (role && to.path == "/login") {
// next("/index");
// } else {
// let mg = from.query.mg;
// if (mg) {
// if (!to.query.mg) {
// next({
// path: to.path,
// query: { mg }
// });
// } else {
// next();
// }
// } else {
// next();
// }
// }
// });
Loading…
Cancel
Save