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 { ...@@ -72,7 +72,8 @@ class Notifier {
// 对外接口 // 对外接口
async start() { async start() {
window.cc = this.messageCache; window.cc = this.messageCache;
this.getMqttSiteCode().then(() => { this.getMqttSiteCode().then((res) => {
console.log(res);
this.loadHisMessages(this.currentPageIndex, this.currentPageSize); this.loadHisMessages(this.currentPageIndex, this.currentPageSize);
this.connectMQTTServer(); this.connectMQTTServer();
}); });
...@@ -288,7 +289,10 @@ class Notifier { ...@@ -288,7 +289,10 @@ class Notifier {
) { ) {
this.renderWindowsInfo(buffer); 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 = const timeH =
(new Date() - new Date(parseMessage.createTime)) / 1000 / 60; (new Date() - new Date(parseMessage.createTime)) / 1000 / 60;
const timeMss = const timeMss =
...@@ -300,8 +304,8 @@ class Notifier { ...@@ -300,8 +304,8 @@ class Notifier {
? `${timeH.toFixed(0)}分钟前` ? `${timeH.toFixed(0)}分钟前`
: '刚刚'; : '刚刚';
const messString = { const messString = {
id: parseMessage.ID, id: parseMessage.infoId,
infoContent: this._siteConfig.MessageLevel === DEFAULT_PARSE_LEVEL ? messContent: JSON.parse(messContent || "{}"), infoContent: parseMessage.content,
infoLevel: parseMessage.level, infoLevel: parseMessage.level,
time: `${timeMss}`, time: `${timeMss}`,
infoType, infoType,
...@@ -313,14 +317,16 @@ class Notifier { ...@@ -313,14 +317,16 @@ class Notifier {
if (parseMessage.tousers === '') { if (parseMessage.tousers === '') {
messString.messType = '公告'; messString.messType = '公告';
const content = messContent.replace(/\\n/g, ','); let content = messContent.replace(/\\n/g, ',');
content = this.replaceSpeak(content)
state = new window.SpeechSynthesisUtterance( state = new window.SpeechSynthesisUtterance(
`您有新的公告:${content `您有新的公告:${content
.substring(0, content.lastIndexOf(',')) .substring(0, content.lastIndexOf(','))
.replace(':', ',')} 时间:${timeMss}`, .replace(':', ',')} 时间:${timeMss}`,
); );
} else { } else {
const content = messContent.replace(/\\n/g, ','); let content = messContent.replace(/\\n/g, ',');
content = this.replaceSpeak(content)
state = new window.SpeechSynthesisUtterance( state = new window.SpeechSynthesisUtterance(
`您有新的消息:${content `您有新的消息:${content
.substring(0, content.lastIndexOf(',')) .substring(0, content.lastIndexOf(','))
...@@ -366,6 +372,42 @@ class Notifier { ...@@ -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) { renderWindowsInfo(message) {
function notifyMessage(message) { function notifyMessage(message) {
const parseMessage = JSON.parse(message.payloadString); const parseMessage = JSON.parse(message.payloadString);
...@@ -446,7 +488,7 @@ class Notifier { ...@@ -446,7 +488,7 @@ class Notifier {
self.messageCache.totalCount = result.totalCount; self.messageCache.totalCount = result.totalCount;
(result.messages || []).forEach(message => { (result.messages || []).forEach(message => {
const index = self.messageCache.messages.findIndex( const index = self.messageCache.messages.findIndex(
item => item.id == message.id, item => item.id === message.id,
); );
index === -1 && self.messageCache.messages.push(message); index === -1 && self.messageCache.messages.push(message);
}); });
...@@ -468,6 +510,7 @@ class Notifier { ...@@ -468,6 +510,7 @@ class Notifier {
return Http.getMqttSiteCode({ 'request.preventCache': Date.now() }).then( return Http.getMqttSiteCode({ 'request.preventCache': Date.now() }).then(
res => { res => {
if (res && res.say.statusCode === ERR_OK) { if (res && res.say.statusCode === ERR_OK) {
if (Array.isArray(res.getMe) && res.getMe.length > 0) { if (Array.isArray(res.getMe) && res.getMe.length > 0) {
if (res.getMe[0]) { if (res.getMe[0]) {
self._siteConfig.IsSSL = res.getMe[0].IsSSL self._siteConfig.IsSSL = res.getMe[0].IsSSL
...@@ -504,7 +547,7 @@ class Notifier { ...@@ -504,7 +547,7 @@ class Notifier {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.replace(/[xy]/g, function(c) { .replace(/[xy]/g, function(c) {
const r = (Math.random() * 16) | 0; 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); return v.toString(16);
}) })
.toUpperCase(); .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