From fcf00515afefc853127f0904f061c388cafba564 Mon Sep 17 00:00:00 2001 From: lld <15027638633@163.com> Date: Fri, 3 Apr 2026 23:50:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E4=B8=AD=E5=BF=83=E7=9B=91?= =?UTF-8?q?=E5=90=AC=E6=96=B0=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/warn/message.js | 10 ++++++++-- pages/news/index.vue | 12 +++++++----- utils/mqtt.js | 23 +++++++++++++++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/api/warn/message.js b/api/warn/message.js index 13646cd..339c1b8 100644 --- a/api/warn/message.js +++ b/api/warn/message.js @@ -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 }) } \ No newline at end of file diff --git a/pages/news/index.vue b/pages/news/index.vue index 97e9962..ebd8354 100644 --- a/pages/news/index.vue +++ b/pages/news/index.vue @@ -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); } diff --git a/utils/mqtt.js b/utils/mqtt.js index d99f61a..cc98041 100644 --- a/utils/mqtt.js +++ b/utils/mqtt.js @@ -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) => {}