From 7941623b1fb108a154ea4270d7c7e2df6031f6e5 Mon Sep 17 00:00:00 2001
From: zhuguifei <zhuguifei@zhuguifeideiMac.local>
Date: 星期四, 11 十二月 2025 12:36:14 +0800
Subject: [PATCH] 优化页面UI更新

---
 mqtt/MqttView.vue       |   11 +++--
 pages/tabBar/device.vue |   82 ++++++++++++++++++++++++----------------
 common/api.js           |    7 ++-
 3 files changed, 60 insertions(+), 40 deletions(-)

diff --git a/common/api.js b/common/api.js
index 8d4a91f..6e13ab0 100644
--- a/common/api.js
+++ b/common/api.js
@@ -1,11 +1,12 @@
 import {
 	fly
 } from '@/common/request/fly.js'
-const base = "http://192.168.21.3:9999"
-// const base = "https://lanpucloud.cn"
+// const base = "http://192.168.21.3:9999"
+const base = "http://lanpucloud.cn"
 
 //閰嶇疆璇锋眰鍩哄湴鍧�
-fly.config.baseURL = base + ""
+fly.config.baseURL = base + "/herb"
+// fly.config.baseURL = base + ""
 const ip = uni.getStorageSync('lan_ip');
 if (ip) {
 	fly.config.baseURL = "http://" + ip + ":9999"
diff --git a/mqtt/MqttView.vue b/mqtt/MqttView.vue
index 33c97d2..db452a0 100644
--- a/mqtt/MqttView.vue
+++ b/mqtt/MqttView.vue
@@ -47,17 +47,20 @@
 				}
 				let opts = {
 					// #ifdef H5
-					url: 'wss://' + this.$api.mqttBaseUrl + ':8084/mqtt',
+					url: 'ws://' + this.$api.mqttBaseUrl + ':8083/mqtt',
 					// #endif
 					// #ifdef MP-WEIXIN
 					url: 'wxs://' + this.$api.mqttBaseUrl + ':8084/mqtt', // 寰俊灏忕▼搴忓己鍒� WSS
 					// #endif
 					// #ifdef APP-PLUS
-					url: 'wxs://' + this.$api.mqttBaseUrl + ':8084/mqtt', // Android/iOS 鐢ㄦ櫘閫� WebSocket
+					url: 'wx://' + this.$api.mqttBaseUrl + ':8083/mqtt', // Android/iOS 鐢ㄦ櫘閫� WebSocket
 					// #endif
 					clientId: deviceid,
-					username: account.username,
-					password: account.password
+					// username: account.username,
+					// password: account.password,
+					//缁熶竴浣跨敤绉熸埛鐧诲綍 TODO 娣诲姞澶氱鎴风敤鎴�
+					username: 'tongjitang',
+					password: '123456'
 				}
 				if (!this.$mqttTool.client) {
 					this.$mqttTool.client = await this.$mqttTool.connect(opts);
diff --git a/pages/tabBar/device.vue b/pages/tabBar/device.vue
index 5f54016..9781fd8 100644
--- a/pages/tabBar/device.vue
+++ b/pages/tabBar/device.vue
@@ -177,13 +177,13 @@
 
 						     <template v-else-if="item.warnData">
 								<view class="title text-sm text-yellow text-cut"> {{(item.warnData.length > 0) ? item.warnData[0]:''}}</view>
-							</template> 
-							<view v-if="getErrorCount(item) > 0">
-								<u-tag  size="mini" :text="getErrorCount(item)" type="error" plain></u-tag>
-							</view>
-							<view style="width: 20rpx;"></view>
-							<view v-if="getWarnCount(item) > 0">
-								<u-tag  size="mini" :text="getWarnCount(item)" type="warning" plain></u-tag>
+							</template> 
+							<view v-if="getErrorCount(item) > 0">
+								<u-tag  size="mini" :text="getErrorCount(item)" type="error" plain></u-tag>
+							</view>
+							<view style="width: 20rpx;"></view>
+							<view v-if="getWarnCount(item) > 0">
+								<u-tag  size="mini" :text="getWarnCount(item)" type="warning" plain></u-tag>
 							</view>
 
 						</view>
@@ -208,23 +208,28 @@
 				loading: true,
 				// v-model缁戝畾鐨勮繖涓彉閲忎笉瑕佸湪鍒嗛〉璇锋眰缁撴潫涓嚜宸辫祴鍊硷紒锛侊紒
 				dataList: [],
-				curDate: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd'),
+				curDate: dayjs().format('YYYY-MM-DD HH:mm:ss'),
 				isProcessing: false,
 				// key->璁惧绉熸埛+code 
 				dataMap: new Map(),
 
 				alarmEquCount: 0,
 				faultEquCount: 0,
-				timer: null
+				timer: null,
+				mqttThrottleMs: 1000,
+				lastMqttTs: 0,
+				dateTimer: null
 
 			}
 		},
 		onShow() {
 			this.startTimer()
+			this.startDateTimer()
 			this.mqttData()
 		},
 		onHide() {
 			this.stopTimer()
+			this.stopDateTimer()
 			uni.$off(this.$constant.MQTT_TOPIC_MESSAGE)
 		},
 		onTabItemTap: function(e) {
@@ -273,22 +278,22 @@
 
 
 			},
-			
-			getErrorCount(item){
-				let count = 0;
-				if(item.errorData){
-					count += item.errorData.length
-				}
-				return count;
-			},
-			getWarnCount(item){
-				let count = 0;
-				if(item.warnData){
-					count += item.warnData.length
-				}
-				return count;
-			},
-			
+			
+			getErrorCount(item){
+				let count = 0;
+				if(item.errorData){
+					count += item.errorData.length
+				}
+				return count;
+			},
+			getWarnCount(item){
+				let count = 0;
+				if(item.warnData){
+					count += item.warnData.length
+				}
+				return count;
+			},
+			
 			startTimer() {
 				this.timer = setInterval(() => {
 					//this.queryRealFaultData();
@@ -296,6 +301,14 @@
 			},
 			stopTimer() {
 				clearInterval(this.timer);
+			},
+			startDateTimer() {
+				this.dateTimer = setInterval(() => {
+					this.curDate = dayjs().format('YYYY-MM-DD HH:mm:ss')
+				}, 1000);
+			},
+			stopDateTimer() {
+				clearInterval(this.dateTimer);
 			},
 			queryRealFaultData() {
 				//鍙戦�佹暟鎹�
@@ -324,6 +337,9 @@
 			mqttData() {
 				uni.$on(this.$constant.MQTT_TOPIC_MESSAGE, (data) => {
 					try {
+						const now = Date.now();
+						if (now - this.lastMqttTs < this.mqttThrottleMs) return;
+						this.lastMqttTs = now;
 						// 1. 鏁版嵁瑙f瀽鍜岄獙璇�
 						const {
 							data: wdata,
@@ -342,11 +358,11 @@
 							case topics.updateEquStatu:
 								this.handleEquipmentStatusUpdate(wdata);
 								break;
-							case topics.realData:
+							case topics.realData:
 								this.mergeMqttRealData(wdata);
 								break;
 							case topics.realFaultTopic:
-							case topics.oneceFaultTopic:
+							case topics.oneceFaultTopic:
 								this.handleFaultData(wdata);
 								break;
 						}
@@ -428,16 +444,16 @@
 					const [tenantId, equCode] = key.split("_");
 					const targetItem = this.dataList.find(i =>
 						i.tenantId == tenantId && i.code == equCode
-					);
-					
+					);
+					
 					if (targetItem) {
 						const updatedItem = {
 							...targetItem,
 							errorData: targetItem.online ? faults.filter(f => f.faultType === 1).map(n => n.faultName) : [],
 							warnData: targetItem.online ? faults.filter(f => f.faultType === 2).map(n => n.faultName) : [],
-						};
-						if(targetItem.online){
-							updatedItem.refreshTime = dayjs().format('HH:mm:ss');
+						};
+						if(targetItem.online){
+							updatedItem.refreshTime = dayjs().format('HH:mm:ss');
 						}
 						
 						this.$set(this.dataList, this.dataList.indexOf(targetItem), updatedItem);
@@ -573,4 +589,4 @@
 			}
 		}
 	}
-</style>
\ No newline at end of file
+</style>

--
Gitblit v1.9.3