Browse Source

Merge pull request #88 from zhou151/master

new file routes
good luck 4 years ago
parent
commit
acc7c0f9ad
2 changed files with 16 additions and 22 deletions
  1. 7 10
      src/store/modules/routes.js
  2. 9 12
      src/utils/request.js

+ 7 - 10
src/store/modules/routes.js

@@ -24,16 +24,13 @@ const mutations = {
 };
 const actions = {
   async setRoutes({ commit }, permissions) {
-    //防止污染路由
-    const baseRoutes = [...asyncRoutes];
-    let accessedRoutes = [];
-    if (permissions.includes("admin")) {
-      accessedRoutes = baseRoutes;
-    } else {
-      accessedRoutes = await filterAsyncRoutes(baseRoutes, permissions);
-    }
-    commit("setRoutes", accessedRoutes);
-    return accessedRoutes;
+    //开源版只过滤动态路由permissions,admin不再默认拥有全部权限
+    const finallyAsyncRoutes = await filterAsyncRoutes(
+      [...asyncRoutes],
+      permissions
+    );
+    commit("setRoutes", finallyAsyncRoutes);
+    return finallyAsyncRoutes;
   },
   async setAllRoutes({ commit }) {
     let { data } = await getRouterList();

+ 9 - 12
src/utils/request.js

@@ -5,7 +5,7 @@ import {
   contentType,
   debounce,
   invalidCode,
-  noPermissionCode,
+  noRoleCode,
   requestTimeout,
   successCode,
   tokenName,
@@ -19,7 +19,7 @@ import { isArray } from "@/utils/validate";
 let loadingInstance;
 
 /**
- * @copyright chuzhixin 1204505056@qq.com
+ * @author chuzhixin 1204505056@qq.com
  * @description 判断当前url是否需要加loading
  * @param {*} config
  * @returns
@@ -35,7 +35,7 @@ const needLoading = (config) => {
 };
 
 /**
- * @copyright chuzhixin 1204505056@qq.com
+ * @author chuzhixin 1204505056@qq.com
  * @description 处理code异常
  * @param {*} code
  * @param {*} msg
@@ -44,13 +44,15 @@ const handleCode = (code, msg) => {
   switch (code) {
     case invalidCode:
       Vue.prototype.$baseMessage(msg || `后端接口${code}异常`, "error");
+
       store.dispatch("user/resetAccessToken").catch(() => {});
-      //开启登录拦截才需要刷新,不然死循环
+
       if (loginInterception) {
         location.reload();
       }
+
       break;
-    case noPermissionCode:
+    case noRoleCode:
       router.push({ path: "/401" }).catch(() => {});
       break;
     default:
@@ -65,6 +67,7 @@ const instance = axios.create({
   headers: {
     "Content-Type": contentType,
   },
+  //withCredentials: true,
 });
 
 instance.interceptors.request.use(
@@ -72,12 +75,6 @@ instance.interceptors.request.use(
     if (store.getters["user/accessToken"]) {
       config.headers[tokenName] = store.getters["user/accessToken"];
     }
-    //这里会过滤所有为空、0、false的key,如果不需要请自行注释
-    if (config.data)
-      config.data = Vue.prototype.$baseLodash.pickBy(
-        config.data,
-        Vue.prototype.$baseLodash.identity
-      );
 
     if (
       contentType === "application/x-www-form-urlencoded;charset=UTF-8" &&
@@ -100,7 +97,7 @@ instance.interceptors.response.use(
   (response) => {
     if (loadingInstance) loadingInstance.close();
 
-    const { status, data, config } = response;
+    const { data, config } = response;
     const { code, msg } = data;
     // 操作正常Code数组
     const codeVerificationArray = isArray(successCode)