消息中心监听新消息

feasure-livedata
lld 2026-04-03 23:50:33 +08:00
parent d83f75f2d6
commit fcf00515af
3 changed files with 38 additions and 7 deletions

View File

@ -16,6 +16,12 @@ export function getMessage(id) {
method: 'get'
})
}
export function unReadCount() {
return request({
url: '/warn/message/unReadCount',
method: 'get'
})
}
// 新增系统消息中心
export function addMessage(data) {
@ -65,10 +71,10 @@ export function getMessages(query) {
})
}
export function getMsgOverview(query) {
export function getMsgOverview(data) {
return request({
url: '/warn/message/getMsgOverview',
method: 'get',
params: query
data: data
})
}

View File

@ -251,7 +251,12 @@ export default {
item.createTime = msgItem.createTime
}
})
})
});
if (this.messageList.filter(item => item.readStatus === 0).length>0) {
uni.showTabBarRedDot({index: 2})
} else {
uni.hideTabBarRedDot({index: 2 })
}
}
})
},
@ -314,21 +319,18 @@ export default {
event:3
}
if (!regex[tag]) return;
console.info("收到消息2222",topic)
let msgData = {};
// JSON
try {
msgData = JSON.parse(payload);
var msg = msgData.msgType;
console.info("收到消息5555",msg)
if (!regex[tag]) return;
const item = this.msgList[regex[tag]];
item.numBadge+=1;
item.content = msg.content;
item.createTime = msg.createTime;
console.info("收到消息3333",item)
uni.showTabBarRedDot({index: 2})
} catch (e) {
console.error("MQTT消息解析失败", e, payload);
}

View File

@ -126,6 +126,7 @@ export function connectMqtt() {
// console.log(`收到MQTT消息topic=${topic}message=${message}`)
if (typeof mqttState.onMessageCallback === 'function') {
mqttState.onMessageCallback(topic, message)
ackMsg(topic, payload)
}
})
@ -138,6 +139,28 @@ export function connectMqtt() {
}
}
export function ackMsg(topic, payload) {
var words = topic.split("/");
if (words.length!==3) {
return;
}
const agriList = uni.getStorageSync('agri_list')
if (agriList.length === 0 || !agriList.includes(words[1])) {
return;
}
const tag = topic.match(/[^/]+$/)?.[0]
var regex = {
alarm:1,
notice:2,
event:3
}
if (!regex[tag]) return;
uni.showTabBarRedDot({index: 2})
// uni.setTabBarBadge({
// index: 0,
// text: '666'
// })
}
/**
* 设置页面专属消息回调各页面独立处理消息
* @param {Function} callback - (topic, message) => {}