Commit 2e9397bd authored by 邓晓峰's avatar 邓晓峰

feat: add systemMessage push

parent 13b2d66a
Pipeline #21633 passed with stages
in 14 minutes 51 seconds
...@@ -7,6 +7,8 @@ const API = { ...@@ -7,6 +7,8 @@ const API = {
'/CityInterface/rest/services/CountyProduct.svc/SCADAOper/getMqttSitecode', '/CityInterface/rest/services/CountyProduct.svc/SCADAOper/getMqttSitecode',
POST_INFORMATION_STATUS: POST_INFORMATION_STATUS:
'/CityInterface/rest/services/CountyProduct.svc/SCADAOper/PostInformationStatus', '/CityInterface/rest/services/CountyProduct.svc/SCADAOper/PostInformationStatus',
POST_ADD_OPTIONS:
'/CityInterface/rest/services/WisdomUnion.svc/CustomerManage/AddOption',
}; };
/* eslint-disable */ /* eslint-disable */
export default vm => { export default vm => {
...@@ -22,4 +24,8 @@ export default vm => { ...@@ -22,4 +24,8 @@ export default vm => {
.post(`${API.POST_INFORMATION_STATUS}?${paramsStr}`) .post(`${API.POST_INFORMATION_STATUS}?${paramsStr}`)
.then(res => Promise.resolve(res)); .then(res => Promise.resolve(res));
}; };
vm.postAddOptions = (params = {}) => {
return vm.post(API.POST_ADD_OPTIONS, params).then(res => Promise.resolve(res))
}
}; };
...@@ -2,11 +2,11 @@ import React, { Component } from 'react'; ...@@ -2,11 +2,11 @@ import React, { Component } from 'react';
import { Modal } from 'antd'; import { Modal } from 'antd';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Form, Input, Button } from 'antd';
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 { MESSAGE_TYPE, NEW_MESSAGE } from '../Notifier/constants'; import { ERR_OK, MESSAGE_TYPE, NEW_MESSAGE } from '../Notifier/constants';
import styles from './index.less'; import styles from './index.less';
import { findPathByWidget, isJSON } from '../../utils/utils'; import { findPathByWidget, isJSON } from '../../utils/utils';
import { actionCreators } from '../../containers/App/store'; import { actionCreators } from '../../containers/App/store';
...@@ -25,12 +25,14 @@ class NoticeIconView extends Component { ...@@ -25,12 +25,14 @@ class NoticeIconView extends Component {
renderVideo: null, renderVideo: null,
// eslint-disable-next-line react/no-unused-state // eslint-disable-next-line react/no-unused-state
initVisible: false, initVisible: false,
sysTopVisible: false,
}; };
// this.renderPlatform // this.renderPlatform
this.notifier = new Notifier( this.notifier = new Notifier(
this.props.global.userInfo, this.props.global.userInfo,
this.renderVideo, this.renderVideo,
this.renderPlatform, this.renderPlatform,
this.renderSysPlatform,
this.props, this.props,
); );
} }
...@@ -74,7 +76,11 @@ class NoticeIconView extends Component { ...@@ -74,7 +76,11 @@ 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; 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,
}); });
...@@ -177,6 +183,66 @@ class NoticeIconView extends Component { ...@@ -177,6 +183,66 @@ class NoticeIconView extends Component {
</Modal> </Modal>
); );
}; };
handlerOptions = (value) => {
Http.postAddOptions({
UserName: this.props.global.userInfo.fullName,
Type: "其他问题",
System: "熊猫智联",
Content: value.content,
Phone: value.phone,
UserID: this.props.global.userInfo.OID,
Picture: ''
}).then(res => {
if(res.statusCode === ERR_OK) {
this.setState({
sysTopVisible: false
})
}
})
}
renderSysPlatform = message => {
console.log("renderSysPlatform", message);
const noticeContent =
this.props.global.mqtt_mess.MessageLevel === '2.0' && isJSON(message.infoContent)
? JSON.parse(message.infoContent)
: message.infoContent;
this.setState({
sysTopVisible: true,
platformVisible: false,
videoVisible: false
});
return (
<Modal
title="系统通知"
visible={this.state.sysTopVisible}
zIndex={8000}
className={styles.noticeModal}
onCancel={() => this.setState({sysTopVisible: false})}
footer={null}
centered
>
<div className={styles.alarmContent}>
<div className={styles.title}>{noticeContent.noticeTitle}</div>
<div className={styles.content} dangerouslySetInnerHTML={{ __html: noticeContent.noticeContent }}/>
<div className={styles.time}>{message.time}</div>
<Form formLayout="vertical" onFinish={this.handlerOptions}>
<div>1、您还有其他建议和反馈吗?</div>
<Form.Item name="content" rules={[{ required: true, message: '请填写反馈内容' }]}>
<Input/>
</Form.Item>
<div>2、怎么联系您(您填写了建议和反馈,也请帮忙填写下您的联系方式,以便我们有不清楚的问题时,能与您联系沟通)</div>
<Form.Item name="phone">
<Input />
</Form.Item>
<Form.Item>
<Button htmlType="submit" type="primary">提交</Button>
</Form.Item>
</Form>
</div>
</Modal>
)
}
handlerMointer = (item, detail) => { handlerMointer = (item, detail) => {
this.notifier.confirmRead(false, [item.id]); this.notifier.confirmRead(false, [item.id]);
...@@ -225,6 +291,10 @@ class NoticeIconView extends Component { ...@@ -225,6 +291,10 @@ class NoticeIconView extends Component {
} }
{this.state.videoVisible ? this.notifier.renderVideoElement : null} {this.state.videoVisible ? this.notifier.renderVideoElement : null}
{
this.state.sysTopVisible ? this.notifier.renderSysElement: null
}
</> </>
); );
} }
......
...@@ -265,7 +265,7 @@ ...@@ -265,7 +265,7 @@
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
white-space: nowrap; white-space: nowrap;
width: 80%; width: 60%;
} }
span { span {
width: 18px; width: 18px;
...@@ -385,3 +385,51 @@ ...@@ -385,3 +385,51 @@
height: 28px; height: 28px;
} }
} }
.noticeModal {
:global {
.@{ant-prefix}-modal-body {
padding: 10px 24px;
b {
float: right;
text-align: right;
display: block;
&:last-child {
float: inherit;
}
}
.@{ant-prefix}-form-item {
margin-bottom: 20px;
padding-top: 4px;
}
.@{ant-prefix}-form-item {
&:last-child {
text-align: center;
}
}
}
}
:global(.@{ant-prefix}-modal-header) {
padding: 10px 24px !important;
}
:global(.@{ant-prefix}-modal-close .@{ant-prefix}-modal-close-x) {
width: 45px;
height: 45px;
font-size: 12px;
line-height: 35px;
}
.title {
font-size: 20px;
font-weight: bold;
}
.content {
text-indent: 24px;
padding-top: 4px;
}
.time {
display: block;
font-weight: 500;
font-size: 16px;
text-align: right;
}
}
...@@ -124,7 +124,7 @@ class NoticeList extends React.Component { ...@@ -124,7 +124,7 @@ class NoticeList extends React.Component {
break; break;
case 'sysType': case 'sysType':
messageTemplate = ( messageTemplate = (
<Notice message={item} confirmRead={this.confirmRead} /> <Notice message={item} confirmRead={this.confirmRead} config={this.props.config}/>
); );
break; break;
default: default:
......
...@@ -4,6 +4,7 @@ import classNames from 'classnames'; ...@@ -4,6 +4,7 @@ import classNames from 'classnames';
import commonStyles from '../common.less'; import commonStyles from '../common.less';
import styles from './index.less'; import styles from './index.less';
import { isJSON } from '../../../../utils/utils';
export class NoticeContent { export class NoticeContent {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
...@@ -15,22 +16,15 @@ export class NoticeContent { ...@@ -15,22 +16,15 @@ export class NoticeContent {
} }
} }
const Notice = ({ message, confirmRead }) => { const Notice = ({ message, confirmRead, config }) => {
// eslint-disable-next-line no-debugger // eslint-disable-next-line no-debugger
debugger const noticeContent =
const noticeContent = message.infoContent; config.mqtt_mess.MessageLevel === '2.0' && isJSON(message.infoContent)
? JSON.parse(message.infoContent)
: message.infoContent;
const goPath = item => { const goPath = item => {
// eslint-disable-next-line no-debugger // eslint-disable-next-line no-debugger
debugger
confirmRead(false, [message.id]); confirmRead(false, [message.id]);
const webPath =
item.webPath || 'product/notification/HistoryNotice/HistoryNotice';
window.share.event.emit('listenerMointer', {
// eslint-disable-next-line no-undef
widgetId: widgetID,
label: '系统公告',
url: webPath,
});
}; };
return ( return (
<div <div
...@@ -55,7 +49,7 @@ const Notice = ({ message, confirmRead }) => { ...@@ -55,7 +49,7 @@ const Notice = ({ message, confirmRead }) => {
<i>{noticeContent.noticeType}</i> <i>{noticeContent.noticeType}</i>
{noticeContent.noticeTitle} {noticeContent.noticeTitle}
</p> </p>
<p>{noticeContent.noticeContent}</p> <p dangerouslySetInnerHTML={{ __html: noticeContent.noticeContent }}></p>
<p className={commonStyles.messageTime}>{message.time}</p> <p className={commonStyles.messageTime}>{message.time}</p>
</div> </div>
</div> </div>
......
...@@ -33,6 +33,7 @@ export const USERNAME = 'mao2080'; ...@@ -33,6 +33,7 @@ export const USERNAME = 'mao2080';
export const PASSWORD = '123'; export const PASSWORD = '123';
export const PLATFORM_LEVEL = '4'; export const PLATFORM_LEVEL = '4';
export const VIDEO_LEVEL = '5'; export const VIDEO_LEVEL = '5';
export const SYS_LEVEL = '6';
export const ERR_OK = '0000'; export const ERR_OK = '0000';
export const DEFAULT_TCP_PORT = 443; export const DEFAULT_TCP_PORT = 443;
export const DEFAULT_TCP_IP = 'emqttd.panda-water.cn'; export const DEFAULT_TCP_IP = 'emqttd.panda-water.cn';
......
...@@ -16,7 +16,7 @@ import { ...@@ -16,7 +16,7 @@ import {
NEW_MESSAGE, NEW_MESSAGE,
PASSWORD, PASSWORD,
PLATFORM_LEVEL, PLATFORM_LEVEL,
REQUEST_SERVICE, REQUEST_SERVICE, SYS_LEVEL,
USERNAME, USERNAME,
VIDEO_LEVEL, VIDEO_LEVEL,
} from './constants'; } from './constants';
...@@ -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, props) { constructor(userInfo, renderVideo, renderPlatform, renderSysPlatform, props) {
this.userInfo = userInfo; this.userInfo = userInfo;
this.messageCache = { this.messageCache = {
totalCount: 0, totalCount: 0,
...@@ -70,6 +70,8 @@ class Notifier { ...@@ -70,6 +70,8 @@ class Notifier {
this.renderVideoElement = null; this.renderVideoElement = null;
this.renderPlatform = renderPlatform; this.renderPlatform = renderPlatform;
this.renderPlatformElement = null; this.renderPlatformElement = null;
this.renderSysPlatform = renderSysPlatform;
this.renderSysElement = null;
this.props = props; this.props = props;
} }
...@@ -276,6 +278,7 @@ class Notifier { ...@@ -276,6 +278,7 @@ class Notifier {
onMessageArrived(buffer) { onMessageArrived(buffer) {
try { try {
const parseMessage = JSON.parse(buffer.payloadString); const parseMessage = JSON.parse(buffer.payloadString);
const userInfo = this.getUserInfo(); const userInfo = this.getUserInfo();
const infoType = this.getMessageType(parseMessage.infoType); const infoType = this.getMessageType(parseMessage.infoType);
...@@ -351,7 +354,12 @@ class Notifier { ...@@ -351,7 +354,12 @@ class Notifier {
} }
const message = createMessage(messString); const message = createMessage(messString);
this.messageCache.totalCount += 1; this.messageCache.totalCount += 1;
if(message.infoLevel === SYS_LEVEL) {
this.messageCache.messages.unshift(message)
} else {
this.messageCache.messages.push(message); this.messageCache.messages.push(message);
}
this.publish(NEW_MESSAGE, this.messageCache); this.publish(NEW_MESSAGE, this.messageCache);
if ( if (
messString.infoLevel === PLATFORM_LEVEL && messString.infoLevel === PLATFORM_LEVEL &&
...@@ -366,6 +374,8 @@ class Notifier { ...@@ -366,6 +374,8 @@ class Notifier {
window.speechSynthesis.speak(state); window.speechSynthesis.speak(state);
} else if (message.infoLevel === PLATFORM_LEVEL) { } else if (message.infoLevel === PLATFORM_LEVEL) {
console.log(messString); console.log(messString);
} else if(message.infoLevel === SYS_LEVEL) {
this.renderSysNoticePlatform(Object.assign(message, { messContent }))
} else { } else {
state.lang = 'zh'; state.lang = 'zh';
state.rate = 1; state.rate = 1;
...@@ -417,16 +427,20 @@ class Notifier { ...@@ -417,16 +427,20 @@ class Notifier {
const self = this; 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(message.level !== SYS_LEVEL) {
if(self.getMessageLevel() === "2.0") { if(self.getMessageLevel() === "2.0") {
if(message.level === "4") {
const messageContent = JSON.parse(parseMessage.content); const messageContent = JSON.parse(parseMessage.content);
content += `${messageContent.alarmType} ${messageContent.alarmDevice} ${messageContent.alarmContent} ${messageContent.alarmValue} / ${messageContent.alarmThreshold}` content += `${messageContent.alarmType} ${messageContent.alarmDevice} ${messageContent.alarmContent} ${messageContent.alarmValue} / ${messageContent.alarmThreshold}`
}
} else { } 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: '',
...@@ -438,7 +452,7 @@ class Notifier { ...@@ -438,7 +452,7 @@ class Notifier {
} else { } else {
messageBody.title = '新通知:'; messageBody.title = '新通知:';
} }
if(content !== "") {
if (!('Notification' in window)) { if (!('Notification' in window)) {
message.warn('This browser does not support desktop notification'); message.warn('This browser does not support desktop notification');
} else if (Notification.permission === 'granted') { } else if (Notification.permission === 'granted') {
...@@ -464,6 +478,8 @@ class Notifier { ...@@ -464,6 +478,8 @@ class Notifier {
}); });
} }
} }
}
notifyMessage(message); notifyMessage(message);
} }
...@@ -472,6 +488,10 @@ class Notifier { ...@@ -472,6 +488,10 @@ class Notifier {
this.renderPlatform && this.renderPlatform(message); this.renderPlatform && this.renderPlatform(message);
} }
renderSysNoticePlatform(message) {
this.renderSysElement = this.renderSysPlatform && this.renderSysPlatform(message)
}
renderPopVideo(message) { renderPopVideo(message) {
this.renderVideoElement = this.renderVideo && this.renderVideo(message); this.renderVideoElement = this.renderVideo && this.renderVideo(message);
} }
......
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