From aec1b6ec73897b5e5f3a85f2985447726a399ed0 Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期六, 19 四月 2025 15:56:48 +0800
Subject: [PATCH] 更新灌溉计划页面,添加灌溉计划列表刷新标记,优化项目选择器和时间选择器的逻辑;更新样式以提升用户体验,确保在切换标签时只加载必要的数据。

---
 api/request.js |   51 ++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/api/request.js b/api/request.js
index 62f4b83..ab0c6e7 100644
--- a/api/request.js
+++ b/api/request.js
@@ -1,9 +1,7 @@
 // 寮曞叆鐘舵�佺爜statusCode
 const statusCode = require('./statusCode')
 // 瀹氫箟璇锋眰璺緞, BASEURL: 鏅�氳姹侫PI; CBASEURL: 涓彴API,涓嶄娇鐢ㄤ腑鍙板彲涓嶅紩鍏BASEURL
-const {
-  BASEURL
-} = require('./config')
+const config = require('./config')
 // 瀹氫箟榛樿鍙傛暟
 const defaultOptions = {
   data: {},
@@ -31,11 +29,20 @@
     data,
     ignoreToken,
     form,
-    isShowLoding
+    isShowLoding,
+    timeout,
+    header,
+    useParams
   } = _options
+
+  // 妫�鏌rl鏄惁涓簎ndefined
+  if (!url) {
+    console.error('璇锋眰URL涓嶈兘涓虹┖');
+    return Promise.reject(new Error('璇锋眰URL涓嶈兘涓虹┖'));
+  }
+
   const app = getApp()
   // 璁剧疆璇锋眰澶�
-  let header = {}
   if (form) {
     header = {
       'content-type': 'application/x-www-form-urlencoded'
@@ -45,13 +52,22 @@
       'content-type': 'application/json' //鑷畾涔夎姹傚ご淇℃伅
     }
   }
+  if (!timeout) {
+    timeout = 60000
+  }
+
   if (!ignoreToken) {
     // 浠庡叏灞�鍙橀噺涓幏鍙杢oken
     let token = app.globalData.token
     header.Authorization = `Bearer ${token}`
   }
+  header.tag = app.globalData.tag;
+  header.appId = app.globalData.AppID;
   return new Promise((resolve, reject) => {
-    console.log("url:" + BASEURL + url);
+    // 鑾峰彇鏈�鏂扮殑 BASEURL
+    let currentBaseUrl = app.globalData.baseUrl || config.BASEURL;
+
+    console.log("url:" + currentBaseUrl + url);
     if (isShowLoding) {
       wx.showLoading({
         title: '閫氫俊涓�...', // 鍔犺浇鍔ㄧ敾鏍囬
@@ -62,13 +78,20 @@
     if (url.startsWith('http')) {
       myUrl = url;
     } else {
-      myUrl = BASEURL + url;
+      myUrl = currentBaseUrl + url;
+    }
+    // 濡傛灉 useParams 涓� true锛屾嫾鎺ユ煡璇㈠弬鏁�
+    if (useParams && data) {
+      const queryString = objToQueryString(data); // 浣跨敤涓婇潰瀹氫箟鐨勫嚱鏁�
+      myUrl += `?${queryString}`; // 鎷兼帴鏌ヨ瀛楃涓�
+      data = {}; // 璇锋眰浣撴暟鎹涓虹┖
     }
     wx.request({
       url: myUrl,
       data,
       header,
       method,
+      timeout: timeout,
       success: (res) => {
         let {
           statusCode: code
@@ -80,7 +103,7 @@
         if (code === statusCode.SUCCESS) {
           if (res.data.code !== "0001") {
             // 缁熶竴澶勭悊璇锋眰閿欒
-            showToast(res.data.errorMsg)
+            // showToast(res.data.errorMsg)
             reject(res.data)
             return
           }
@@ -101,14 +124,20 @@
         if (isShowLoding) {
           wx.hideLoading(); // 闅愯棌鍔犺浇鍔ㄧ敾
         }
-
-        showToast(err.errMsg)
+        // showToast(err.errMsg)
         reject(err)
       }
     })
   })
 }
-
+function objToQueryString(obj) {
+  return Object.keys(obj)
+      .map(key => {
+          // 瀵归敭鍜屽�艰繘琛� URL 缂栫爜
+          return `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;
+      })
+      .join('&'); // 灏嗘墍鏈夐敭鍊煎鐢� '&' 杩炴帴璧锋潵
+}
 // 灏佽toast鍑芥暟
 function showToast(title, icon = 'none', duration = 2500, mask = false) {
   wx.showToast({

--
Gitblit v1.8.0