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 | 104 ++++++++++++++++++++++++++++-----------------------
1 files changed, 57 insertions(+), 47 deletions(-)
diff --git a/mqtt/MqttView.vue b/mqtt/MqttView.vue
index 0064474..db452a0 100644
--- a/mqtt/MqttView.vue
+++ b/mqtt/MqttView.vue
@@ -15,6 +15,12 @@
},
+ destroyed() {
+ console.error("MQTT缁勪欢閿�姣�")
+ this.$mqttTool.end().then(res => {
+ console.error(res)
+ })
+ },
methods: {
initMqtt() {
uni.getSystemInfo({
@@ -41,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
+ // #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
+ // username: account.username,
+ // password: account.password,
+ //缁熶竴浣跨敤绉熸埛鐧诲綍 TODO 娣诲姞澶氱鎴风敤鎴�
+ username: 'tongjitang',
+ password: '123456'
}
if (!this.$mqttTool.client) {
this.$mqttTool.client = await this.$mqttTool.connect(opts);
@@ -70,39 +79,40 @@
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_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,
@@ -113,30 +123,30 @@
// if (!client) {
// return false
// }
- let that = this
+ let that = this
let client = this.$mqttTool.client
client.on('connect', function(res) {
- console.error('杩炴帴鎴愬姛')
+ console.error('杩炴帴鎴愬姛')
console.error(res)
})
client.on('reconnect', function(res) {
- console.error('閲嶆柊杩炴帴')
+ console.error('閲嶆柊杩炴帴')
console.error(res)
})
client.on('error', function(res) {
- console.info('杩炴帴閿欒')
+ console.info('杩炴帴閿欒')
console.error(res)
})
client.on('close', function(res) {
- console.error('鍏抽棴鎴愬姛')
+ console.error('鍏抽棴鎴愬姛')
console.error(res)
})
client.on('message', function(topic, message, buffer) {
uni.$emit(that.$constant.MQTT_TOPIC_MESSAGE, message);
- console.error("鏀跺埌message锛堟�伙級锛�"+topic)
+ //console.error("鏀跺埌message锛堟�伙級锛�"+topic)
})
--
Gitblit v1.9.3