From 90612989855f6849fd94b0665168c3bb7619ff32 Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期一, 07 四月 2025 18:08:01 +0800
Subject: [PATCH] 更新项目配置,添加多个项目的专有设置,包括登录需求和统一ID;优化用户数据获取逻辑,确保根据项目需求进行登录状态检查;调整界面显示项目名称和提示信息,增强用户体验。
---
pages/irrigationDetail/irrigationDetail.js | 295 +++++++++++------------------------------------------------
1 files changed, 55 insertions(+), 240 deletions(-)
diff --git a/pages/irrigationDetail/irrigationDetail.js b/pages/irrigationDetail/irrigationDetail.js
index 5b4907b..5012c84 100644
--- a/pages/irrigationDetail/irrigationDetail.js
+++ b/pages/irrigationDetail/irrigationDetail.js
@@ -5,248 +5,51 @@
data: {
planCode: '',
startTime: '',
- projects: [],
- isRefreshing: false, // 涓嬫媺鍒锋柊鐘舵��
- planId: '' // 淇濆瓨璁″垝ID
+ isRefreshing: false,
+ projects: []
},
/**
* 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
*/
onLoad: function (options) {
- if (options.id) {
- this.setData({
- planId: options.id
- });
- // 浠庡垪琛ㄩ〉闈㈣繘鍏ユ椂锛屾墍鏈夐」鐩粯璁ゆ敹璧�
- const fromListPage = options.fromList === 'true';
- this.loadIrrigationDetail(options.id, !fromListPage);
- }
- },
-
- /**
- * 鍔犺浇鐏屾簤璁″垝璇︽儏
- * @param {string} id 鐏屾簤璁″垝ID
- * @param {boolean} isFirstLoad 鏄惁棣栨鍔犺浇
- */
- loadIrrigationDetail: function (id, isFirstLoad = false) {
- // 寮�濮嬪姞杞斤紝璁剧疆鍒锋柊鐘舵��
+ // 妯℃嫙鏁版嵁
this.setData({
- isRefreshing: true
- });
-
- // 淇濆瓨褰撳墠椤圭洰鐨勫睍寮�鐘舵��
- const currentExpandStates = {};
- if (!isFirstLoad && this.data.projects.length > 0) {
- this.data.projects.forEach((project, index) => {
- currentExpandStates[project.id] = project.expanded;
- });
- }
-
- // 杩欓噷搴旇鏄粠API鑾峰彇鏁版嵁
- // 浠ヤ笅鏄ā鎷熸暟鎹�
- const mockData = {
- planCode: 'IRG20240317001',
- startTime: '2024-03-17 08:00',
- projects: [
- {
- id: 1,
- name: '椤圭洰A',
- expanded: isFirstLoad ? true : false, // 浠呭湪闈炲垪琛ㄩ〉杩涘叆涓旈娆″姞杞芥椂灞曞紑绗竴涓」鐩�
- groups: [
- {
- id: 1,
- name: '杞亴缁凙-1',
- status: 'irrigated', // 宸茬亴婧�
- statusText: '宸茬亴婧�',
- startTime: '2024-03-17 08:00',
- endTime: '2024-03-17 09:30',
- duration: 90
- },
- {
- id: 2,
- name: '杞亴缁凙-2',
- status: 'irrigating', // 姝e湪鐏屾簤
- statusText: '姝e湪鐏屾簤',
- startTime: '2024-03-17 09:30',
- endTime: '2024-03-17 11:00',
- duration: 90
- }
- ]
- },
- {
- id: 2,
- name: '椤圭洰B',
- expanded: false,
- groups: [
- {
- id: 3,
- name: '杞亴缁凚-1',
- status: 'waiting', // 鏈亴婧�
- statusText: '鏈亴婧�',
- startTime: '2024-03-17 11:00',
- endTime: '2024-03-17 12:30',
- duration: 90
- },
- {
- id: 4,
- name: '杞亴缁凚-2',
- status: 'waiting', // 鏈亴婧�
- statusText: '鏈亴婧�',
- startTime: '2024-03-17 12:30',
- endTime: '2024-03-17 14:00',
- duration: 90
- }
- ]
- },
- {
- id: 3,
- name: '椤圭洰C',
- expanded: false,
- groups: [
- {
- id: 5,
- name: '杞亴缁凜-1',
- status: 'waiting', // 鏈亴婧�
- statusText: '鏈亴婧�',
- startTime: '2024-03-17 14:00',
- endTime: '2024-03-17 15:30',
- duration: 90
- }
- ]
- }
- ]
- };
-
- // 璁$畻姣忎釜椤圭洰鐨勬�荤亴婧夋椂闀�
- mockData.projects = this.calculateProjectTotalDuration(mockData.projects);
-
- // 濡傛灉涓嶆槸棣栨鍔犺浇锛屾仮澶嶉」鐩殑灞曞紑鐘舵��
- if (!isFirstLoad) {
- mockData.projects.forEach(project => {
- if (currentExpandStates[project.id] !== undefined) {
- project.expanded = currentExpandStates[project.id];
- }
- });
- }
-
- // 妯℃嫙缃戠粶璇锋眰寤惰繜
- setTimeout(() => {
- // 璁剧疆椤甸潰鏁版嵁
- this.setData({
- planCode: mockData.planCode,
- startTime: mockData.startTime,
- projects: mockData.projects,
- isRefreshing: false // 缁撴潫鍒锋柊鐘舵��
- });
- }, 1000);
-
- // 瀹為檯椤圭洰涓簲璇ヤ娇鐢╳x.request鑾峰彇鏁版嵁
- // wx.request({
- // url: 'https://your-api-url/irrigation/' + id,
- // method: 'GET',
- // success: (res) => {
- // if (res.data && res.data.code === 0) {
- // // 鑾峰彇鏂版暟鎹�
- // let projects = res.data.data.projects;
- //
- // // 濡傛灉鏄娆″姞杞斤紝璁剧疆榛樿灞曞紑鐘舵��
- // if (isFirstLoad) {
- // projects = projects.map((project, index) => {
- // return {
- // ...project,
- // expanded: index === 0 // 榛樿鍙睍寮�绗竴涓」鐩�
- // };
- // });
- // } else {
- // // 濡傛灉涓嶆槸棣栨鍔犺浇锛屾仮澶嶉」鐩殑灞曞紑鐘舵��
- // projects = projects.map(project => {
- // return {
- // ...project,
- // expanded: currentExpandStates[project.id] !== undefined
- // ? currentExpandStates[project.id]
- // : false
- // };
- // });
- // }
- //
- // // 璁$畻姣忎釜椤圭洰鐨勬�荤亴婧夋椂闀�
- // projects = this.calculateProjectTotalDuration(projects);
- //
- // this.setData({
- // planCode: res.data.data.planCode,
- // startTime: res.data.data.startTime,
- // projects: projects,
- // isRefreshing: false // 缁撴潫鍒锋柊鐘舵��
- // });
- // } else {
- // wx.showToast({
- // title: '鑾峰彇鏁版嵁澶辫触',
- // icon: 'none'
- // });
- // this.setData({
- // isRefreshing: false // 缁撴潫鍒锋柊鐘舵��
- // });
- // }
- // },
- // fail: () => {
- // wx.showToast({
- // title: '缃戠粶閿欒',
- // icon: 'none'
- // });
- // this.setData({
- // isRefreshing: false // 缁撴潫鍒锋柊鐘舵��
- // });
- // }
- // });
- },
-
- /**
- * 璁$畻姣忎釜椤圭洰鐨勬�荤亴婧夋椂闀�
- */
- calculateProjectTotalDuration: function(projects) {
- return projects.map(project => {
- // 璁$畻椤圭洰涓嬫墍鏈夎疆鐏岀粍鐨勬�绘椂闀�
- const totalDuration = project.groups.reduce((total, group) => {
- return total + (group.duration || 0);
- }, 0);
-
- return {
- ...project,
- totalDuration: totalDuration
- };
- });
- },
-
- /**
- * 鍒囨崲椤圭洰灞曞紑/鏀惰捣鐘舵��
- */
- toggleProject: function (e) {
- const index = e.currentTarget.dataset.index;
- const expanded = this.data.projects[index].expanded;
-
- // 鏇存柊椤圭洰鐨勫睍寮�鐘舵��
- const key = `projects[${index}].expanded`;
- this.setData({
- [key]: !expanded
- });
- },
-
- /**
- * 瀵艰埅鍒拌疆鐏岀粍璇︽儏椤甸潰
- */
- navigateToGroupDetail: function (e) {
- const projectName = e.currentTarget.dataset.projectName;
- const groupName = e.currentTarget.dataset.groupName;
- const groupId = e.currentTarget.dataset.groupId;
- const status = e.currentTarget.dataset.status;
-
- console.log('璺宠浆鍒扮粍璇︽儏椤甸潰锛屽師濮嬬姸鎬�:', status);
-
- // 瀵艰埅鍒扮粍璇︽儏椤甸潰锛屽苟浼犻�掑弬鏁�
- // 娉ㄦ剰锛氶渶瑕佸皢status杞崲涓篿sIrrigating鍙傛暟锛屼互渚垮湪缁勮鎯呴〉闈㈡纭樉绀哄懡浠ょ姸鎬�
- wx.navigateTo({
- url: `/pages/groupDetail/groupDetail?projectName=${projectName}&groupName=${groupName}&groupId=${groupId}&status=${status}&isIrrigating=${status === 'irrigating' ? 'true' : 'false'}`
+ planCode: 'IRR-2024-001',
+ startTime: '2024-03-20 08:00',
+ projects: [{
+ id: 1,
+ name: '绀轰緥椤圭洰',
+ groups: [
+ {
+ id: 1,
+ name: '杞亴缁�1',
+ status: 'pending',
+ statusText: '寰呯亴婧�',
+ startTime: '08:00',
+ endTime: '09:00',
+ duration: 60
+ },
+ {
+ id: 2,
+ name: '杞亴缁�2',
+ status: 'in_progress',
+ statusText: '鐏屾簤涓�',
+ startTime: '09:00',
+ endTime: '10:00',
+ duration: 60
+ },
+ {
+ id: 3,
+ name: '杞亴缁�3',
+ status: 'completed',
+ statusText: '宸插畬鎴�',
+ startTime: '10:00',
+ endTime: '11:00',
+ duration: 60
+ }
+ ]
+ }]
});
},
@@ -282,14 +85,16 @@
* 涓嬫媺鍒锋柊澶勭悊鍑芥暟
*/
onPullDownRefresh: function () {
- // 閲嶆柊鍔犺浇鏁版嵁锛屼絾淇濇寔灞曞紑鐘舵��
- if (this.data.planId) {
- this.loadIrrigationDetail(this.data.planId, false);
- } else {
+ this.setData({
+ isRefreshing: true
+ });
+
+ // 妯℃嫙鍒锋柊鏁版嵁
+ setTimeout(() => {
this.setData({
isRefreshing: false
});
- }
+ }, 1000);
},
/**
@@ -304,5 +109,15 @@
*/
onShareAppMessage: function () {
+ },
+
+ /**
+ * 瀵艰埅鍒拌疆鐏岀粍璇︽儏椤甸潰
+ */
+ navigateToGroupDetail: function (e) {
+ const { projectName, groupName, groupId, status } = e.currentTarget.dataset;
+ wx.navigateTo({
+ url: `/pages/groupDetail/groupDetail?projectName=${projectName}&groupName=${groupName}&groupId=${groupId}&status=${status}`
+ });
}
})
\ No newline at end of file
--
Gitblit v1.8.0