From 61e89d748cc7f5456c20866e672a4bde153534f1 Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期一, 21 四月 2025 17:18:53 +0800
Subject: [PATCH] 优化项目配置,重构项目URL管理逻辑,改为使用动态配置;更新灌溉组详情页面,添加详细信息展示和请求逻辑,提升用户体验;更新首页项目选择器,支持动态项目列表展示。

---
 pages/groupDetail/groupDetail.js |  205 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 144 insertions(+), 61 deletions(-)

diff --git a/pages/groupDetail/groupDetail.js b/pages/groupDetail/groupDetail.js
index 3a75ef0..600a6b4 100644
--- a/pages/groupDetail/groupDetail.js
+++ b/pages/groupDetail/groupDetail.js
@@ -46,74 +46,157 @@
       refreshing: true
     });
     
-    console.log('鍔犺浇鍙栨按鍙f暟鎹紝鐏屾簤鐘舵��:', this.data.isIrrigating);
+    console.log('寮�濮嬪姞杞借疆鐏岀粍璇︽儏锛実roupId:', this.data.groupId);
     
-    // 妯℃嫙鏁版嵁
-    let mockData = {
-      waterOutlets: []
-    };
-    
-    // 鐢熸垚鍙栨按鍙f暟鎹紝鎵�鏈夊彇姘村彛閮芥湁鍛戒护鐘舵��
-    mockData.waterOutlets = [
-      {
-        id: 1,
-        name: '鍙栨按鍙� A-1',
-        status: 'online',
-        commandStatus: 'sent' // 鍛戒护宸蹭笅鍙�
-      },
-      {
-        id: 2,
-        name: '鍙栨按鍙� A-2',
-        status: 'online',
-        commandStatus: 'unsent' // 鍛戒护鏈笅鍙�
-      },
-      {
-        id: 3,
-        name: '鍙栨按鍙� A-3',
-        status: 'offline',
-        commandStatus: 'unsent' // 鍛戒护鏈笅鍙�
+    // 妫�鏌piBaseUrl鏄惁瀛樺湪
+    if (!app.globalData.apiBaseUrl) {
+      try {
+        // 浠巆onfig妯″潡鑾峰彇鍩虹URL
+        const config = require('../../api/config');
+        const { PROJECT_CONFIG } = require('../../utils/projectConfig');
+        
+        // 鑾峰彇褰撳墠閫変腑鐨勯」鐩爣璇�
+        const tag = wx.getStorageSync('projectTag') || app.globalData.tag || 'mq';
+        
+        // 鏍规嵁tag鎵惧埌瀵瑰簲椤圭洰閰嶇疆
+        let selectedProject = 'MQ'; // 榛樿涓烘皯鍕ら」鐩�
+        for (const key in PROJECT_CONFIG) {
+          if (PROJECT_CONFIG[key].tag === tag) {
+            selectedProject = key;
+            break;
+          }
+        }
+        
+        // 璁剧疆apiBaseUrl
+        app.globalData.apiBaseUrl = PROJECT_CONFIG[selectedProject].serverUrl;
+        console.log('浠庨厤缃腑鑾峰彇apiBaseUrl:', app.globalData.apiBaseUrl);
+      } catch (error) {
+        console.error('鑾峰彇apiBaseUrl澶辫触:', error);
+        // 浣跨敤璇锋眰搴撲腑鐨勬柟娉�
+        const { get } = require('../../api/request');
+        
+        get({
+          url: '/wx/irrigation/getGroupDetails',
+          data: { groupId: this.data.groupId },
+          isShowLoding: true
+        }).then(res => {
+          if (res.success) {
+            this.handleGroupDetailsResponse(res);
+          } else {
+            wx.showToast({
+              title: res.msg || '鑾峰彇鏁版嵁澶辫触',
+              icon: 'none'
+            });
+          }
+        }).catch(err => {
+          console.error('璇锋眰澶辫触:', err);
+          wx.showToast({
+            title: '缃戠粶閿欒',
+            icon: 'none'
+          });
+        }).finally(() => {
+          this.setData({
+            refreshing: false
+          });
+        });
+        
+        return; // 宸茬粡浣跨敤璇锋眰搴撳鐞嗭紝鐩存帴杩斿洖
       }
-    ];
+    }
     
-    // 妯℃嫙缃戠粶璇锋眰寤惰繜
-    setTimeout(() => {
+    // 浣跨敤wx.request鍙戦�佽姹�
+    wx.request({
+      url: `${app.globalData.apiBaseUrl}/wx/irrigation/getGroupDetails`,
+      method: 'GET',
+      data: {
+        groupId: this.data.groupId
+      },
+      header: {
+        'content-type': 'application/json',
+        'Authorization': wx.getStorageSync('token') || '',
+        'tag': wx.getStorageSync('projectTag') || app.globalData.tag || '',
+        'appId': app.globalData.AppID || ''
+      },
+      success: (res) => {
+        console.log('杞亴缁勮鎯呮帴鍙h繑鍥�:', res.data);
+        
+        if (res.data && res.data.success) {
+          this.handleGroupDetailsResponse(res.data);
+        } else {
+          wx.showToast({
+            title: res.data.msg || '鑾峰彇鏁版嵁澶辫触',
+            icon: 'none'
+          });
+          this.setData({
+            refreshing: false
+          });
+        }
+      },
+      fail: (err) => {
+        console.error('璇锋眰澶辫触:', err);
+        // 灏濊瘯浣跨敤璇锋眰搴撻噸璇�
+        this.retryUsingRequestLib();
+      }
+    });
+  },
+  
+  /**
+   * 浣跨敤璇锋眰搴撻噸璇曡幏鍙栨暟鎹�
+   */
+  retryUsingRequestLib: function() {
+    console.log('浣跨敤璇锋眰搴撻噸璇曡幏鍙栨暟鎹�');
+    const { get } = require('../../api/request');
+    
+    get({
+      url: '/wx/irrigation/getGroupDetails',
+      data: { groupId: this.data.groupId },
+      isShowLoding: true
+    }).then(res => {
+      if (res.success) {
+        this.handleGroupDetailsResponse(res);
+      } else {
+        wx.showToast({
+          title: res.msg || '鑾峰彇鏁版嵁澶辫触',
+          icon: 'none'
+        });
+      }
+    }).catch(err => {
+      console.error('璇锋眰搴撻噸璇曞け璐�:', err);
+      wx.showToast({
+        title: '缃戠粶閿欒',
+        icon: 'none'
+      });
+    }).finally(() => {
       this.setData({
-        waterOutletList: mockData.waterOutlets,
         refreshing: false
       });
-      console.log('璁剧疆鍙栨按鍙f暟鎹畬鎴�:', this.data.waterOutletList);
-    }, 1000);
+    });
+  },
+  
+  /**
+   * 澶勭悊杞亴缁勮鎯呭搷搴旀暟鎹�
+   */
+  handleGroupDetailsResponse: function(response) {
+    const data = response.content;
     
-    // 瀹為檯椤圭洰涓簲璇ヤ娇鐢╳x.request鑾峰彇鏁版嵁
-    // wx.request({
-    //   url: `https://your-api-url/groups/${this.data.groupId}/waterOutlets`,
-    //   method: 'GET',
-    //   success: (res) => {
-    //     if (res.data && res.data.code === 0) {
-    //       this.setData({
-    //         waterOutletList: res.data.data.waterOutlets,
-    //         refreshing: false
-    //       });
-    //     } else {
-    //       wx.showToast({
-    //         title: '鑾峰彇鏁版嵁澶辫触',
-    //         icon: 'none'
-    //       });
-    //       this.setData({
-    //         refreshing: false
-    //       });
-    //     }
-    //   },
-    //   fail: () => {
-    //     wx.showToast({
-    //       title: '缃戠粶閿欒',
-    //       icon: 'none'
-    //     });
-    //     this.setData({
-    //       refreshing: false
-    //     });
-    //   }
-    // });
+    // 澶勭悊鍙栨按鍙f暟鎹�
+    const waterOutletList = data.intakes.map(item => {
+      return {
+        id: item.rtuAddr, // 浣跨敤rtuAddr浣滀负ID
+        name: item.intakeName,
+        rtuAddr: item.rtuAddr,
+        status: item.isOnLine ? 'online' : 'offline'
+      };
+    });
+    
+    this.setData({
+      projectName: data.projectName || this.data.projectName,
+      groupName: data.groupName || this.data.groupName,
+      waterOutletList: waterOutletList,
+      refreshing: false
+    });
+    
+    console.log('璁剧疆鍙栨按鍙f暟鎹畬鎴�:', this.data.waterOutletList);
   },
 
   /**

--
Gitblit v1.8.0