From c35074e0e33054bb6c5ada22f8104422ae953b17 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 21 二月 2025 17:19:04 +0800
Subject: [PATCH] 1. 新增默认加载时先判断各选项是否获取完成逻辑

---
 src/api/index.js |   75 ++++++++++++++++++++++++++++++-------
 1 files changed, 61 insertions(+), 14 deletions(-)

diff --git a/src/api/index.js b/src/api/index.js
index f657c25..c19983c 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -1,10 +1,13 @@
 import axios from 'axios';
 import { ElMessage } from 'element-plus';
 
-const debug = true;
+const debug = false;
 
-// let ip1 = 'http://114.215.109.124:8805/';
 let ip1 = 'http://47.100.191.150:9029/';
+// console.log(import.meta.env);
+if (import.meta.env.VITE_DATA_MODE == 'jingan') {
+  ip1 = 'http://114.215.109.124:8805/';
+}
 
 if (debug) {
   ip1 = 'http://192.168.0.138:8084/';
@@ -12,7 +15,7 @@
 
 const $http = axios.create({
   baseURL: ip1,
-  timeout: 20000
+  timeout: 30000
 });
 
 //娣诲姞鎷︽埅鍣�
@@ -21,17 +24,21 @@
   i.interceptors.request.use(
     function (config) {
       // 鍦ㄥ彂閫佽姹備箣鍓嶅仛浜涗粈涔�
-      console.log('==>璇锋眰寮�濮�');
-      console.log(`${config.baseURL}${config.url}`);
-      if (config.data) {
-        console.log('==>璇锋眰鏁版嵁', config.data);
+      if (import.meta.env.DEV) {
+        console.log('==>璇锋眰寮�濮�');
+        console.log(`${config.baseURL}${config.url}`);
+        if (config.data) {
+          console.log('==>璇锋眰鏁版嵁', config.data);
+        }
       }
       return config;
     },
     function (error) {
       // 瀵硅姹傞敊璇仛浜涗粈涔�
-      console.log('==>璇锋眰寮�濮�');
-      console.log(error);
+      if (import.meta.env.DEV) {
+        console.log('==>璇锋眰寮�濮�');
+        console.log(error);
+      }
       ElMessage({
         message: error,
         type: 'error'
@@ -45,8 +52,10 @@
     function (response) {
       // 2xx 鑼冨洿鍐呯殑鐘舵�佺爜閮戒細瑙﹀彂璇ュ嚱鏁般��
       // 瀵瑰搷搴旀暟鎹仛鐐逛粈涔�
-      console.log(response);
-      console.log('==>璇锋眰缁撴潫');
+      if (import.meta.env.DEV) {
+        console.log(response);
+        console.log('==>璇锋眰缁撴潫');
+      }
       if (response.status == 200) {
         if (
           response.data.success != undefined &&
@@ -71,8 +80,10 @@
     function (error) {
       // 瓒呭嚭 2xx 鑼冨洿鐨勭姸鎬佺爜閮戒細瑙﹀彂璇ュ嚱鏁般��
       // 瀵瑰搷搴旈敊璇仛鐐逛粈涔�
-      console.log(error);
-      console.log('==>璇锋眰缁撴潫');
+      if (import.meta.env.DEV) {
+        console.log(error);
+        console.log('==>璇锋眰缁撴潫');
+      }
       ElMessage({
         message: error,
         type: 'error'
@@ -82,4 +93,40 @@
   );
 });
 
-export { $http };
+// const $http = {
+//   get(url) {
+//     const controller = new AbortController();
+//     return {
+//       con: controller,
+//       resp: axiosInstance.get(url, { signal: controller.signal })
+//     };
+//   },
+//   put(url, data) {
+//     const controller = new AbortController();
+//     return {
+//       con: controller,
+//       resp: axiosInstance.put(url, data, { signal: controller.signal })
+//     };
+//   },
+//   post(url, data) {
+//     const controller = new AbortController();
+//     return {
+//       con: controller,
+//       resp: axiosInstance.post(url, data, { signal: controller.signal })
+//     };
+//   },
+//   delete(url) {
+//     const controller = new AbortController();
+//     return {
+//       con: controller,
+//       resp: axiosInstance.delete(url, { signal: controller.signal })
+//     };
+//   }
+// };
+
+function resToData(res) {
+  res.resp = res.resp.then((res) => res.data);
+  return res;
+}
+
+export { $http, resToData };

--
Gitblit v1.9.3