From 8b036c9702908597505a37cff6baba238a49683a Mon Sep 17 00:00:00 2001
From: zuoxiao <zuoxiao>
Date: 星期四, 24 四月 2025 13:42:56 +0800
Subject: [PATCH] 更新灌溉时间设置弹窗样式,优化信息展示;调整多个页面的字体大小以提升视觉一致性和用户体验。
---
pages/home/home.js | 334 ++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 288 insertions(+), 46 deletions(-)
diff --git a/pages/home/home.js b/pages/home/home.js
index afb394f..9f9c353 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -4,12 +4,13 @@
get,
post
} = require('../../api/request.js');
-const {
- PROJECT_URLS
-} = require('../../api/config.js');
+const config = require('../../api/config.js');
const {
PROJECT_CONFIG
} = require('../../utils/projectConfig.js');
+const {
+ ENV
+} = require('../../api/env.js');
Page({
@@ -42,7 +43,8 @@
isFromLogin: false,
showTipDialog: '',
projectConfig: PROJECT_CONFIG, // 娣诲姞椤圭洰閰嶇疆鍒癲ata涓�
- showInfoDialog: false
+ showInfoDialog: false,
+ projectList: []
},
openValve: function (e) {
@@ -58,14 +60,14 @@
})
}
},
- calculateScrollViewHeight: function () {
- wx.createSelectorQuery().selectAll('.list-item').boundingClientRect((rects) => {
- let totalHeight = rects.reduce((sum, rect) => sum + rect.height, 0);
- this.setData({
- scrollViewHeight: totalHeight,
- });
- }).exec();
- },
+ // calculateScrollViewHeight: function () {
+ // wx.createSelectorQuery().selectAll('.list-item').boundingClientRect((rects) => {
+ // let totalHeight = rects.reduce((sum, rect) => sum + rect.height, 0);
+ // this.setData({
+ // scrollViewHeight: totalHeight,
+ // });
+ // }).exec();
+ // },
startPullDownRefresh() {
if (getApp().globalData.isLoggedIn) {
if (!this.data.isWXRefreshing) {
@@ -93,6 +95,10 @@
*/
onLoad(options) {
console.log('home椤甸潰onLoad寮�濮嬶紝鍙傛暟:', options);
+
+ // 鍒濆鍖栭」鐩垪琛ㄦ暟鎹�
+ this.initProjectList();
+
//褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂�
if (options.param === "1" || options.param === "2") {
this.setData({
@@ -124,6 +130,44 @@
}, 100);
},
+ // 鍒濆鍖栭」鐩垪琛ㄦ暟鎹�
+ initProjectList() {
+ // 灏哖ROJECT_CONFIG瀵硅薄杞崲涓烘暟缁勶紝鏂逛究鍦ㄨ鍥句腑閬嶅巻
+ const projectList = Object.entries(PROJECT_CONFIG).map(([key, config]) => ({
+ key: key, // 浣跨敤key浣滀负椤圭洰鏍囪瘑(JYG銆丮Q绛�)
+ tag: config.tag, // 淇濈暀tag瀛楁锛堝師閰嶇疆涓凡鏈夌殑鏍囪瘑锛屽ym銆乵q绛夛級
+ displayName: config.displayName, // 鏄剧ず鍚嶇О
+ ...config // 鍏朵粬閰嶇疆灞炴��
+ }));
+
+ // 鑾峰彇褰撳墠宸查�夋嫨鐨勯」鐩紝榛樿涓篔YG
+ let currentSelectedProject = 'JYG';
+
+ // 灏濊瘯浠庡叏灞�鍙橀噺鑾峰彇
+ const app = getApp();
+ if (app && app.globalData && app.globalData.selectedProject) {
+ currentSelectedProject = app.globalData.selectedProject;
+ } else {
+ // 灏濊瘯浠庢湰鍦板瓨鍌ㄨ幏鍙�
+ try {
+ const savedProject = wx.getStorageSync('selectedProject');
+ if (savedProject) {
+ currentSelectedProject = savedProject;
+ }
+ } catch (e) {
+ console.error('浠庢湰鍦板瓨鍌ㄨ幏鍙栭」鐩け璐�:', e);
+ }
+ }
+
+ // 璁剧疆鍒伴〉闈㈡暟鎹腑
+ this.setData({
+ projectList,
+ selectedProject: currentSelectedProject
+ });
+
+ console.log('椤圭洰鍒楄〃宸插垵濮嬪寲:', projectList, '褰撳墠閫変腑椤圭洰:', currentSelectedProject);
+ },
+
// 鏂板鐨勫垵濮嬪寲椤甸潰杈呭姪鍑芥暟锛屽垎绂诲嚭onLoad涓殑閫昏緫浠ヤ究寤惰繜鎵ц
initializePage(options, fromLogin) {
// 妫�鏌ユ槸鍚﹀凡閫夋嫨椤圭洰
@@ -142,9 +186,12 @@
});
// 璁剧疆 baseUrl
- const baseUrl = PROJECT_URLS[project];
- getApp().globalData.baseUrl = baseUrl;
- getApp().globalData.selectedProject = project;
+ const serverUrl = PROJECT_CONFIG[project]?.serverUrl;
+ if (serverUrl) {
+ getApp().globalData.baseUrl = serverUrl;
+ getApp().globalData.selectedProject = project;
+ console.log('璁剧疆baseUrl:', serverUrl);
+ }
// 鏍规嵁椤圭洰璁剧疆瀵瑰簲鐨則ag
const projectConfig = PROJECT_CONFIG[project];
@@ -340,13 +387,17 @@
})
},
openValveList() {
- // wx.navigateTo({
- // url: '/pages/valveList/valveList',
- // })
- wx.showToast({
- title: '鏆傛湭寮�鏀�',
- icon: 'none'
- })
+ const app = getApp();
+ if (app.globalData.isLoggedIn) {
+ wx.navigateTo({
+ url: '/pages/valveList/valveList',
+ })
+ } else {
+ wx.showToast({
+ title: '璇峰厛鐧诲綍',
+ icon: 'error'
+ })
+ }
},
feedBack() {
wx.showToast({
@@ -360,23 +411,36 @@
const currentProject = getApp().globalData.selectedProject;
const projectConfig = PROJECT_CONFIG[currentProject];
- // 濡傛灉褰撳墠椤圭洰閰嶇疆涓轰笉闇�瑕佺櫥褰曪紝鍒欐彁绀虹敤鎴蜂笉鍙В缁�
+ // 濡傛灉褰撳墠椤圭洰閰嶇疆涓轰笉闇�瑕佺櫥褰曪紝鍒欐彁绀虹敤鎴峰苟鎵撳紑椤圭洰閫夋嫨寮圭獥
if (projectConfig && !projectConfig.needLogin) {
- wx.showToast({
- title: '褰撳墠鐢ㄦ埛涓嶅彲瑙g粦',
- icon: 'none',
- duration: 2000
+ wx.showModal({
+ title: '鍒囨崲椤圭洰',
+ content: '鏄惁纭畾瑙g粦锛�',
+ confirmText: '纭',
+ cancelText: '鍙栨秷',
+ success: (res) => {
+ if (res.confirm) {
+ // 鏄剧ず椤圭洰閫夋嫨寮圭獥
+ this.setData({
+ showProjectDialog: true
+ });
+ }
+ }
});
return;
}
+ // 濡傛灉宸茬櫥褰曪紝鏄剧ず瑙g粦纭瀵硅瘽妗�
if (getApp().globalData.isLoggedIn) {
wx.showModal({
title: '瑙g粦纭',
- content: '纭畾瑕佽В缁戝綋鍓嶈处鍙峰悧锛�',
+ content: '纭畾瑕佽В缁戝綋鍓嶈处鍙峰悧锛熻В缁戝悗灏嗘棤娉曚娇鐢ㄧ浉鍏冲姛鑳斤紝闇�閲嶆柊缁戝畾銆�',
+ confirmText: '纭瑙g粦',
+ confirmColor: '#e34d59',
+ cancelText: '鍙栨秷',
success: (res) => {
if (res.confirm) {
- this.unBindPost()
+ this.unBindPost();
}
}
});
@@ -384,7 +448,7 @@
wx.showToast({
title: '杩樻湭缁戝畾',
icon: 'error'
- })
+ });
}
},
//杞亴
@@ -538,11 +602,8 @@
isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
});
+ this.updateDisplayText();
- // 鎴愬姛鑾峰彇鏁版嵁鍚庡埛鏂癠I楂樺害
- setTimeout(() => {
- this.calculateScrollViewHeight();
- }, 200);
}).catch(err => {
console.error('鑾峰彇鍒楄〃鏁版嵁澶辫触:', err);
// 閿欒鍥炶皟
@@ -938,6 +999,8 @@
// 澶勭悊椤圭洰閫夋嫨纭
handleProjectConfirm() {
+ console.log('寮�濮嬪鐞嗛」鐩�夋嫨纭', this.data.selectedProject, this.data.projectList);
+
if (!this.data.selectedProject) {
wx.showToast({
title: '璇烽�夋嫨椤圭洰',
@@ -949,7 +1012,11 @@
// 鑾峰彇褰撳墠宸查�夐」鐩拰鏂伴�夋嫨鐨勯」鐩�
const currentProject = getApp().globalData.selectedProject;
const newProject = this.data.selectedProject;
+ console.log('褰撳墠椤圭洰:', currentProject, '鏂伴�夋嫨椤圭洰:', newProject);
+ console.log('PROJECT_CONFIG 鍐呭:', PROJECT_CONFIG);
+
const projectConfig = PROJECT_CONFIG[newProject];
+ console.log('閫夋嫨鐨勯」鐩厤缃�:', projectConfig);
if (!projectConfig) {
wx.showToast({
@@ -962,6 +1029,30 @@
// 妫�鏌ユ槸鍚﹀垏鎹簡椤圭洰锛堝鏋滃綋鍓嶉」鐩笉鍚屼簬鏂伴�夋嫨鐨勯」鐩級
const isProjectChanged = currentProject && currentProject !== newProject;
+ // 娣诲姞浜屾纭
+ const confirmText = isProjectChanged
+ ? `纭畾瑕佸皢椤圭洰浠�"${PROJECT_CONFIG[currentProject]?.displayName || '褰撳墠椤圭洰'}"鍒囨崲鍒�"${projectConfig.displayName}"鍚楋紵`
+ : `纭畾閫夋嫨"${projectConfig.displayName}"椤圭洰鍚楋紵`;
+
+ wx.showModal({
+ title: isProjectChanged ? '纭鍒囨崲椤圭洰' : '纭閫夋嫨椤圭洰',
+ content: confirmText,
+ confirmText: isProjectChanged ? '纭鍒囨崲' : '纭',
+ cancelText: '鍙栨秷',
+ success: (res) => {
+ if (res.confirm) {
+ // 鐢ㄦ埛纭閫夋嫨锛岀户缁鐞�
+ this.processProjectSelection(currentProject, newProject, projectConfig, isProjectChanged);
+ } else {
+ // 鐢ㄦ埛鍙栨秷锛屼笉杩涜浠讳綍鎿嶄綔
+ console.log('鐢ㄦ埛鍙栨秷浜嗛」鐩�夋嫨');
+ }
+ }
+ });
+ },
+
+ // 澶勭悊椤圭洰閫夋嫨鐨勫悗缁搷浣�
+ processProjectSelection(currentProject, newProject, projectConfig, isProjectChanged) {
// 濡傛灉鍒囨崲浜嗛」鐩紝鍏堟竻闄ょ櫥褰曠姸鎬�
if (isProjectChanged) {
console.log(`姝e湪浠庨」鐩� ${currentProject} 鍒囨崲鍒� ${newProject}锛屽皢娓呴櫎鐧诲綍鐘舵�乣);
@@ -993,13 +1084,21 @@
// 淇濆瓨椤圭洰閫夋嫨鍒版湰鍦板瓨鍌�
storage.setItem('selectedProject', newProject).then(() => {
- // 鏇存柊 BASEURL
- const baseUrl = PROJECT_URLS[newProject];
-
+ // 璋冪敤setBaseUrl鏉ユ洿鏂板熀纭�URL
+ try {
+ console.log('灏濊瘯璁剧疆鍩虹URL锛岄」鐩�:', newProject);
+ const result = config.setBaseUrl(newProject);
+ console.log('璁剧疆鍩虹URL缁撴灉:', result);
+ } catch (error) {
+ console.error('璁剧疆鍩虹URL鍑洪敊:', error);
+ // 缁х画鎵ц锛屼笉涓柇娴佺▼
+ }
+
// 鏇存柊鍏ㄥ眬鍙橀噺
getApp().globalData = getApp().globalData || {};
- getApp().globalData.baseUrl = baseUrl;
getApp().globalData.selectedProject = newProject;
+ getApp().globalData.baseUrl = projectConfig.serverUrl;
+ getApp().globalData.serverId = projectConfig.serverId;
// 閫氳繃閰嶇疆瀵硅薄缁熶竴璁剧疆椤圭洰鍙傛暟
getApp().globalData.tag = projectConfig.tag;
@@ -1037,7 +1136,7 @@
storage.setItem(`${newProject}_params`, params);
}
- console.log('宸插垏鎹㈠埌椤圭洰:', projectConfig.displayName, '鍩熷悕:', baseUrl, 'tag:', getApp().globalData.tag);
+ console.log('宸插垏鎹㈠埌椤圭洰:', projectConfig.displayName, '鏈嶅姟鍣�:', projectConfig.serverId, 'tag:', getApp().globalData.tag);
this.setData({
showProjectDialog: false
@@ -1235,13 +1334,6 @@
console.log('continueInitPage: 浠庨〉闈㈡暟鎹腑妫�娴嬪埌isFromLogin=true');
fromLogin = true;
}
-
- // 鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId
- // 浣跨敤 wx.nextTick 绛夊緟椤甸潰娓叉煋瀹屾垚
- wx.nextTick(() => {
- this.calculateScrollViewHeight();
- });
-
// 褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂�
if (options && options.param) {
console.log("寮�闃�鎴愬姛鍙傛暟:", options.param);
@@ -1498,4 +1590,154 @@
showInfoDialog: false
})
},
+ //寮哄埗鍒犻櫎
+ onDelete(e) {
+ const item = e.currentTarget.dataset.item;
+ const that = this;
+
+ if (this.data.useTestData) {
+ // 娴嬭瘯鏁版嵁妯″紡涓嬶紝妯℃嫙鍒犻櫎鎿嶄綔
+ wx.showLoading({
+ title: '姝e湪寮哄埗鍒犻櫎璇风◢鍊�...',
+ mask: true
+ });
+
+ // 妯℃嫙璇锋眰寤惰繜
+ setTimeout(() => {
+ wx.hideLoading();
+
+ // 浠庡垪琛ㄤ腑绉婚櫎琚垹闄ょ殑椤�
+ const updatedList = this.data.listData.filter(listItem =>
+ listItem.orderNo !== item.orderNo
+ );
+
+ this.setData({
+ listData: updatedList
+ });
+
+ wx.showToast({
+ title: '鍒犻櫎鎴愬姛',
+ icon: 'success',
+ duration: 2000
+ });
+ }, 1500);
+ return;
+ }
+
+ wx.showLoading({
+ title: '姝e湪寮哄埗鍒犻櫎璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
+ mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false
+ });
+ const data = {
+ vcNum: item.vcNum, //鍙栨按鍙D
+ rtuAddr: item.rtuAddr, //闃�鎺у櫒鍦板潃
+ };
+ post({
+ url: "wx/valve/deleteUnclosed",
+ data: data,
+ timeout: 180000
+ }).then(response => {
+ // 澶勭悊鎴愬姛鍝嶅簲
+ console.log('璇锋眰鎴愬姛:', response);
+ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+ wx.hideLoading();
+ //閲嶆柊鑾峰彇鍒楄〃鍒锋柊鏁版嵁
+ this.getOpenList();
+ }).catch(error => {
+ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+ wx.hideLoading();
+ // 澶勭悊閿欒鍝嶅簲
+ console.error('璇锋眰澶辫触:', error);
+ });
+ },
+ //淇敼鎸夐挳鏂囧瓧
+ updateDisplayText() {
+ const updatedList = this.data.listData.map(item => {
+ let displayText = '';
+ if (item.planned) {
+ displayText = '鍙栨秷';
+ } else {
+ displayText = "鍏抽榾"
+ }
+ let deleteText = "鍒犻櫎"
+ let time;
+ if (!item.dt) {
+ time = "鏆傛棤"
+ } else {
+ time = this.extractTime(item.dt)
+ }
+ if (item.waterInstant===null) {
+ item.waterInstant = "鏆傛棤"
+ }
+
+ return {
+ ...item,
+ displayText,
+ deleteText,
+ time
+ }; // 淇濈暀鎵�鏈夊叾浠栧瓧娈碉紝骞舵坊鍔� displayText 瀛楁
+ });
+ // 鏇存柊鍒楄〃鏁版嵁
+ this.setData({
+ listData: updatedList
+ });
+ },
+ //澶勭悊鏃堕棿鍘绘帀骞存湀鏃�
+ extractTime(datetimeString) {
+ const formattedDate = datetimeString.replace(" ", "T");
+ const date = new Date(formattedDate);
+ // 鑾峰彇灏忔椂銆佸垎閽熷拰绉�
+ const hours = date.getHours().toString().padStart(2, '0');
+ const minutes = date.getMinutes().toString().padStart(2, '0');
+ const seconds = date.getSeconds().toString().padStart(2, '0');
+ return `${hours}:${minutes}:${seconds}`;
+ },
+
+ // 鍒囨崲椤圭洰
+ switchProject(e) {
+ const project = e.currentTarget.dataset.project;
+
+ if (config.setBaseUrl(project)) {
+ this.setData({
+ selectedProject: project
+ });
+
+ // 淇濆瓨閫夋嫨鍒版湰鍦板瓨鍌�
+ try {
+ wx.setStorageSync('selectedProject', project);
+ } catch (e) {
+ console.error('淇濆瓨椤圭洰閫夋嫨澶辫触:', e);
+ }
+
+ // 鏇存柊鍏ㄥ眬鍙橀噺
+ const app = getApp();
+ if (app && app.globalData) {
+ app.globalData.selectedProject = project;
+
+ // 鏍规嵁椤圭洰閰嶇疆璁剧疆鐩稿叧鍙傛暟
+ const projectConfig = PROJECT_CONFIG[project];
+ if (projectConfig) {
+ app.globalData.tag = projectConfig.tag;
+ if (!projectConfig.needLogin) {
+ app.globalData.operator = projectConfig.operatorId;
+ app.globalData.clientId = projectConfig.operatorId;
+ app.globalData.isLoggedIn = true;
+ app.globalData.sessionId = projectConfig.operatorId;
+ // 濡傛灉鏈塿cId锛屼篃璁剧疆
+ if (projectConfig.vcId) {
+ app.globalData.vcId = projectConfig.vcId;
+ }
+ }
+ }
+ }
+
+ // 閲嶆柊鍔犺浇椤甸潰鏁版嵁
+ this.initData();
+ } else {
+ wx.showToast({
+ title: '鍒囨崲椤圭洰澶辫触',
+ icon: 'none'
+ });
+ }
+ },
})
\ No newline at end of file
--
Gitblit v1.8.0