消息中心监听新消息

feasure-livedata
lld 2026-04-04 00:15:23 +08:00
parent 9277036176
commit 7cf8871cef
2 changed files with 10 additions and 2 deletions

11
App.vue
View File

@ -3,6 +3,7 @@ import config from './config'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import mqttUtil from '@/utils/mqtt' import mqttUtil from '@/utils/mqtt'
import {startMqttOnlinePing, stopMqttOnlinePing} from "./utils/mqtt"; import {startMqttOnlinePing, stopMqttOnlinePing} from "./utils/mqtt";
import {unReadCount} from "@/api/warn/message";
export default { export default {
subscribeList:[], subscribeList:[],
globalData: { globalData: {
@ -71,6 +72,7 @@ export default {
// mqtt client connected start // mqtt client connected start
startMqttOnlinePing( 20000); startMqttOnlinePing( 20000);
this.unReadCount()
} }
}, },
onHide() { onHide() {
@ -212,7 +214,14 @@ export default {
icon: 'none' icon: 'none'
}); });
}); });
} },
unReadCount() {
unReadCount().then(response => {
if (response.code === 200 && response.data > 0) {
uni.showTabBarRedDot({index: 2})
}
})
},
} }
} }
</script> </script>

View File

@ -330,7 +330,6 @@ export default {
item.numBadge+=1; item.numBadge+=1;
item.content = msg.content; item.content = msg.content;
item.createTime = msg.createTime; item.createTime = msg.createTime;
uni.showTabBarRedDot({index: 2})
} catch (e) { } catch (e) {
console.error("MQTT消息解析失败", e, payload); console.error("MQTT消息解析失败", e, payload);
} }