Commit 649d67bf authored by 邓晓峰's avatar 邓晓峰

fix: message throme

parent ed4cf05c
This diff was suppressed by a .gitattributes entry.
......@@ -72,7 +72,8 @@ class Notifier {
// 对外接口
async start() {
window.cc = this.messageCache;
this.getMqttSiteCode().then(() => {
this.getMqttSiteCode().then((res) => {
console.log(res);
this.loadHisMessages(this.currentPageIndex, this.currentPageSize);
this.connectMQTTServer();
});
......@@ -288,7 +289,10 @@ class Notifier {
) {
this.renderWindowsInfo(buffer);
}
const messContent = parseMessage.content;
let messContent = parseMessage.content;
if(this._siteConfig.MessageLevel && this._siteConfig.MessageLevel === "2.0") {
messContent = this.messageThrome(infoType, JSON.parse(parseMessage.content))
}
const timeH =
(new Date() - new Date(parseMessage.createTime)) / 1000 / 60;
const timeMss =
......@@ -300,8 +304,8 @@ class Notifier {
? `${timeH.toFixed(0)}分钟前`
: '刚刚';
const messString = {
id: parseMessage.ID,
infoContent: this._siteConfig.MessageLevel === DEFAULT_PARSE_LEVEL ? messContent: JSON.parse(messContent || "{}"),
id: parseMessage.infoId,
infoContent: parseMessage.content,
infoLevel: parseMessage.level,
time: `${timeMss}`,
infoType,
......@@ -313,14 +317,16 @@ class Notifier {
if (parseMessage.tousers === '') {
messString.messType = '公告';
const content = messContent.replace(/\\n/g, ',');
let content = messContent.replace(/\\n/g, ',');
content = this.replaceSpeak(content)
state = new window.SpeechSynthesisUtterance(
`您有新的公告:${content
.substring(0, content.lastIndexOf(','))
.replace(':', ',')} 时间:${timeMss}`,
);
} else {
const content = messContent.replace(/\\n/g, ',');
let content = messContent.replace(/\\n/g, ',');
content = this.replaceSpeak(content)
state = new window.SpeechSynthesisUtterance(
`您有新的消息:${content
.substring(0, content.lastIndexOf(','))
......@@ -366,6 +372,42 @@ class Notifier {
}
}
replaceSpeak(msg) {
msg = msg.replaceAll(" ", "");
msg = msg.replace(/MPa/ig, "兆帕");
msg = msg.replace(/m³\/h/ig, "立方米每小时");
msg = msg.replace(/m³/ig, "立方米");
msg = msg.replace(/kWh/ig, "千瓦时");
msg = msg.replace(/kW/ig, "千瓦");
msg = msg.replace(/min/ig, "分钟");
msg = msg.replace(/m/ig, "米");
msg = msg.replace(/A/ig, "安");
msg = msg.replace(/V/ig, "伏");
msg = msg.replace(/h/ig, "小时");
return msg;
}
messageThrome(themeName, info) {
let messageInfo = "";
switch (themeName) {
case MESSAGE_TYPE.CASE_TYPE:
case "工单提醒":
messageInfo = `【${info.caseType}${info.flowName}\\n${info.nodeName}\\n承办意见:${info.content}`;
break;
case MESSAGE_TYPE.SCADA_TYPE:
case "通用报警":
messageInfo = `【${info.title}${info.alarmDevice}\\n${info.alarmContent}\\n${info.alarmValue} / ${info.alarmThreshold}\\n${info.deviceCode}`;
break;
case MESSAGE_TYPE.SYS_TYPE:
case "系统通知":
messageInfo = `【${info.noticeType}${info.noticeTitle}\\n${info.noticeContent}`;
break;
default:
messageInfo = info;
break;
}
return messageInfo;
}
renderWindowsInfo(message) {
function notifyMessage(message) {
const parseMessage = JSON.parse(message.payloadString);
......@@ -446,7 +488,7 @@ class Notifier {
self.messageCache.totalCount = result.totalCount;
(result.messages || []).forEach(message => {
const index = self.messageCache.messages.findIndex(
item => item.id == message.id,
item => item.id === message.id,
);
index === -1 && self.messageCache.messages.push(message);
});
......@@ -468,6 +510,7 @@ class Notifier {
return Http.getMqttSiteCode({ 'request.preventCache': Date.now() }).then(
res => {
if (res && res.say.statusCode === ERR_OK) {
if (Array.isArray(res.getMe) && res.getMe.length > 0) {
if (res.getMe[0]) {
self._siteConfig.IsSSL = res.getMe[0].IsSSL
......@@ -504,7 +547,7 @@ class Notifier {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.replace(/[xy]/g, function(c) {
const r = (Math.random() * 16) | 0;
const v = c == 'x' ? r : (r & 0x3) | 0x8;
const v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
})
.toUpperCase();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment