From 9cc59c17892a7e69de54e06b5931e78c9b05551c Mon Sep 17 00:00:00 2001
From: zhuguifei <zhuguifei@zhuguifeideiMac.local>
Date: 星期二, 02 九月 2025 09:24:34 +0800
Subject: [PATCH] 添加mqtt登出
---
mqtt/MqttView.vue | 95 +++++++++++++++++++++++++----------------------
1 files changed, 51 insertions(+), 44 deletions(-)
diff --git a/mqtt/MqttView.vue b/mqtt/MqttView.vue
index 0064474..33c97d2 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({
@@ -43,11 +49,11 @@
// #ifdef H5
url: 'wss://' + this.$api.mqttBaseUrl + ':8084/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: 'wxs://' + this.$api.mqttBaseUrl + ':8084/mqtt', // Android/iOS 鐢ㄦ櫘閫� WebSocket
// #endif
clientId: deviceid,
username: account.username,
@@ -70,39 +76,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 +120,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