diff --git a/src/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue
index ec5093d..0e97560 100644
--- a/src/layout/components/Sidebar/index.vue
+++ b/src/layout/components/Sidebar/index.vue
@@ -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 {
},
};
-
+
diff --git a/src/permission.js b/src/permission.js
index 8cd7de1..d31cb9a 100644
--- a/src/permission.js
+++ b/src/permission.js
@@ -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();
}
}
});
diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js
index 725132c..cae3194 100644
--- a/src/store/modules/permission.js
+++ b/src/store/modules/permission.js
@@ -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);
}
}
diff --git a/src/utils/request.js b/src/utils/request.js
index b35943b..2c4c305 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -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);