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 host = "http://39.108.250.202:9000/"; // 测试服
let uploadURL = Setting.upload.apiURL; let uploadURL = Setting.upload.apiURL;
let host1 = "http://39.108.250.202:8080/"; // 川大 let host1 = "http://39.108.250.202:8080/"; // 川大

@ -41,11 +41,30 @@ function getPermission(){
name:e.name, name:e.name,
component:`../pages${e.path}`, component:`../pages${e.path}`,
meta:[], meta:[],
children:[]
} }
// 取得页面内的次级路由以及页面按钮 // 取得页面内的次级路由以及页面按钮
if(e.children&&e.children.length>0){ if(e.children&&e.children.length>0){
// 先判断是否有path,有就是页面 let meta = []
e 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'){ if(to.path == '/login'){
localStorage.removeItem(Setting.tokenKey) localStorage.removeItem(Setting.tokenKey)
} }

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