|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|