dev
许宏杰 1 year ago
parent 8bcc4e6577
commit 7705b2bc6b

@ -36,7 +36,6 @@ export default {
...mapGetters(["sidebarRouters", "sidebar"]),
activeMenu() {
const route = this.$route;
console.log(route);
const { meta, path } = route;
// if set path, the sidebar will highlight the path you set
if (meta.activeMenu) {
@ -56,6 +55,4 @@ export default {
},
};
</script>
<style lang="scss" scoped>
</style>
<style lang="scss" scoped></style>

@ -8,21 +8,71 @@ import { isRelogin } from "@/utils/request";
NProgress.configure({ showSpinner: false });
const whiteList = [
"/login",
"/register",
"/3dmodel",
"/volunteer/userbq/bqhsj",
"/volunteer/userbq/dictGl",
"/volunteer/hdtj/hdGl",
"/volunteer/yzczs/ycxzsff",
"/volunteer/gxhzs/gxhzsgl",
"/volunteer/gxhzs/gxhzsff",
];
const whiteList = ["/login", "/register", "/3dmodel"];
router.beforeEach((to, from, next) => {
let { isFromVolunteer, tel } = to.query;
NProgress.start();
let { isFromVolunteer, tel } = to.query;
if (isFromVolunteer || tel) {
let userName;
if (tel) {
userName = atob(tel); //志愿者
} else {
userName = "15937192537"; //管理员
}
if (!getToken()) {
if (whiteList.indexOf(to.path) !== -1) {
// 没有token
// 在免登录白名单,直接进入
store.commit("SET_IS_MENU_HEADER", false); //不显示左侧菜单,头部标题
next();
} else {
// next(`/login?redirect=${encodeURIComponent(to.fullPath)}`); // 否则全部重定向到登录页
store
.dispatch("Login", {
username: userName,
password: "123456",
})
.then(() => {
to.meta.title && store.dispatch("settings/setTitle", to.meta.title);
/* has token*/
if (to.path === "/login") {
next({ path: "/" });
NProgress.done();
} else {
store.commit(
"SET_IS_MENU_HEADER",
isFromVolunteer ? false : true
);
if (store.getters.roles.length === 0) {
isRelogin.show = true;
// 判断当前用户是否已拉取完user_info信息
store
.dispatch("GetInfo")
.then(() => {
isRelogin.show = false;
store.dispatch("GenerateRoutes").then((accessRoutes) => {
// 根据roles权限生成可访问的路由表
router.addRoutes(accessRoutes); // 动态添加可访问路由表
next({ ...to, replace: true }); // hack方法 确保addRoutes已完成
});
})
.catch((err) => {
store.dispatch("LogOut").then(() => {
Message.error(err);
next({ path: "/" });
});
});
} else {
next();
}
}
});
}
}
}
if (getToken()) {
to.meta.title && store.dispatch("settings/setTitle", to.meta.title);
/* has token*/
@ -55,25 +105,14 @@ router.beforeEach((to, from, next) => {
}
}
} else {
if (tel) {
// store
// .dispatch("Login", {
// username: "15937192537",
// password: "123456",
// })
// .then(() => {
// store.commit("SET_IS_MENU_HEADER", false);
// });
if (whiteList.indexOf(to.path) !== -1) {
// 没有token
// 在免登录白名单,直接进入
store.commit("SET_IS_MENU_HEADER", false); //不显示左侧菜单,头部标题
next();
} else {
if (whiteList.indexOf(to.path) !== -1) {
// 没有token
// 在免登录白名单,直接进入
store.commit("SET_IS_MENU_HEADER", false); //不显示左侧菜单,头部标题
next();
} else {
next(`/login?redirect=${encodeURIComponent(to.fullPath)}`); // 否则全部重定向到登录页
NProgress.done();
}
// next(`/login?redirect=${encodeURIComponent(to.fullPath)}`); // 否则全部重定向到登录页
NProgress.done();
}
}
});

@ -81,7 +81,6 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
} else if (route.component === "InnerLink") {
route.component = InnerLink;
} else {
console.log("组件", route.component);
route.component = loadView(route.component);
}
}

@ -28,9 +28,13 @@ service.interceptors.request.use(
const isToken = (config.headers || {}).isToken === false;
// 是否需要防止数据重复提交
const isRepeatSubmit = (config.headers || {}).repeatSubmit === false;
if (getToken() && !isToken) {
config.headers["Authorization"] = "Bearer " + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
}
// if (config.url == "/getInfo" || config.url == "/getRouters") {
// config.headers["Authorization"] = "Bearer " + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
// }
// get请求映射params参数
if (config.method === "get" && config.params) {
let url = config.url + "?" + tansParams(config.params);

Loading…
Cancel
Save