فهرست منبع

合并代码+ 添加菜单码

林倩 4 سال پیش
والد
کامیت
3816bdd454

+ 1 - 1
config/dev.env.js

@@ -28,7 +28,7 @@ module.exports = merge(prodEnv, {
 
     // 布局结构配置,可选项包含 `layout-menu-top`, `layout`
     LAYOUT: '"layout"',
-
+    PORT: "8871",
     //是否启用本地mock
     IS_MOCK: "false",
     PROT: "8871",

+ 1 - 1
config/dev.env.js-deploy

@@ -16,7 +16,7 @@ module.exports = merge(prodEnv, {
     //MODULE2: '"/easy-mock2"',
 
     //是否需要登录验证
-    NEED_LOGIN: "true",
+    NEED_LOGIN: "false",
 
     //需要依赖的系统名称
     //INSTALLED_PROJECT: "'zfba,demo2,cross-env'",

+ 1 - 1
config/prod.env.js

@@ -4,7 +4,7 @@ module.exports = {
     IS_BASE_PACKAGE: "true",
     FILE_BASE_PATH: '"http://192.168.10.14:1665"',
 
-    NEED_LOGIN: "true",
+    NEED_LOGIN: "false",
     BASE_API: '"/dcucauth"',
     BUILD_PATH: '"../dist"',
     IS_OAUTH2: "false",

+ 1 - 1
config/prod.env.js-deploy

@@ -3,7 +3,7 @@ module.exports = {
     NODE_ENV: '"production"',
     IS_BASE_PACKAGE: "true",
 
-    NEED_LOGIN: "true",
+    NEED_LOGIN: "false",
     BASE_API: '"/zfba"',
     BUILD_PATH: '"../dist"',
 

+ 5 - 1
src/main.js

@@ -45,7 +45,11 @@ if (!process.env.IS_BASE_PACKAGE) {
     utils = require("@/utils").default;
 } else {
     // 引入路由权限控制
-    require("ui-jz-v4-common/src/router/permission");
+    if(process.env.NEED_LOGIN) {
+       require("@/router/dcuc_permission.js");      
+    }else {
+        require("@/router/lxr_permission.js");  
+    }
     // 全局引入 封装的组件
     BaseUI = require("ui-jz-v4-common/src/components").default;
     // 全局引入工具类

+ 1 - 12
src/pages/layout/components/navbar.vue

@@ -80,18 +80,7 @@ export default {
         },
         logout() {
             this.$confirm("是否确定退出系统").then(() => {
-                window.loginUtil.logout(this);
-
-                // if (getSettingBool("IS_OAUTH2")) {
-                //     let logoutUrl =
-                //         window.sessionStorage["authorizeUrl"] + `/logout?redirect_uri=${window.location.href}`;
-                //     this.$store.dispatch("LogoutOauth", logoutUrl);
-                // } else {
-                //     this.$store.dispatch("Logout").then(() => {
-                //         this.$router.push(`/login?redirect=${this.$route.fullPath}`);
-                //         location.reload(); // In order to re-instantiate the vue-router object to avoid bugs
-                //     });
-                // }
+                 window.location.href = `https://login.iam.com/apphub/logout`;
             });
         },
         handleClickSearch() {

+ 83 - 89
src/router/permission.js → src/router/dcuc_permission.js

@@ -2,44 +2,62 @@ import router from "@/router/index.js";
 import store from "@/store";
 import NProgress from "nprogress"; // progress bar
 import "./progress.css";
-import {getQueryObject} from "../utils/data-utils.js";
-import {getToken, getUserName} from "@/utils/auth"; // getToken from cookie
+import { getToken, getUserName } from "@/utils/auth"; // getToken from cookie
 import _ from "lodash";
 
-const {initSettings, getSetting, getSettings, getSettingBool} = window.systemParamsUtils;
+const { initSettings, getSetting, getSettings, getSettingBool } = window.systemParamsUtils;
 
-NProgress.configure({showSpinner: false}); // NProgress Configuration
+NProgress.configure({ showSpinner: false }); // NProgress Configuration
 
-// permission judge function
-function hasPermission(userPermissions, routePermissions) {
-    if (!routePermissions || (routePermissions && routePermissions.length === 0)) {
-        return true;
-    }
-    return userPermissions.some(userPermission => {
-        return routePermissions.indexOf(userPermission) >= 0;
-    });
+// 合并白名单列表
+const WHITE_LIST = getSetting("WHITE_LIST");
+let whiteList = ["/login", "/auth-redirect"]; // no redirect whitelist
+if (WHITE_LIST instanceof Array) {
+    whiteList = whiteList.concat(WHITE_LIST);
 }
 
-const whiteList = ["/login", "/auth-redirect"]; // no redirect whitelist
-
 router.beforeEach((to, from, next) => {
     NProgress.start(); // start progress bar
     let queryObject = getQueryObject();
     if (_.isEmpty(getSettings())) {
-        //如果配置信息为空,则先加载配置信息
-        initSettings().then(() => location.reload());
-    } else if (!getSettingBool("NEED_LOGIN")) {
-        // 如果项目不需要登录,则不需要获取用户信息和权限
-        noNeedLogin(to, from, next);
+        initSettings().then(() => location.reload()); // 如果配置信息为空,则先加载配置信息
+    } else if (!getSettingBool("NEED_LOGIN") || whiteList.indexOf(to.path) !== -1) {
+        noNeedLogin(to, from, next); // 如果项目不需要登录或页面url在白名单中,则不需要获取用户信息和权限
     } else if (getSettingBool("IS_OAUTH2") && queryObject.code) {
-        //如果使用oauth2登录并且地址栏中有code参数,则去请求token
-        getAccessToken(queryObject);
+        getAccessToken(queryObject); // 如果使用oauth2登录并且地址栏中有code参数,则去请求token
     } else {
-        //检查是否登录
-        checkLogin(to, next);
+        checkLogin(to, next); // 检查是否登录
     }
 });
 
+/**
+ * 将url的参数转为对象
+ * 不传默认获取当前浏览器地址的参数
+ */
+function getQueryObject(url = window.location.href) {
+    const search = url.substring(url.lastIndexOf("?") + 1);
+    const obj = {};
+    const reg = /([^?&=]+)=([^?&=]*)/g;
+    search.replace(reg, (rs, $1, $2) => {
+        const name = decodeURIComponent($1);
+        let val = decodeURIComponent($2);
+        val = String(val);
+        obj[name] = val;
+        return rs;
+    });
+    return obj;
+}
+
+// permission judge function
+function hasPermission(userPermissions = [], routePermissions = []) {
+    if (routePermissions && routePermissions.length === 0) {
+        return true;
+    }
+    return userPermissions.some(userPermission => {
+        return routePermissions.indexOf(userPermission) >= 0;
+    });
+}
+
 router.afterEach(() => {
     NProgress.done(); // finish progress bar
 });
@@ -62,49 +80,19 @@ function noNeedLogin(to, from, next) {
  * 如果是Oauth2登录并且地址栏上有code字段,则去请求access_token
  * @param queryObject   地址栏上的参数
  */
-function getAccessToken(queryObject) {
+async function getAccessToken(queryObject) {
     let code = queryObject.code.split("#/")[0];
-    store
-        .dispatch("GetOAuthToken", { code })
-        .then(code => {
-            //如果登录成功了,清除掉url中的code,刷新页面
-            if (getToken()) {
-                window.location.href = delParam("code");
-            }
-        })
-        .catch(reason => {
-            store.dispatch("FedLogout").then(() => {
-                location.reload();
-            });
-        });
-}
-
-/**
- * 去掉url上的指定参数
- * @param paramKey  要删除的key
- */
-function delParam(paramKey) {
-    let url = window.location.href; //页面url
-    let urlParam = window.location.search.substr(1); //页面参数
-    let beforeUrl = url.substr(0, url.indexOf("?")); //页面主地址(参数之前地址)
-    let nextUrl = "";
-    let arr = [];
-    if (urlParam !== "") {
-        let urlParamArr = urlParam.split("&"); //将参数按照&符分成数组
-        for (let i = 0; i < urlParamArr.length; i++) {
-            let paramArr = urlParamArr[i].split("="); //将参数键,值拆开
-            //如果键雨要删除的不一致,则加入到参数中
-            if (paramArr[0] !== paramKey) {
-                arr.push(urlParamArr[i]);
-            }
+    try {
+        await store.dispatch("GetOAuthToken", { code });
+        if (getToken()) {
+            window.location.href = "http://" + window.location.host + decodeURIComponent(window.location.pathname);
         }
-        if (arr.length > 0) {
-            nextUrl = "?" + arr.join("&");
-        }
-        url = beforeUrl + nextUrl;
+    } catch (reason) {
+        console.error(reason);
+        store.dispatch("FedLogout").then(() => {
+            location.reload();
+        });
     }
-    url = "http://" + window.location.host + decodeURIComponent(window.location.pathname);
-    return url;
 }
 
 /**
@@ -115,8 +103,7 @@ function delParam(paramKey) {
  */
 function checkIsInWhiteList(to, next, link, result) {
     if (whiteList.indexOf(to.path) !== -1) {
-        // 在免登录白名单,直接进入
-        next();
+        next(); // 在免登录白名单,直接进入
     } else if (result instanceof Promise) {
         result.then(result => {
             if (result && result.status === 403 && result.link) {
@@ -153,29 +140,36 @@ function generateRoutes(permissions, next, to) {
 }
 
 function checkLogin(to, next) {
+    console.log(getUserName());
     if (getUserName()) {
-        debugger;
         if (to.path === "/login") {
             next({ path: "/" });
             NProgress.done(); // if current page is dashboard will not trigger	afterEach hook, so manually handle it
         } else {
             let permissionsLength = store.getters.permissions.length;
             if (!store.getters.name && !permissionsLength) {
-                store
-                    .dispatch("GetUserInfo")
-                    .then(res => {
+                try {
+                    // 获取用户信息
+                    // await ;
+                    store.dispatch("GetUserInfo").then(() => {
                         let permissions = store.getters.permissions;
                         generateRoutes(permissions, next, to);
-                    })
-                    .catch(err => {
-                        store.dispatch("FedLogout").then(() => {
-                            if (!err.link) {
-                                next(`/login?redirect=${to.path}`); // 否则全部重定向到登录页
-                            } else {
-                                next({ path: "/" });
-                            }
-                        });
                     });
+                } catch (err) {
+                    store.dispatch("FedLogout").then(() => {
+                        if (!err.link) {
+                            next(`/login?redirect=${to.path}`); // 否则全部重定向到登录页
+                        } else {
+                            next({ path: "/" });
+                        }
+                    });
+                    // await store.dispatch("FedLogout")   // 如果获取用户信息失败,则将本地的用户信息相关的东西清空,并登出
+                    // if (!err.link) {
+                    //     next(`/login?redirect=${to.path}`); // 否则全部重定向到登录页
+                    // } else {
+                    //     next({ path: "/" });
+                    // }
+                }
             } else {
                 // 没有动态改变权限的需求可直接next() 删除下方权限判断 ↓
                 // if (hasPermission(store.getters.roles, to.meta.roles)) {
@@ -192,20 +186,20 @@ function checkLogin(to, next) {
         }
     } else {
         if (getSetting("BASE_API") === "/easy-mock") {
-            //检查是否在白名单中
-            checkIsInWhiteList(to, next);
+            checkIsInWhiteList(to, next); // 检查是否在白名单中
         } else {
-            store
-                .dispatch("GetUserInfo")
-                .then(res => {
+            try {
+                store.dispatch("GetUserInfo").then(() => {
                     window.location.reload();
-                })
-                .catch(result => {
-                    let link;
-                    result && (link = result.link);
-                    //检查是否在白名单中
-                    checkIsInWhiteList(to, next, link, result);
                 });
+                // await store.dispatch("GetUserInfo")
+                // window.location.reload();
+            } catch (result) {
+                let link;
+                result && (link = result.link);
+
+                checkIsInWhiteList(to, next, link, result); // 检查是否在白名单中
+            }
         }
     }
 }

+ 185 - 0
src/router/lxr_permission.js

@@ -0,0 +1,185 @@
+import router from "@/router/index.js";
+import store from "@/store";
+import NProgress from "nprogress"; // progress bar
+import "./progress.css";
+import { getToken, getUserName } from "@/utils/auth"; // getToken from cookie
+import _ from "lodash";
+
+const { initSettings, getSetting, getSettings } = window.systemParamsUtils;
+
+NProgress.configure({ showSpinner: false }); // NProgress Configuration
+
+// 合并白名单列表
+const WHITE_LIST = getSetting("WHITE_LIST");
+let whiteList = [ "/auth-redirect"]; // no redirect whitelist
+if (WHITE_LIST instanceof Array) {
+    whiteList = whiteList.concat(WHITE_LIST);
+}
+
+router.beforeEach((to, from, next) => {
+    NProgress.start(); // start progress bar
+    if (_.isEmpty(getSettings())) {
+        initSettings().then(() => location.reload()); // 如果配置信息为空,则先加载配置信息
+    } else if (_.isEmpty(store.state.user.info) && whiteList.indexOf(to.path) == -1) {
+        checkLogin(to, next); // 检查是否登录
+    } else {
+        next();
+    }
+});
+
+
+// permission judge function
+function hasPermission(userPermissions = [], routePermissions = []) {
+    if (routePermissions && routePermissions.length === 0) {
+        return true;
+    }
+    return userPermissions.some(userPermission => {
+        return routePermissions.indexOf(userPermission) >= 0;
+    });
+}
+
+router.afterEach(() => {
+    NProgress.done(); // finish progress bar
+});
+
+/**
+ * 不需要登录则直接加载所有路由
+ * @param to
+ * @param from
+ * @param next
+ */
+function noNeedLogin(to, from, next) {
+    if (store.getters.addRouters.length === 0) {
+        generateRoutes([], next, to);
+    } else {
+        next();
+    }
+}
+
+/**
+ * 如果是Oauth2登录并且地址栏上有code字段,则去请求access_token
+ * @param queryObject   地址栏上的参数
+ */
+async function getAccessToken(queryObject) {
+    let code = queryObject.code.split("#/")[0];
+    try {
+        await store.dispatch("GetOAuthToken", { code });
+        if (getToken()) {
+            window.location.href = "http://" + window.location.host + decodeURIComponent(window.location.pathname);
+        }
+    } catch (reason) {
+        console.error(reason);
+        store.dispatch("FedLogout").then(() => {
+            location.reload();
+        });
+    }
+}
+
+/**
+ * 检查是否在白名单中,进行页面跳转
+ * @param to
+ * @param next
+ * @param link
+ */
+function checkIsInWhiteList(to, next, link, result) {
+    if (whiteList.indexOf(to.path) !== -1) {
+        next(); // 在免登录白名单,直接进入
+    } else if (result instanceof Promise) {
+        result.then(result => {
+            if (result && result.status === 403 && result.link) {
+                console.error("oauth2验证不通过,将跳转到登录页");
+            }
+        });
+    } else {
+        !link && next(`/login?redirect=${to.path}`); // 否则全部重定向到登录页
+        NProgress.done(); // if current page is login will not trigger afterEach hook, so manually handle it
+    }
+}
+
+/**
+ * 生成路由
+ * @param permissions   用户权限
+ * @param next
+ * @param to
+ */
+function generateRoutes(permissions, next, to) {
+    store.dispatch("GenerateRoutes", { permissions }).then(() => {
+        // 根据权限生成可访问的路由表
+        router.addRoutes(store.getters.addRouters); // 动态添加可访问路由表
+
+        if (hasPermission(store.getters.permissions, to.meta.permission)) {
+            next({ ...to, replace: true });
+        } else {
+            next({
+                path: "/",
+                replace: true
+            });
+        }
+        // next({ ...to, replace: true }); // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
+    });
+}
+
+function checkLogin(to, next) {
+    console.log(getUserName());
+    if (getUserName()) {
+        if (to.path === "/login") {
+            next({ path: "/" });
+            NProgress.done(); // if current page is dashboard will not trigger	afterEach hook, so manually handle it
+        } else {
+            let permissionsLength = store.getters.permissions.length;
+            if (!store.getters.name && !permissionsLength) {
+                try {
+                    // 获取用户信息
+                    // await ;
+                    store.dispatch("GetUserInfo").then(() => {
+                        let permissions = store.getters.permissions;
+                        generateRoutes(permissions, next, to);
+                    });
+                } catch (err) {
+                    store.dispatch("FedLogout").then(() => {
+                        if (!err.link) {
+                            next(`/login?redirect=${to.path}`); // 否则全部重定向到登录页
+                        } else {
+                            next({ path: "/" });
+                        }
+                    });
+                    // await store.dispatch("FedLogout")   // 如果获取用户信息失败,则将本地的用户信息相关的东西清空,并登出
+                    // if (!err.link) {
+                    //     next(`/login?redirect=${to.path}`); // 否则全部重定向到登录页
+                    // } else {
+                    //     next({ path: "/" });
+                    // }
+                }
+            } else {
+                // 没有动态改变权限的需求可直接next() 删除下方权限判断 ↓
+                // if (hasPermission(store.getters.roles, to.meta.roles)) {
+                next();
+                // } else {
+                //     next({
+                //         path: "/401",
+                //         replace: true,
+                //         query: { noGoBack: true }
+                //     });
+                // }
+                // 可删 ↑
+            }
+        }
+    } else {
+        if (getSetting("BASE_API") === "/easy-mock") {
+            checkIsInWhiteList(to, next); // 检查是否在白名单中
+        } else {
+            try {
+                store.dispatch("GetUserInfo").then(() => {
+                    window.location.reload();
+                });
+                // await store.dispatch("GetUserInfo")
+                // window.location.reload();
+            } catch (result) {
+                let link;
+                result && (link = result.link);
+
+                checkIsInWhiteList(to, next, link, result); // 检查是否在白名单中
+            }
+        }
+    }
+}

+ 5 - 5
src/router/modules/data-auth-module.js

@@ -12,13 +12,13 @@ const componentsRouter = [
         component: Layout,
         redirect: "/auth-object-manage",
         alwaysShow: true,
-        meta: { title: "授权客体管理", icon: "el-icon-goods", noCache: true, permission: ["YHGLPT_YYGL"] },
+        meta: { title: "授权客体管理", icon: "el-icon-goods", noCache: true, permission: ["QXGL_SQKTGL"] },
         children: [
             {
                 path: "sort-code-manage",
                 component: () => import("@/pages/data-auth-module/auth-object-manage/sort-code-manage"),
                 name: "sort-code-manage",
-                meta: { title: "数据分级分类表码", noCache: false, permission: ["YHGLPT_YYGL_CSGL"]}
+                meta: { title: "数据分级分类表码", noCache: false, permission: ["QXGL_SQKTGL_SJFJFLBM"]}
             }
         ]
     },
@@ -27,20 +27,20 @@ const componentsRouter = [
         component: Layout,
         redirect: "/data-permission",
         alwaysShow: true,
-        meta: { title: "授权查询", icon: "el-icon-goods", noCache: true, permission: ["YHGLPT_YYGL"] },
+        meta: { title: "授权查询", icon: "el-icon-goods", noCache: true, permission: ["QXGL_SQCX"] },
         children: [
             {
                 path: "data-auth-search",
                 component: common,
                 name: "common",
-                meta: { title: "数据授权查询", noCache: false, permission: ["YHGLPT_YYGL_CSGL"] },
+                meta: { title: "数据授权查询", noCache: false, permission: ["QXGL_SQCX_SJSQCX"] },
                 alwaysShow: true,
                 children: [
                     {
                         path: "person-view",
                         component: () => import("@/pages/data-auth-module/data-permission-manage/data-auth-search/person-view.vue"),
                         name: "person-view",
-                        meta: { title: "人员视角", noCache: false, permission: ["YHGLPT_YYGL_CSGL"], layout:'page' }
+                        meta: { title: "人员视角", noCache: false, permission: ["QXGL_SQCX_SJSQCX_RYSJ"], layout:'page' }
                     },
                     // {
                     //     path: "data-view",

+ 6 - 6
src/router/modules/empower-manage.js

@@ -31,28 +31,28 @@ const componentRouter = {
             path: "data-auth-manage",
             component: common,
             name: "common",
-            meta: { title: "数据授权管理", noCache: false, permission: ["YHGLPT_YYGL_CSGL"] },
+            meta: { title: "数据授权管理", noCache: false, permission: ["QXGL_SQGL_SJSQGL"] },
             children: [
                 {
                     path: "business-tag-auth",
                     component: () =>
                         import("@/pages/data-auth-module/data-permission-manage/data-auth-manage/business-tag-auth.vue"),
                     name: "business-tag-auth",
-                    meta: { title: "标签授权", noCache: false, permission: ["YHGLPT_YYGL_CSGL"], layout: "page" }
+                    meta: { title: "标签授权", noCache: false, permission: ["QXGL_SQGL_SJSQGL_BQSQ"], layout: "page" }
                 },
                 {
                     path: "org-auth",
                     component: () =>
                         import("@/pages/data-auth-module/data-permission-manage/data-auth-manage/org-auth.vue"),
                     name: "org-auth",
-                    meta: { title: "机构授权", noCache: false, permission: ["YHGLPT_YYGL_CSGL"], layout: "page" }
+                    meta: { title: "机构授权", noCache: false, permission: ["QXGL_SQGL_SJSQGL_JGSQ"], layout: "page" }
                 },
                 {
                     path: "person-auth",
                     component: () =>
                         import("@/pages/data-auth-module/data-permission-manage/data-auth-manage/person-auth.vue"),
                     name: "person-auth",
-                    meta: { title: "人员授权", noCache: false, permission: ["YHGLPT_YYGL_CSGL"], layout: "page" }
+                    meta: { title: "人员授权", noCache: false, permission: ["QXGL_SQGL_SJSQGL_RYSQ"], layout: "page" }
                 }
             ]
         },
@@ -63,13 +63,13 @@ const componentRouter = {
             name: "common",
             redirect: "/service-delagate",
             alwaysShow: true,
-            meta: { title: "服务授权管理", icon: "el-icon-time", noCache: true },
+            meta: { title: "服务授权管理", icon: "el-icon-time", noCache: false},
             children: [
                 {
                     path: "service-delagate",
                     component: () => import("@/pages/service-delegate"),
                     name: "service-delagate",
-                    meta: { title: "服务授权", noCache: false }
+                    meta: { title: "服务授权", noCache: false}
                 }
             ]
         }

+ 4 - 1
src/store/modules/user.js

@@ -77,7 +77,10 @@ const user = {
                     params["appCode"] = getSetting("APP_CODE");
                 }
                 getUserInfo(params)
-                    .then(({ data }) => {
+                    .then(res => {
+                        // const data = process.env.NEED_LOGIN ? res : userInfo;
+                        const data = res.data;
+
                         //TODO 用户信息缓存,等用户信息出来后做
                         if (data.name === undefined) {
                             reject(data);

+ 34 - 28
src/utils/req.js

@@ -1,6 +1,8 @@
 import request from "./request";
 import { Loading } from "element-ui";
 import Qs from "qs";
+import Cookies from "js-cookie";
+
 
 /*
     reponse
@@ -13,11 +15,11 @@ import Qs from "qs";
 
 // 兼容finally
 if (!Promise.finally) {
-    Promise.prototype.finally = function (callback) {
+    Promise.prototype.finally = function(callback) {
         const P = this.constructor;
         return this.then(
-            (value) => P.resolve(callback()).then(() => value),
-            (reason) =>
+            value => P.resolve(callback()).then(() => value),
+            reason =>
                 P.resolve(callback()).then(() => {
                     throw reason;
                 })
@@ -25,7 +27,7 @@ if (!Promise.finally) {
     };
 }
 
-const isSuccess = (val) => val === 200 || val === "200";
+const isSuccess = val => val === 200 || val === "200";
 
 function showLoding(bool = false) {
     if (!bool) {
@@ -44,50 +46,54 @@ function hideLoading(loading) {
     loading.close();
 }
 
+const axiosConfig = {
+    headers: { userToken: Cookies.get('_idp_session') || 'testUserToken' }
+};
+
 const axios = {
     request(option = {}) {
         return new Promise((resolve, reject) => {
             const loading = showLoding(option.loading);
             request
-                .request(option)
+                .request(option, { ...axiosConfig })
                 .then(({ data = {} }) => {
                     if (isSuccess(data.result)) {
                         resolve(data.content);
                     }
                     reject(data.msg);
                 })
-                .catch((error) => reject(error))
+                .catch(error => reject(error))
                 .finally(() => {
                     loading && hideLoading(loading);
                 });
         });
     },
-    getBu(url, params, option = {}){
+    getBu(url, params, option = {}) {
         return new Promise((resolve, reject) => {
             const loading = showLoding(option.loading);
             request
-              .get(url, { params }, option)
-              .then(({ data = {} }) => {
-                  resolve(data);
-              })
-              .catch((error) => reject(error))
-              .finally(() => {
-                  loading && hideLoading(loading);
-              });
+                .get(url, { params }, option, { ...axiosConfig })
+                .then(({ data = {} }) => {
+                    resolve(data);
+                })
+                .catch(error => reject(error))
+                .finally(() => {
+                    loading && hideLoading(loading);
+                });
         });
     },
     get(url, params, option = {}) {
         return new Promise((resolve, reject) => {
             const loading = showLoding(option.loading);
             request
-                .get(url, { params }, option)
+                .get(url, { params }, option, { ...axiosConfig })
                 .then(({ data = {} }) => {
                     if (isSuccess(data.result)) {
                         resolve(data.content);
                     }
                     reject(data.msg);
                 })
-                .catch((error) => reject(error))
+                .catch(error => reject(error))
                 .finally(() => {
                     loading && hideLoading(loading);
                 });
@@ -97,14 +103,14 @@ const axios = {
         return new Promise((resolve, reject) => {
             const loading = showLoding(option.loading);
             request
-                .post(url, params, option)
+                .post(url, params, option, { ...axiosConfig })
                 .then(({ data = {} }) => {
                     if (isSuccess(data.result)) {
                         resolve(data.content);
                     }
                     reject(data.msg);
                 })
-                .catch((error) => reject(error))
+                .catch(error => reject(error))
                 .finally(() => {
                     loading && hideLoading(loading);
                 });
@@ -114,14 +120,14 @@ const axios = {
         return new Promise((resolve, reject) => {
             const loading = showLoding(option.loading);
             request
-                .put(url, params, option)
+                .put(url, params, option, { ...axiosConfig })
                 .then(({ data = {} }) => {
                     if (isSuccess(data.result)) {
                         resolve(data.content);
                     }
                     reject(data.msg);
                 })
-                .catch((error) => reject(error))
+                .catch(error => reject(error))
                 .finally(() => {
                     loading && hideLoading(loading);
                 });
@@ -132,14 +138,14 @@ const axios = {
         return new Promise((resolve, reject) => {
             const loading = showLoding(option.loading);
             request
-                .delete(url, option)
+                .delete(url, option, { ...axiosConfig })
                 .then(({ data = {} }) => {
                     if (isSuccess(data.result)) {
                         resolve(data.content);
                     }
                     reject(data.msg);
                 })
-                .catch((error) => reject(error))
+                .catch(error => reject(error))
                 .finally(() => {
                     loading && hideLoading(loading);
                 });
@@ -165,11 +171,11 @@ const axios = {
 
 export default axios;
 
-export const restApi = (base, option) => ({
+export const restApi = (base, option = {}) => ({
     base,
     table: `${base}s`,
-    detail: (id) => axios.get(`${base}/${id}`, null, option),
-    save: (data) => axios.post(base, data, option),
-    update: (data) => axios.put(`${base}/${data.id}`, data, option),
-    del: (id) => axios.delete(`${base}/${id}`, null, option)
+    detail: id => axios.get(`${base}/${id}`, null, option, { ...axiosConfig }),
+    save: data => axios.post(base, data, option, { ...axiosConfig }),
+    update: data => axios.put(`${base}/${data.id}`, data, option, { ...axiosConfig }),
+    del: id => axios.delete(`${base}/${id}`, null, option, { ...axiosConfig })
 });

+ 2 - 2
src/utils/request-base.js

@@ -1,7 +1,6 @@
 import axios from "axios";
 import { Loading } from "element-ui";
-import { getToken } from "@/utils/auth";
-
+import Cookies from "js-cookie";
 const { getSetting } = window.systemParamsUtils;
 
 console.log("BASE_API:" + getSetting("BASE_API"));
@@ -38,6 +37,7 @@ service.interceptors.request.use(
         // Do something before request is sent
         config = window.loginUtil.beforeRequest(config);
         config.headers["X-Requested-With"] = "XMLHttpRequest";
+        config.headers['userToken'] = Cookies.get('_idp_session') || 'testUserToken',
         loadingShow(config);
 
         return config;

+ 1 - 5
src/utils/request.js

@@ -1,9 +1,5 @@
 let request = {};
-if (!process.env.IS_BASE_PACKAGE) {
-    request = require("./request-base").default;
-} else {
-    request = require("ui-jz-v4-common/src/utils/request-base").default;
-}
+request = require("./request-base").default;
 
 request.interceptors.request.use(
     config => {