mqtt架构修改

master
xce 2026-01-24 19:54:38 +08:00
parent 5c09b7fd63
commit 4fd68347e0
2 changed files with 8 additions and 3 deletions

View File

@ -304,7 +304,7 @@ export default {
if ((e === 'A' || e==='B' || e==='C') if ((e === 'A' || e==='B' || e==='C')
&& store.getters && store.getters.name === 'admin' ) { && store.getters && store.getters.name === 'admin' ) {
this.getNewSpecialData(e); this.getNewSpecialData(e);
this.mqttConfig.subscribeTopic = `frontend/${clientId}/dtu/862538063921866${MQTT_TOPIC_SUFFIX.UP}`; this.mqttConfig.subscribeTopic = `frontend/${clientId}/dtu/862538065276061${MQTT_TOPIC_SUFFIX.UP}`;
} }
const selectedItem = this.range.find(item => item.value === e); const selectedItem = this.range.find(item => item.value === e);
if (selectedItem) { if (selectedItem) {
@ -406,7 +406,6 @@ export default {
// 3. // 3.
const isAdmin = store.getters?.name === 'admin'; const isAdmin = store.getters?.name === 'admin';
const sk = (isAdmin && ['A','B','C'].includes(this.imei)) ? IMEI_SENSOR_MAP[this.imei] : IMEI_SENSOR_MAP.A; const sk = (isAdmin && ['A','B','C'].includes(this.imei)) ? IMEI_SENSOR_MAP[this.imei] : IMEI_SENSOR_MAP.A;
// 4. liveData // 4. liveData
this.liveData = Object.fromEntries( this.liveData = Object.fromEntries(
Object.entries(sk).map(([k, skVal]) => [ Object.entries(sk).map(([k, skVal]) => [

View File

@ -78,7 +78,6 @@ export function connectMqtt() {
console.error('MQTT连接失败请先调用initMqttConfig初始化配置') console.error('MQTT连接失败请先调用initMqttConfig初始化配置')
return false return false
} }
console.info(mqttState.client!=null,mqttState.client)
// 避免重复连接 // 避免重复连接
if (mqttState.client!=null) { if (mqttState.client!=null) {
console.log('MQTT已连接无需重复操作') console.log('MQTT已连接无需重复操作')
@ -102,6 +101,13 @@ export function connectMqtt() {
}) })
mqttState.client.on('close', () => { mqttState.client.on('close', () => {
if (getToken()) {
batchUnsubscribe({clientId:mqttState.options.clientId}).then(response => {
if (response.code === 200) {
console.info("取消订阅成功!")
}
})
}
console.log('MQTT连接断开') console.log('MQTT连接断开')
mqttState.isConnected = false mqttState.isConnected = false
}) })