消息中心监听新消息
parent
d83f75f2d6
commit
fcf00515af
|
|
@ -16,6 +16,12 @@ export function getMessage(id) {
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
export function unReadCount() {
|
||||||
|
return request({
|
||||||
|
url: '/warn/message/unReadCount',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 新增系统消息中心
|
// 新增系统消息中心
|
||||||
export function addMessage(data) {
|
export function addMessage(data) {
|
||||||
|
|
@ -65,10 +71,10 @@ export function getMessages(query) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMsgOverview(query) {
|
export function getMsgOverview(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/warn/message/getMsgOverview',
|
url: '/warn/message/getMsgOverview',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
params: query
|
data: data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -251,7 +251,12 @@ export default {
|
||||||
item.createTime = msgItem.createTime
|
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
|
event:3
|
||||||
}
|
}
|
||||||
if (!regex[tag]) return;
|
if (!regex[tag]) return;
|
||||||
console.info("收到消息2222",topic)
|
|
||||||
|
|
||||||
let msgData = {};
|
let msgData = {};
|
||||||
// 优化:捕获JSON解析异常
|
// 优化:捕获JSON解析异常
|
||||||
try {
|
try {
|
||||||
msgData = JSON.parse(payload);
|
msgData = JSON.parse(payload);
|
||||||
var msg = msgData.msgType;
|
var msg = msgData.msgType;
|
||||||
console.info("收到消息5555",msg)
|
|
||||||
if (!regex[tag]) return;
|
if (!regex[tag]) return;
|
||||||
const item = this.msgList[regex[tag]];
|
const item = this.msgList[regex[tag]];
|
||||||
item.numBadge+=1;
|
item.numBadge+=1;
|
||||||
item.content = msg.content;
|
item.content = msg.content;
|
||||||
item.createTime = msg.createTime;
|
item.createTime = msg.createTime;
|
||||||
console.info("收到消息3333",item)
|
uni.showTabBarRedDot({index: 2})
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("MQTT消息解析失败:", e, payload);
|
console.error("MQTT消息解析失败:", e, payload);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ export function connectMqtt() {
|
||||||
// console.log(`收到MQTT消息:topic=${topic},message=${message}`)
|
// console.log(`收到MQTT消息:topic=${topic},message=${message}`)
|
||||||
if (typeof mqttState.onMessageCallback === 'function') {
|
if (typeof mqttState.onMessageCallback === 'function') {
|
||||||
mqttState.onMessageCallback(topic, message)
|
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) => {}
|
* @param {Function} callback - (topic, message) => {}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue