zhangjie 5 роки тому
батько
коміт
a7d15f7072

+ 20 - 20
src/main.js

@@ -7,6 +7,7 @@ import store from "./store";
 import globalVuePlugins from "./plugins/globalVuePlugins";
 import GLOBAL from "./config";
 import { jsonBigNumberToString } from "./plugins/utils";
+// import { getAuthorisation } from "./plugins/crypto";
 
 // https://github.com/RobinCK/vue-ls
 import VueLocalStorage from "vue-ls";
@@ -26,17 +27,6 @@ router.beforeEach((to, from, next) => {
   const token = Vue.ls.get("token");
   if (to.meta.noRequire) {
     next();
-    // 不需要登录的页面
-    // if (token) {
-    //   // 当前状态是已登录
-    //   ElementUI.Notice.info({
-    //     title: "您已经登录,已自动跳转到主页",
-    //     duration: 5
-    //   });
-    //   next({ name: "Home" });
-    // } else {
-
-    // }
   } else {
     // 需要登录的路由
     if (token) {
@@ -60,6 +50,8 @@ axios.defaults.transformResponse = [
     return JSON.parse(jsonBigNumberToString(data));
   }
 ];
+// 设置延迟时效
+axios.defaults.timeout = GLOBAL.timeout;
 axios.interceptors.request.use(
   config => {
     // 显示loading提示
@@ -72,19 +64,27 @@ axios.interceptors.request.use(
     }
     queue.push(1);
 
-    // 为请求地址添加全局domain
-    if (config.url.indexOf("http://") < 0) {
-      config.url = GLOBAL.domain + config.url;
-    }
-
-    // 为请求头添加token信息
+    // 为请求头添加鉴权信息
     let token = Vue.ls.get("token");
     if (token) {
+      // 新版鉴权 to open
+      // const userId = Vue.ls.get("user").id;
+      // const { Authorization, timestamp } = getAuthorisation(
+      //   {
+      //     token: token,
+      //     account: userId,
+      //     uri: config.url,
+      //     method: config.method
+      //   },
+      //   "token"
+      // );
+      // config.headers["Authorization"] = Authorization;
+      // config.headers["time"] = timestamp;
+      // config.headers["deviceId"] = userId;
+      // config.headers["domain"] = window.location.origin;
+      // config.headers["platform"] = "print-web";
       config.headers["token"] = token;
     }
-
-    // 设置延迟时效
-    config.timeout = GLOBAL.timeout;
     return config;
   },
   error => {

+ 1 - 2
src/modules/base/components/BusinessFields.vue

@@ -52,8 +52,7 @@ export default {
       mustColumns: [],
       extendColumns: [],
       // import
-      uploadUrl:
-        this.GLOBAL.domain + "/api/print/basic/cardRule/impExtendColums"
+      uploadUrl: "/api/print/basic/cardRule/impExtendColums"
     };
   },
   computed: {

+ 2 - 2
src/modules/base/views/UserManage.vue

@@ -155,9 +155,9 @@ export default {
       ABLE_TYPE,
       roles: [],
       users: [],
-      downloadUrl: this.GLOBAL.domain + "/temps/用户导入模版.xlsx",
+      downloadUrl: "/temps/用户导入模版.xlsx",
       // import
-      uploadUrl: this.GLOBAL.domain + "/api/print/basic/user/add",
+      uploadUrl: "/api/print/basic/user/add",
       uploadData: {
         schoolId: this.$ls.get("schoolId"),
         userId: this.$ls.get("user", { id: "" }).id

+ 1 - 1
src/modules/card/components/PaperParams.vue

@@ -156,7 +156,7 @@ export default {
         type: ""
       },
       // import
-      uploadUrl: this.GLOBAL.domain + "/api/print/basic/sys/saveAttachment"
+      uploadUrl: "/api/print/basic/sys/saveAttachment"
     };
   },
   methods: {

+ 35 - 1
src/plugins/ajax.js

@@ -1,4 +1,33 @@
 import { jsonBigNumberToString } from "./utils";
+// 新鉴权 to open
+// import { getAuthorisation } from "./crypto";
+
+// function getStorage(key) {
+//   const content = window.sessionStorage.getItem(key);
+//   return content ? JSON.parse(content).value : null;
+// }
+
+// function getAuthorHeader(uri, method) {
+//   const user = getStorage("user");
+
+//   const infos = getAuthorisation(
+//     {
+//       token: getStorage("token"),
+//       account: user && user["id"],
+//       uri,
+//       method
+//     },
+//     "token"
+//   );
+
+//   return {
+//     Authorization: infos.Authorization,
+//     time: infos.timestamp,
+//     deviceId: user && user["id"],
+//     domain: window.location.origin,
+//     platform: "print-web"
+//   };
+// }
 
 function getError(action, option, xhr) {
   let msg;
@@ -75,7 +104,12 @@ export default function upload(option) {
     xhr.withCredentials = true;
   }
 
-  const headers = option.headers || {};
+  let headers = option.headers || {};
+  // const authorHeader = getAuthorHeader(action, "post");
+
+  // for (let item in authorHeader) {
+  //   headers[item] = authorHeader[item];
+  // }
 
   for (let item in headers) {
     if (headers.hasOwnProperty(item) && headers[item] !== null) {

+ 31 - 0
src/plugins/crypto.js

@@ -10,3 +10,34 @@ export const AES = content => {
 
   return enstr;
 };
+
+/**
+ * 获取authorisation
+ * @param {Object} infos 相关信息
+ * @param {String} type 类别:secret、token两种
+ */
+export const getAuthorisation = (infos, type) => {
+  // {type} {invoker}:base64(sha1(method&uri&timestamp&{secret}))
+  const timestamp = Date.now();
+  if (type === "secret") {
+    // accessKey | method&uri&timestamp&accessSecret
+    const str = `${infos.method.toLowerCase()}&${infos.uri}&${timestamp}&${
+      infos.accessSecret
+    }`;
+    const sign = CryptoJS.enc.Base64.stringify(CryptoJS.SHA1(str));
+    return {
+      timestamp,
+      Authorization: `Secret ${infos.accessKey}:${sign}`
+    };
+  } else if (type === "token") {
+    // userId | method&uri&timestamp&token
+    const str = `${infos.method.toLowerCase()}&${infos.uri}&${timestamp}&${
+      infos.token
+    }`;
+    const sign = CryptoJS.enc.Base64.stringify(CryptoJS.SHA1(str));
+    return {
+      timestamp,
+      Authorization: `Token ${infos.account}:${sign}`
+    };
+  }
+};