chenjun 1 month ago
parent
commit
b250529034
1 changed files with 47 additions and 3 deletions
  1. 47 3
      src/utils/request.js

+ 47 - 3
src/utils/request.js

@@ -1,8 +1,21 @@
 import axios from "axios";
-import { MessageBox, Message } from "element-ui";
+import {
+  MessageBox,
+  Message
+} from "element-ui";
 import store from "@/store";
-import router, { resetRouter } from "@/router";
-import { getToken, TokenKey, removeToken } from "@/utils/auth";
+import router, {
+  resetRouter
+} from "@/router";
+import {
+  getToken,
+  TokenKey,
+  removeToken
+} from "@/utils/auth";
+import {
+  isArray,
+  isString
+} from "lodash";
 // create an axios instance
 // let baseURL
 // if (process.env.NODE_ENV === "development") {
@@ -80,6 +93,37 @@ service.interceptors.response.use(
       }
       return Promise.reject(new Error(res.message || "Error"));
     } else {
+      // 格式化时间开始
+      const isoDateTimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/;
+      if ((res.returnData && !isString(res.returnData))) {
+        if (res.returnData.listValues) {
+          res.returnData.listValues.forEach((item, index) => {
+            // 取得属性名
+            let keys = Object.keys(item);
+            // 取得属性值
+            let values = Object.values(item);
+            keys.map(items => {
+              if (isoDateTimeRegex.test(item[items]) && /T/.test(item[items])) {
+                item[items] = item[items].replace(/T/g, ' ');
+              }
+            })
+          });
+        } else {
+            res.returnData.forEach((item, index) => {
+              // 取得属性名
+              let keys = Object.keys(item);
+              // 取得属性值
+              let values = Object.values(item);
+              keys.map(items => {
+                if (isoDateTimeRegex.test(item[items]) && /T/.test(item[items])) {
+                  item[items] = item[items].replace(/T/g, ' ');
+                }
+              })
+            });
+        }
+
+      }
+      // 格式化时间结束
       return res;
     }
   },