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 |  202 +++++++++++++++++++++++++++++++------------------
 1 files changed, 127 insertions(+), 75 deletions(-)

diff --git a/mqtt/MqttView.vue b/mqtt/MqttView.vue
index 412d8bf..db452a0 100644
--- a/mqtt/MqttView.vue
+++ b/mqtt/MqttView.vue
@@ -4,7 +4,6 @@
 </template>
 
 <script>
- 
 	export default {
 		name: 'MqttView',
 		data() {
@@ -13,92 +12,145 @@
 			}
 		},
 		onReady() {
-			 
+
+
+		},
+		destroyed() {
+			console.error("MQTT缁勪欢閿�姣�")
+			this.$mqttTool.end().then(res => {
+				console.error(res)
+			})
 		},
 		methods: {
-			initMqtt(){
+			initMqtt() {
 				uni.getSystemInfo({
 					success: (res) => {
 						let deviceId = res.deviceId
 						if (!deviceId) {
 							deviceId = 'mobile-' + this.tenantId + '-' + Date.parse(new Date())
 						}
-						uni.setStorageSync(this.$constant.DEVICE_ID, 'mobile-' + this.tenantId + '-' + res.deviceId);
+						uni.setStorageSync(this.$constant.DEVICE_ID, 'mobile-' + this.tenantId + '-' + res
+							.deviceId);
 					}
 				})
-					this.startConnect();
+				this.startConnect();
 			},
-			 /* 杩炴帴MQTT */
-			 async startConnect() {
-			 	var _this = this
-			 	const account = uni.getStorageSync('account');
-			 	const deviceid = uni.getStorageSync(this.$constant.DEVICE_ID);
-			 
-			 	if (!account) {
-			 
-			 		return false
-			 	}
-			 	let opts = {
-			 		// #ifdef H5
-			 		url: 'ws://' + this.$api.mqttBaseUrl + ':8083/mqtt',
-			 		// #endif
-			 		// #ifdef APP-PLUS
-			 		url: 'wx://' + this.$api.mqttBaseUrl + ':8083/mqtt',
-			 		// #endif
-			 		clientId: deviceid,
-			 		username: account.username,
-			 		password: account.password
-			 	}
-			 	if (!this.$mqttTool.client) {
-			 		var client = await this.$mqttTool.connect(opts);
-			 	}
-			 	//璁㈤槄鏌ヨ璁惧鐘舵�佽繑鍥炴暟鎹�
-			 	this.$mqttTool.subscribe({
-			 		topic: this.$constant.SERVICE_DOWN + '/' + deviceid + '/#',
-			 		qos: 0
-			 	}).then(res => {
-			 		console.error(res)
-			 	})
-			  
-			 	//璁㈤槄璁惧鏁呴殰骞挎挱锛堝箍鎾笉鍦ㄤ箮瀹㈡埛绔痠d锛屽彂閫佺粰绉熸埛涓嬫墍鏈夊湪绾跨殑璁惧锛�
-			 	this.$mqttTool.subscribe({
-			 		topic: this.$constant.SERVICE_BROADCAST_TENANT_REAL_FAULT.replace('%s', this.tenantId),
-			 		qos: 0
-			 	}).then(res => {
-			 		console.error(res)
-			 	})
-			 	//璁㈤槄鍙戦�佹寚浠よ繑鍥炵粨鏋�
-			 	// this.$mqttTool.subscribe({
-			 	// 	topic: this.$constant.SERVICE_RES_EQU_CMD,
-			 	// 	qos: 0
-			 	// }).then(res => {
-			 	// 	console.error(res)
-			 	// })
-			 	// if (!client) {
-			 	// 	return false
-			 	// }
+			/* 杩炴帴MQTT */
+			async startConnect() {
+				var _this = this
+				const account = uni.getStorageSync('account');
+				const deviceid = uni.getStorageSync(this.$constant.DEVICE_ID);
+
+				if (!account) {
+
+					return false
+				}
+				let opts = {
+					// #ifdef H5
+					url: 'ws://' + this.$api.mqttBaseUrl + ':8083/mqtt',
+					// #endif
+					// #ifdef MP-WEIXIN
+					url: 'wxs://' + this.$api.mqttBaseUrl + ':8084/mqtt', // 寰俊灏忕▼搴忓己鍒� WSS
+					// #endif
+					// #ifdef APP-PLUS
+					url: 'wx://' + this.$api.mqttBaseUrl + ':8083/mqtt', // Android/iOS 鐢ㄦ櫘閫� WebSocket
+					// #endif
+					clientId: deviceid,
+					// username: account.username,
+					// password: account.password,
+					//缁熶竴浣跨敤绉熸埛鐧诲綍 TODO 娣诲姞澶氱鎴风敤鎴�
+					username: 'tongjitang',
+					password: '123456'
+				}
+				if (!this.$mqttTool.client) {
+					this.$mqttTool.client = await this.$mqttTool.connect(opts);
+				}
+				//璁㈤槄鏌ヨ璁惧鐘舵�佽繑鍥炴暟鎹�
+				this.$mqttTool.subscribe({
+					topic: this.$constant.SERVICE_DOWN + '/' + deviceid + '/#',
+					qos: 0
+				}).then(res => {
+					console.error(res)
+				})
+
+				//璁㈤槄璁惧鏁呴殰骞挎挱锛堝箍鎾笉鍦ㄤ箮瀹㈡埛绔痠d锛屽彂閫佺粰绉熸埛涓嬫墍鏈夊湪绾跨殑璁惧锛�
+				this.$mqttTool.subscribe({
+					topic: this.$constant.SERVICE_BROADCAST_TENANT_REAL_FAULT.replace('%s', this.tenantId),
+					qos: 0
+				}).then(res => {
+					console.error(res)
+				})
+
+				//璁㈤槄璁惧瀹炴椂鏁呴殰锛堜富鍔ㄨ姹傚彧鍙戠粰璇锋眰璁惧锛�
+				this.$mqttTool.subscribe({
+					topic: this.$constant.SERVICE_ONECE_TENANT_REAL_FAULT.replace('%s', deviceid),
+					qos: 0
+				}).then(res => {
+					console.error(res)
+				})
+
+				//璁㈤槄骞茬嚗璁惧杩炴帴鏂紑鐘舵�佹洿鏂�-绉熸埛鍐呮墍鏈夎澶�
+				this.$mqttTool.subscribe({
+					topic: this.$constant.SERVICE_BROADCAST_TENANT_UPDATE_EQU_STATU.replace('%s', this
+						.tenantId),
+					qos: 0
+				}).then(res => {
+					console.error(res)
+				})
+				//璁㈤槄鏌ヨ骞茬嚗璁惧杩炴帴鐘舵��-鍗曚釜璁惧
+				this.$mqttTool.subscribe({
+					topic: this.$constant.SERVICE_RES_EQU_STATU.replace('%s', deviceid),
+					qos: 0
+				}).then(res => {
+					console.error(res)
+				})
+
+				//璁㈤槄骞茬嚗璁惧瀹炴椂鏁版嵁
+				this.$mqttTool.subscribe({
+					topic: this.$constant.SERVICE_BROADCAST_TENANT_REAL_DATA.replace('%s', this.tenantId),
+					qos: 0
+				}).then(res => {
+					console.error(res)
+				})
+
+				//璁㈤槄鍙戦�佹寚浠よ繑鍥炵粨鏋�
+				// this.$mqttTool.subscribe({
+				// 	topic: this.$constant.SERVICE_RES_EQU_CMD,
+				// 	qos: 0
+				// }).then(res => {
+				// 	console.error(res)
+				// })
+				// if (!client) {
+				// 	return false
+				// }
 				let that = this
-			 
-			 	client.on('connect', function(res) {
-			 		console.error('杩炴帴鎴愬姛')
-			 	})
-			 	client.on('reconnect', function(res) {
-			 		console.error('閲嶆柊杩炴帴')
-			 	})
-			 	client.on('error', function(res) {
-			 		console.info('杩炴帴閿欒')
-			 	})
-			 	client.on('close', function(res) {
-			 
-			 		console.error('鍏抽棴鎴愬姛')
-			 
-			 	})
-			 	client.on('message', function(topic, message, buffer) {
-					that.$eventBus.$emit(that.$constant.MQTT_TOPIC_MESSAGE, message);
-			 		console.info(message)
-				
-			 	})
-			 },
+				let client = this.$mqttTool.client
+
+				client.on('connect', function(res) {
+					console.error('杩炴帴鎴愬姛')
+					console.error(res)
+				})
+				client.on('reconnect', function(res) {
+					console.error('閲嶆柊杩炴帴')
+					console.error(res)
+				})
+				client.on('error', function(res) {
+					console.info('杩炴帴閿欒')
+					console.error(res)
+				})
+				client.on('close', function(res) {
+
+					console.error('鍏抽棴鎴愬姛')
+					console.error(res)
+
+				})
+				client.on('message', function(topic, message, buffer) {
+					uni.$emit(that.$constant.MQTT_TOPIC_MESSAGE, message);
+					//console.error("鏀跺埌message锛堟�伙級锛�"+topic)
+
+
+				})
+			},
 		},
 		computed: {
 			tenantId() {

--
Gitblit v1.9.3