From 5f9cf32984bb26a99e3fe0359e295c7a27cd5069 Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期二, 22 四月 2025 14:17:13 +0800
Subject: [PATCH] 重构灌溉组详情页面的请求逻辑,改用请求库简化API调用;更新WXML以优化组名展示样式,提升用户体验。
---
pages/groupDetail/groupDetail.js | 114 +++++----------------------------------------------------
pages/groupDetail/groupDetail.wxml | 3 +
pages/groupDetail/groupDetail.wxss | 2
3 files changed, 13 insertions(+), 106 deletions(-)
diff --git a/pages/groupDetail/groupDetail.js b/pages/groupDetail/groupDetail.js
index 600a6b4..edec131 100644
--- a/pages/groupDetail/groupDetail.js
+++ b/pages/groupDetail/groupDetail.js
@@ -1,4 +1,5 @@
const app = getApp();
+const { get } = require('../../api/request');
Page({
/**
@@ -46,112 +47,15 @@
refreshing: true
});
- console.log('寮�濮嬪姞杞借疆鐏岀粍璇︽儏锛実roupId:', this.data.groupId);
-
- // 妫�鏌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; // 宸茬粡浣跨敤璇锋眰搴撳鐞嗭紝鐩存帴杩斿洖
- }
- }
-
- // 浣跨敤wx.request鍙戦�佽姹�
- wx.request({
- url: `${app.globalData.apiBaseUrl}/wx/irrigation/getGroupDetails`,
- method: 'GET',
+ get({
+ url: '/wx/irrigation/getGroupDetails',
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 => {
+ console.log('杞亴缁勮鎯呮帴鍙h繑鍥�:', res);
+
if (res.success) {
this.handleGroupDetailsResponse(res);
} else {
@@ -159,20 +63,22 @@
title: res.msg || '鑾峰彇鏁版嵁澶辫触',
icon: 'none'
});
+ this.setData({
+ refreshing: false
+ });
}
}).catch(err => {
- console.error('璇锋眰搴撻噸璇曞け璐�:', err);
+ console.error('璇锋眰澶辫触:', err);
wx.showToast({
title: '缃戠粶閿欒',
icon: 'none'
});
- }).finally(() => {
this.setData({
refreshing: false
});
});
},
-
+
/**
* 澶勭悊杞亴缁勮鎯呭搷搴旀暟鎹�
*/
diff --git a/pages/groupDetail/groupDetail.wxml b/pages/groupDetail/groupDetail.wxml
index 1619d88..cfe3f99 100644
--- a/pages/groupDetail/groupDetail.wxml
+++ b/pages/groupDetail/groupDetail.wxml
@@ -3,11 +3,12 @@
<view class="page-header">
<view class="header-content">
<view class="project-info">
+ <view class="group-name">{{groupName}}</view>
<view class="project-name">
<text class="project-label">鎵�灞為」鐩細</text>
<text>{{projectName}}</text>
</view>
- <view class="group-name">{{groupName}}</view>
+
</view>
</view>
</view>
diff --git a/pages/groupDetail/groupDetail.wxss b/pages/groupDetail/groupDetail.wxss
index 78bdfba..717239a 100644
--- a/pages/groupDetail/groupDetail.wxss
+++ b/pages/groupDetail/groupDetail.wxss
@@ -26,7 +26,6 @@
.project-name {
font-size: 28rpx;
color: #666666;
- margin-bottom: 10rpx;
display: flex;
align-items: center;
}
@@ -40,6 +39,7 @@
font-size: 36rpx;
font-weight: bold;
color: #333333;
+ margin-bottom: 10rpx;
}
/* 鍙栨按鍙e垪琛ㄥ鍣� */
--
Gitblit v1.8.0