Commit 7537eaf7 authored by 邓晓峰's avatar 邓晓峰

fix: notice bug

parent 9c0fcfdb
Pipeline #21603 passed with stages
...@@ -6,9 +6,10 @@ import { connect } from 'react-redux'; ...@@ -6,9 +6,10 @@ import { connect } from 'react-redux';
import isProd from '../../utils/env'; import isProd from '../../utils/env';
import NoticeIcon from '../NoticeIcon'; import NoticeIcon from '../NoticeIcon';
import Notifier from '../Notifier'; import Notifier from '../Notifier';
import { NEW_MESSAGE } from '../Notifier/constants'; import { MESSAGE_TYPE, NEW_MESSAGE } from '../Notifier/constants';
import styles from './index.less'; import styles from './index.less';
import { findPathByWidget } from '../../utils/utils'; import { findPathByWidget, isJSON } from '../../utils/utils';
import { actionCreators } from '../../containers/App/store';
class NoticeIconView extends Component { class NoticeIconView extends Component {
constructor(props) { constructor(props) {
...@@ -30,6 +31,7 @@ class NoticeIconView extends Component { ...@@ -30,6 +31,7 @@ class NoticeIconView extends Component {
this.props.global.userInfo, this.props.global.userInfo,
this.renderVideo, this.renderVideo,
this.renderPlatform, this.renderPlatform,
this.props,
); );
} }
...@@ -72,6 +74,7 @@ class NoticeIconView extends Component { ...@@ -72,6 +74,7 @@ class NoticeIconView extends Component {
}; };
renderPlatform = message => { renderPlatform = message => {
const messageContent = (this.props.global.mqtt_mess.MessageLevel === "2.0" && isJSON(message.infoContent)) ? JSON.parse(message.infoContent): message.infoContent;
this.setState({ this.setState({
platformVisible: true, platformVisible: true,
}); });
...@@ -94,7 +97,7 @@ class NoticeIconView extends Component { ...@@ -94,7 +97,7 @@ class NoticeIconView extends Component {
<div className={styles.content}> <div className={styles.content}>
<div className={styles['content-top']}> <div className={styles['content-top']}>
<a onClick={() => this.handlerMointer(message, true)}> <a onClick={() => this.handlerMointer(message, true)}>
{message.infoContent.alarmDevice} {messageContent.alarmDevice}
</a> </a>
<span <span
title="点击标为已读" title="点击标为已读"
...@@ -103,13 +106,13 @@ class NoticeIconView extends Component { ...@@ -103,13 +106,13 @@ class NoticeIconView extends Component {
</div> </div>
<div className={styles['content-mid']}> <div className={styles['content-mid']}>
<b>{message.infoContent.alarmType}</b> <b>{messageContent.alarmType}</b>
{`|${message.infoContent.alarmContent}`} {`|${messageContent.alarmContent}`}
</div> </div>
<div className={styles['content-bottom']}> <div className={styles['content-bottom']}>
<p> <p>
<b>{message.infoContent.alarmValue}/</b> <b>{messageContent.alarmValue}/</b>
{message.infoContent.alarmThreshold} {messageContent.alarmThreshold}
</p> </p>
<span>{message.time}</span> <span>{message.time}</span>
</div> </div>
...@@ -124,9 +127,22 @@ class NoticeIconView extends Component { ...@@ -124,9 +127,22 @@ class NoticeIconView extends Component {
videoVisible: true, videoVisible: true,
}); });
const { props } = this; const { props } = this;
const data = const infoType = message.infoType
(message && message.messContent && message.messContent.split('\\n')) || ? message.infoType
[]; : MESSAGE_TYPE.SCADA_TYPE;
let data = [];
if (this.props.global.mqtt_mess.MessageLevel === '2.0') {
// eslint-disable-next-line no-shadow
const message = this.notifier.messageThrome(
infoType,
// eslint-disable-next-line no-use-before-define
JSON.parse(message.messContent),
);
data = message.split('\\n');
} else {
data = message.messContent.split('\\n');
}
const id = data[3]; const id = data[3];
const name = data[0]; const name = data[0];
const baseURI = isProd const baseURI = isProd
...@@ -166,9 +182,7 @@ class NoticeIconView extends Component { ...@@ -166,9 +182,7 @@ class NoticeIconView extends Component {
if (detail) { if (detail) {
const widgetID = 'widget_city_综合运营_管网监控_实时监控_报警监控'; const widgetID = 'widget_city_综合运营_管网监控_实时监控_报警监控';
const webPath = 'product/scada/AlertMonitoring/AlertMonitoring'; const webPath = 'product/scada/AlertMonitoring/AlertMonitoring';
debugger
let widget = findPathByWidget("productex/water/IOTMonitor/RealTimeAlarm/RealTimeAlarm", this.props.global.widgets, "", "url"); let widget = findPathByWidget("productex/water/IOTMonitor/RealTimeAlarm/RealTimeAlarm", this.props.global.widgets, "", "url");
console.log(widget)
window.share.event.emit('listenerMointer', { window.share.event.emit('listenerMointer', {
widgetId: widgetID, widgetId: widgetID,
label: '实时报警', label: '实时报警',
...@@ -219,7 +233,15 @@ const mapStateToProps = state => ({ ...@@ -219,7 +233,15 @@ const mapStateToProps = state => ({
global: state.getIn(['global', 'globalConfig']), global: state.getIn(['global', 'globalConfig']),
}); });
const mapDispatchToProps = dispatch => {
return {
updateConfig(config) {
dispatch(actionCreators.getConfig(config));
},
}
}
export default connect( export default connect(
mapStateToProps, mapStateToProps,
null, mapDispatchToProps,
)(NoticeIconView); )(NoticeIconView);
import React from 'react'; import React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { findPathByWidget } from '../../../../utils/utils'; import { findPathByWidget, isJSON } from '../../../../utils/utils';
import commonStyles from '../common.less'; import commonStyles from '../common.less';
import styles from './index.less'; import styles from './index.less';
/* eslint-disable */ /* eslint-disable */
...@@ -26,8 +26,9 @@ export class AlarmContent { ...@@ -26,8 +26,9 @@ export class AlarmContent {
} }
const Alarm = ({ message, confirmRead, config }) => { const Alarm = ({ message, confirmRead, config }) => {
const alarmContent = message.infoContent; const alarmContent = (config.mqtt_mess.MessageLevel === "2.0" && isJSON(message.infoContent)) ? JSON.parse(message.infoContent): message.infoContent;
const goPath = item => { const goPath = item => {
debugger
confirmRead(false, [message.id]); confirmRead(false, [message.id]);
const widgetID = 'widget_city_综合运营_管网监控_实时监控_报警监控'; const widgetID = 'widget_city_综合运营_管网监控_实时监控_报警监控';
const webPath = 'product/scada/AlertMonitoring/AlertMonitoring'; const webPath = 'product/scada/AlertMonitoring/AlertMonitoring';
...@@ -39,10 +40,8 @@ const Alarm = ({ message, confirmRead, config }) => { ...@@ -39,10 +40,8 @@ const Alarm = ({ message, confirmRead, config }) => {
url: widget.url || webPath, url: widget.url || webPath,
}); });
}; };
const alarmValue = console.log("alarmContent", alarmContent, config);
alarmContent && const alarmValue = alarmContent && alarmContent.alarmValue && alarmContent.alarmValue.split(' ');
alarmContent.alarmValue &&
alarmContent.alarmValue.split(' ');
return ( return (
<div <div
className={classNames(styles.scada, commonStyles.messageContainer)} className={classNames(styles.scada, commonStyles.messageContainer)}
......
...@@ -16,8 +16,12 @@ export class NoticeContent { ...@@ -16,8 +16,12 @@ export class NoticeContent {
} }
const Notice = ({ message, confirmRead }) => { const Notice = ({ message, confirmRead }) => {
// eslint-disable-next-line no-debugger
debugger
const noticeContent = message.infoContent; const noticeContent = message.infoContent;
const goPath = item => { const goPath = item => {
// eslint-disable-next-line no-debugger
debugger
confirmRead(false, [message.id]); confirmRead(false, [message.id]);
const webPath = const webPath =
item.webPath || 'product/notification/HistoryNotice/HistoryNotice'; item.webPath || 'product/notification/HistoryNotice/HistoryNotice';
......
...@@ -25,7 +25,7 @@ import createMessage from './message'; ...@@ -25,7 +25,7 @@ import createMessage from './message';
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const Logger = logger('mqtt'); const Logger = logger('mqtt');
class Notifier { class Notifier {
constructor(userInfo, renderVideo, renderPlatform) { constructor(userInfo, renderVideo, renderPlatform, props) {
this.userInfo = userInfo; this.userInfo = userInfo;
this.messageCache = { this.messageCache = {
totalCount: 0, totalCount: 0,
...@@ -41,14 +41,17 @@ class Notifier { ...@@ -41,14 +41,17 @@ class Notifier {
KeepAlive: '', KeepAlive: '',
IsSSL: true, IsSSL: true,
mqtt_path: DEFAULT_MQTT_PATH, mqtt_path: DEFAULT_MQTT_PATH,
mqtt_mess: {},
nginxStart: false
}; };
this._config = { // this._config = {
mqtt_path: '/mqtt', // mqtt_path: '/mqtt',
nginxStart: 'false', // nginxStart: 'false',
mqtt_mess: { // mqtt_mess: {
IsSSL: false, // IsSSL: false,
}, // },
}; // };
this.MQTTCount = 0; this.MQTTCount = 0;
this.MQTTClient = null; this.MQTTClient = null;
this.MQTTOptions = {}; this.MQTTOptions = {};
...@@ -67,13 +70,13 @@ class Notifier { ...@@ -67,13 +70,13 @@ class Notifier {
this.renderVideoElement = null; this.renderVideoElement = null;
this.renderPlatform = renderPlatform; this.renderPlatform = renderPlatform;
this.renderPlatformElement = null; this.renderPlatformElement = null;
this.props = props;
} }
// 对外接口 // 对外接口
async start() { async start() {
window.cc = this.messageCache; window.cc = this.messageCache;
this.getMqttSiteCode().then((res) => { this.getMqttSiteCode().then((res) => {
console.log(res);
this.loadHisMessages(this.currentPageIndex, this.currentPageSize); this.loadHisMessages(this.currentPageIndex, this.currentPageSize);
this.connectMQTTServer(); this.connectMQTTServer();
}); });
...@@ -277,6 +280,7 @@ class Notifier { ...@@ -277,6 +280,7 @@ class Notifier {
const userInfo = this.getUserInfo(); const userInfo = this.getUserInfo();
const infoType = this.getMessageType(parseMessage.infoType); const infoType = this.getMessageType(parseMessage.infoType);
let state = null; let state = null;
if ( if (
_.isEmpty(parseMessage.tousers) || _.isEmpty(parseMessage.tousers) ||
userInfo.OID == parseMessage.tousers || userInfo.OID == parseMessage.tousers ||
...@@ -290,6 +294,7 @@ class Notifier { ...@@ -290,6 +294,7 @@ class Notifier {
this.renderWindowsInfo(buffer); this.renderWindowsInfo(buffer);
} }
let messContent = parseMessage.content; let messContent = parseMessage.content;
if(this._siteConfig.MessageLevel && this._siteConfig.MessageLevel === "2.0") { if(this._siteConfig.MessageLevel && this._siteConfig.MessageLevel === "2.0") {
messContent = this.messageThrome(infoType, JSON.parse(parseMessage.content)) messContent = this.messageThrome(infoType, JSON.parse(parseMessage.content))
} }
...@@ -317,7 +322,7 @@ class Notifier { ...@@ -317,7 +322,7 @@ class Notifier {
if (parseMessage.tousers === '') { if (parseMessage.tousers === '') {
messString.messType = '公告'; messString.messType = '公告';
let content = messContent.replace(/\\n/g, ','); let content = (_.isObject(messContent) ? messContent.content: messContent).replace(/\\n/g, ',');
content = this.replaceSpeak(content) content = this.replaceSpeak(content)
state = new window.SpeechSynthesisUtterance( state = new window.SpeechSynthesisUtterance(
`您有新的公告:${content `您有新的公告:${content
...@@ -325,7 +330,7 @@ class Notifier { ...@@ -325,7 +330,7 @@ class Notifier {
.replace(':', ',')} 时间:${timeMss}`, .replace(':', ',')} 时间:${timeMss}`,
); );
} else { } else {
let content = messContent.replace(/\\n/g, ','); let content = ( _.isObject(messContent) ? messContent.content: messContent).replace(/\\n/g, ',');
content = this.replaceSpeak(content) content = this.replaceSpeak(content)
state = new window.SpeechSynthesisUtterance( state = new window.SpeechSynthesisUtterance(
`您有新的消息:${content `您有新的消息:${content
...@@ -409,12 +414,20 @@ class Notifier { ...@@ -409,12 +414,20 @@ class Notifier {
} }
renderWindowsInfo(message) { renderWindowsInfo(message) {
const self = this;
function notifyMessage(message) { function notifyMessage(message) {
const parseMessage = JSON.parse(message.payloadString); const parseMessage = JSON.parse(message.payloadString);
let content = ''; let content = '';
if(self.getMessageLevel() === "2.0") {
const messageContent = JSON.parse(parseMessage.content);
content += `${messageContent.alarmType} ${messageContent.alarmDevice} ${messageContent.alarmContent} ${messageContent.alarmValue} / ${messageContent.alarmThreshold}`
} else {
for (let i = 0; i < parseMessage.content.split('\\n').length; i++) { for (let i = 0; i < parseMessage.content.split('\\n').length; i++) {
content += `${parseMessage.content.split('\\n')[i]} `; content += `${parseMessage.content.split('\\n')[i]} `;
} }
}
const messageBody = { const messageBody = {
title: '', title: '',
content, content,
...@@ -510,31 +523,42 @@ class Notifier { ...@@ -510,31 +523,42 @@ 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) {
let mqttConfig = {
mqtt_mess: {},
mqtt_path: self._siteConfig.mqtt_path,
nginxStart: self._siteConfig.NginxStart,
mqtt_IsSSL: true
};
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 const data = res.getMe[0];
? res.getMe[0].IsSSL mqttConfig.mqtt_IsSSL = self._siteConfig.IsSSL = data.IsSSL ? data.IsSSL : false;
: false; mqttConfig.mqtt_mess.site_code = self._siteConfig.site_code = data.SiteCode || self._siteConfig.site_code;
self._siteConfig.site_code = mqttConfig.mqtt_mess.TcpIP = self._siteConfig.TcpIP = data.TcpIP;
res.getMe[0].SiteCode || self._siteConfig.site_code; mqttConfig.mqtt_mess.TcpPort = self._siteConfig.TcpPort = data.TcpPort ? parseInt(data.TcpPort) : 8083;
self._siteConfig.TcpIP = res.getMe[0].TcpIP; mqttConfig.mqtt_mess.MessageLevel = self._siteConfig.MessageLevel = data.MessageLevel ? data.MessageLevel : DEFAULT_PARSE_LEVEL;
self._siteConfig.TcpPort = res.getMe[0].TcpPort
? parseInt(res.getMe[0].TcpPort) if (data.NginxStart) {
: 8083; mqttConfig.NginxStart = self._siteConfig.NginxStart = data.NginxStart;
self._siteConfig.MessageLevel = res.getMe[0].MessageLevel mqttConfig.mqtt_mess.TcpIP = self._siteConfig.mqtt_mess.TcpIP = window.location.hostname;
? res.getMe[0].MessageLevel mqttConfig.mqtt_mess.TcpPort = self._siteConfig.mqtt_mess.TcpPort = parseInt(window.location.port);
: DEFAULT_PARSE_LEVEL; mqttConfig.mqtt_path = self._siteConfig.mqtt_path = '/ws/';
}
if (res.getMe[0].NginxStart) {
self._siteConfig.TcpIP = window.location.hostname;
self._siteConfig.TcpPort = parseInt(window.location.port);
self._siteConfig.mqtt_path = '/ws/';
} else { } else {
self._siteConfig.TcpIP = DEFAULT_TCP_IP; mqttConfig.nginxStart = data.NginxStart
self._siteConfig.TcpPort = DEFAULT_TCP_PORT;
self._siteConfig.IsSSL = true;
} }
}else {
mqttConfig.mqtt_mess.TcpIP = self._siteConfig.mqtt_mess.TcpIP = DEFAULT_TCP_IP;
mqttConfig.mqtt_mess.TcpPort = self._siteConfig.mqtt_mess.TcpPort = DEFAULT_TCP_PORT;
mqttConfig.mqtt_IsSSL = self._siteConfig.IsSSL = self._siteConfig.mqtt_mess.TcpIP + ":" + self._siteConfig.mqtt_mess.TcpPort;
}
mqttConfig.mqtt_iotIP = self._siteConfig.mqtt_iotIP = mqttConfig.mqtt_mess.TcpIP + ":" + mqttConfig.mqtt_mess.TcpPort;
self.props.updateConfig && self.props.updateConfig(Object.assign({}, self.props.global, {
...mqttConfig
}))
} }
} else { } else {
logger.info('获取mqtt服务器参数失败'); logger.info('获取mqtt服务器参数失败');
...@@ -542,7 +566,9 @@ class Notifier { ...@@ -542,7 +566,9 @@ class Notifier {
}, },
); );
} }
getMessageLevel() {
return this._siteConfig.MessageLevel
}
generatedId() { generatedId() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.replace(/[xy]/g, function(c) { .replace(/[xy]/g, function(c) {
...@@ -554,7 +580,7 @@ class Notifier { ...@@ -554,7 +580,7 @@ class Notifier {
} }
getMessageType(messageType) { getMessageType(messageType) {
let infoType = MESSAGE_TYPE.UNKNOWN; let infoType = MESSAGE_TYPE.SCADA_TYPE;
switch (messageType) { switch (messageType) {
case MESSAGE_TEXT_TYPE.PROJECT_FLOW: case MESSAGE_TEXT_TYPE.PROJECT_FLOW:
infoType = MESSAGE_TYPE.CASE_TYPE; infoType = MESSAGE_TYPE.CASE_TYPE;
...@@ -572,9 +598,6 @@ class Notifier { ...@@ -572,9 +598,6 @@ class Notifier {
case MESSAGE_TEXT_TYPE.MESSAGE_ALERT: case MESSAGE_TEXT_TYPE.MESSAGE_ALERT:
infoType = MESSAGE_TYPE.MESSAGE_ALERT; infoType = MESSAGE_TYPE.MESSAGE_ALERT;
break; break;
case MESSAGE_TEXT_TYPE.SCADA_ALARM:
case '':
infoType = MESSAGE_TYPE.SCADA_TYPE;
default: default:
break; break;
} }
......
...@@ -30,12 +30,11 @@ export default function configureStore(initialState = {}, history) { ...@@ -30,12 +30,11 @@ export default function configureStore(initialState = {}, history) {
const sagaMiddleware = createSagaMiddleware(reduxSagaMonitorOptions); const sagaMiddleware = createSagaMiddleware(reduxSagaMonitorOptions);
const middlewares = [ const middlewares = [sagaMiddleware, routerMiddleware(history), thunk];
sagaMiddleware,
routerMiddleware(history), if (process.env.NODE_ENV !== 'production' && typeof window === 'object') {
logger, middlewares.push(logger);
thunk, }
];
const enhancers = [applyMiddleware(...middlewares)]; const enhancers = [applyMiddleware(...middlewares)];
......
...@@ -66,12 +66,21 @@ export const initialState = fromJS({ ...@@ -66,12 +66,21 @@ export const initialState = fromJS({
const appReducer = (state = initialState, action) => { const appReducer = (state = initialState, action) => {
switch (action.type) { switch (action.type) {
case GET_CONFIG: case GET_CONFIG:
// eslint-disable-next-line no-debugger
debugger
// eslint-disable-next-line no-underscore-dangle // eslint-disable-next-line no-underscore-dangle
window.__INITIAL_STATE__ = Object.assign({}, action.data, { window.__INITIAL_STATE__ = Object.assign({}, action.data, {
allWidgets: action.data.widgets || [], allWidgets: action.data.widgets || [],
}); });
// eslint-disable-next-line global-require
if (!window.globalConfig) {
// eslint-disable-next-line global-require // eslint-disable-next-line global-require
window.globalConfig = require('kit_global_config').default; window.globalConfig = require('kit_global_config').default;
} else {
// eslint-disable-next-line no-underscore-dangle
window.globalConfig = window.__INITIAL_STATE__;
}
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
createStoreage.set('globalConfig', window.globalConfig); createStoreage.set('globalConfig', window.globalConfig);
// eslint-disable-next-line no-undef,no-case-declarations // eslint-disable-next-line no-undef,no-case-declarations
......
...@@ -113,3 +113,17 @@ export function findPathByWidget(leafId, nodes, path, key) { ...@@ -113,3 +113,17 @@ export function findPathByWidget(leafId, nodes, path, key) {
} }
return tmpPath; return tmpPath;
} }
export function isJSON(str) {
if (typeof str === 'string') {
try {
const obj = JSON.parse(str);
if (typeof obj === 'object' && obj) {
return true;
}
return false;
} catch (e) {
return false;
}
}
}
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