NoticeIconView.js 14.6 KB
Newer Older
dengxiaofeng's avatar
dengxiaofeng committed
1
import React, { Component } from 'react';
邓晓峰's avatar
邓晓峰 committed
2

3
import { Button, Form, Input, Modal } from 'antd';
dengxiaofeng's avatar
dengxiaofeng committed
4
import { connect } from 'react-redux';
5 6 7 8 9

import { FormattedMessage } from '@/locales/localeExports';

import service from '../../api/service/notification';
import { actionCreators } from '../../containers/App/store';
邓晓峰's avatar
邓晓峰 committed
10
import isProd from '../../utils/env';
11
import { findPathByWidget, isJSON } from '../../utils/utils';
dengxiaofeng's avatar
dengxiaofeng committed
12
import NoticeIcon from '../NoticeIcon';
邓晓峰's avatar
邓晓峰 committed
13
import Notifier from '../Notifier';
14
import { ERR_OK, MESSAGE_TYPE, NEW_MESSAGE } from '../Notifier/constants';
dengxiaofeng's avatar
dengxiaofeng committed
15
import styles from './index.less';
16 17 18

const { TextArea } = Input;
/* eslint-disable */
dengxiaofeng's avatar
dengxiaofeng committed
19
class NoticeIconView extends Component {
邓晓峰's avatar
邓晓峰 committed
20
  constructor(props) {
叶飞's avatar
叶飞 committed
21 22 23 24
    super(props);
    this.state = {
      count: 0,
      noticeData: [],
25
      platformVisible: false,
邓晓峰's avatar
邓晓峰 committed
26
      videoVisible: false,
邓晓峰's avatar
邓晓峰 committed
27
      // eslint-disable-next-line react/no-unused-state
邓晓峰's avatar
邓晓峰 committed
28
      noticeVisible: false,
邓晓峰's avatar
邓晓峰 committed
29
      // eslint-disable-next-line react/no-unused-state
邓晓峰's avatar
邓晓峰 committed
30
      renderVideo: null,
邓晓峰's avatar
邓晓峰 committed
31 32
      // eslint-disable-next-line react/no-unused-state
      initVisible: false,
33
      sysTopVisible: false,
邓晓峰's avatar
邓晓峰 committed
34 35 36
      sysMessage: {},
      alarmMessage: {},
      videoMessage: {},
叶飞's avatar
叶飞 committed
37
    };
邓晓峰's avatar
邓晓峰 committed
38 39 40 41 42
    // this.renderPlatform
    this.notifier = new Notifier(
      this.props.global.userInfo,
      this.renderVideo,
      this.renderPlatform,
43
      this.renderSysPlatform,
邓晓峰's avatar
邓晓峰 committed
44
      this.props,
邓晓峰's avatar
邓晓峰 committed
45
    );
叶飞's avatar
叶飞 committed
46 47
  }

叶飞's avatar
叶飞 committed
48
  async componentDidMount() {
邓晓峰's avatar
邓晓峰 committed
49
    this.notifier.subscribe(NEW_MESSAGE, this.onNewMessage.bind(this));
叶飞's avatar
叶飞 committed
50 51
    this.notifier.start();
  }
叶飞's avatar
叶飞 committed
52

邓晓峰's avatar
邓晓峰 committed
53
  componentWillUnmount() {
邓晓峰's avatar
邓晓峰 committed
54
    try {
邓晓峰's avatar
邓晓峰 committed
55
      // eslint-disable-next-line no-unused-expressions
邓晓峰's avatar
邓晓峰 committed
56
      this.notifier && this.notifier.stop();
邓晓峰's avatar
邓晓峰 committed
57 58 59
    } catch (error) {
      // eslint-disable-next-line no-empty
    } finally {
邓晓峰's avatar
邓晓峰 committed
60
    }
邓晓峰's avatar
邓晓峰 committed
61
  }
dengxiaofeng's avatar
dengxiaofeng committed
62

叶飞's avatar
叶飞 committed
63 64
  onNewMessage = messages => {
    this.setState({
邓晓峰's avatar
邓晓峰 committed
65 66
      count: messages.totalCount,
      noticeData: messages.messages,
邓晓峰's avatar
邓晓峰 committed
67
    });
叶飞's avatar
叶飞 committed
68 69
  };

邓晓峰's avatar
邓晓峰 committed
70
  modalVisible = () => {
邓晓峰's avatar
邓晓峰 committed
71
    const data = this.state.noticeData.filter(item => item.infoLevel === '4');
邓晓峰's avatar
邓晓峰 committed
72

邓晓峰's avatar
邓晓峰 committed
73 74
    return data.length > 0;
  };
邓晓峰's avatar
邓晓峰 committed
75 76

  handleCloseVideo = () => {
邓晓峰's avatar
邓晓峰 committed
77 78 79
    this.setState({ videoVisible: false });
    this.notifier.destoryVideo();
  };
邓晓峰's avatar
邓晓峰 committed
80

邓晓峰's avatar
邓晓峰 committed
81 82 83 84
  handleClosePlatform = event => {
    this.setState({ platformVisible: false });
    this.notifier.destoryPlatform();
  };
邓晓峰's avatar
邓晓峰 committed
85

邓晓峰's avatar
邓晓峰 committed
86
  renderPlatform = message => {
87 88 89 90 91
    const messageContent =
      this.props.global.mqtt_mess.MessageLevel === '2.0' &&
      isJSON(message.infoContent)
        ? JSON.parse(message.infoContent)
        : message.infoContent;
邓晓峰's avatar
邓晓峰 committed
92

邓晓峰's avatar
邓晓峰 committed
93
    this.setState({
邓晓峰's avatar
邓晓峰 committed
94
      platformVisible: true,
邓晓峰's avatar
邓晓峰 committed
95 96 97 98
      alarmMessage: {
        message,
        messageContent,
      },
邓晓峰's avatar
邓晓峰 committed
99 100 101 102
    });
  };

  renderVideo = message => {
邓晓峰's avatar
邓晓峰 committed
103
    this.setState({
邓晓峰's avatar
邓晓峰 committed
104
      videoVisible: true,
邓晓峰's avatar
邓晓峰 committed
105
    });
邓晓峰's avatar
邓晓峰 committed
106
    const { props } = this;
邓晓峰's avatar
邓晓峰 committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    const infoType = message.infoType
      ? 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');
    }

邓晓峰's avatar
邓晓峰 committed
123 124
    const id = data[3];
    const name = data[0];
邓晓峰's avatar
邓晓峰 committed
125 126 127 128 129 130
    const baseURI = isProd
      ? window.location.origin
      : `http://${window.location.hostname}:3020`;
    const url = `${baseURI}/civweb4/video/indexAll.html?ID=${id}&name=${name}&site=${
      props.global.userInfo.site
    }`;
邓晓峰's avatar
邓晓峰 committed
131 132 133 134 135 136 137 138

    this.setState({
      // eslint-disable-next-line react/no-unused-state
      videoMessage: {
        name,
        url,
      },
    });
邓晓峰's avatar
邓晓峰 committed
139
  };
邓晓峰's avatar
邓晓峰 committed
140 141 142

  handlerOptions = value => {
    // eslint-disable-next-line no-undef
邓晓峰's avatar
邓晓峰 committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    service
      .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,
          });
        }
      });
邓晓峰's avatar
邓晓峰 committed
160 161
  };

162 163
  renderSysPlatform = message => {
    const noticeContent =
邓晓峰's avatar
邓晓峰 committed
164 165
      this.props.global.mqtt_mess.MessageLevel === '2.0' &&
      isJSON(message.infoContent)
166 167 168 169 170
        ? JSON.parse(message.infoContent)
        : message.infoContent;
    this.setState({
      sysTopVisible: true,
      platformVisible: false,
邓晓峰's avatar
邓晓峰 committed
171 172 173 174 175
      videoVisible: false,
      sysMessage: {
        message,
        noticeContent,
      },
176
    });
邓晓峰's avatar
邓晓峰 committed
177
  };
邓晓峰's avatar
邓晓峰 committed
178

邓晓峰's avatar
邓晓峰 committed
179 180
  handlerMointer = (event, item, detail) => {
    event.stopPropagation();
邓晓峰's avatar
邓晓峰 committed
181
    this.notifier.confirmRead(false, [item.id]);
邓晓峰's avatar
邓晓峰 committed
182 183
    if (detail) {
      const widgetID = 'widget_city_综合运营_管网监控_实时监控_报警监控';
邓晓峰's avatar
邓晓峰 committed
184
      const webPath = 'product/scada/AlertMonitoring/AlertMonitoring';
邓晓峰's avatar
邓晓峰 committed
185 186 187 188 189 190
      const widget = findPathByWidget(
        'productex/water/IOTMonitor/RealTimeAlarm/RealTimeAlarm',
        this.props.global.widgets,
        '',
        'url',
      );
邓晓峰's avatar
邓晓峰 committed
191
      window.share.event.emit('listenerMointer', {
邓晓峰's avatar
邓晓峰 committed
192
        widgetId: widgetID,
邓晓峰's avatar
邓晓峰 committed
193
        label: '实时报警',
邓晓峰's avatar
邓晓峰 committed
194
        url: widget.url || webPath,
邓晓峰's avatar
邓晓峰 committed
195 196
      });
    }
邓晓峰's avatar
邓晓峰 committed
197
    this.setState({
邓晓峰's avatar
邓晓峰 committed
198 199 200
      platformVisible: false,
    });
  };
邓晓峰's avatar
邓晓峰 committed
201

邓晓峰's avatar
邓晓峰 committed
202
  handlerSysDetail = message => {
邓晓峰's avatar
邓晓峰 committed
203
    this.setState({
邓晓峰's avatar
邓晓峰 committed
204
      sysTopVisible: true,
邓晓峰's avatar
邓晓峰 committed
205
    });
邓晓峰's avatar
邓晓峰 committed
206
    this.renderSysPlatform(message);
邓晓峰's avatar
邓晓峰 committed
207
  };
邓晓峰's avatar
邓晓峰 committed
208

dengxiaofeng's avatar
dengxiaofeng committed
209 210
  render() {
    return (
邓晓峰's avatar
邓晓峰 committed
211 212 213 214
      <>
        <NoticeIcon
          className={styles.action}
          count={this.state.count}
叶飞's avatar
叶飞 committed
215
          confirmRead={this.notifier.confirmRead}
邓晓峰's avatar
邓晓峰 committed
216 217 218
        >
          <NoticeIcon.Tab
            list={this.state.noticeData}
219
            title={<FormattedMessage id='component.noticeIcon.title'/>}
邓晓峰's avatar
邓晓峰 committed
220
            emptyText={<FormattedMessage id='component.noticeIcon.allClear'/>}
邓晓峰's avatar
邓晓峰 committed
221
            confirmRead={this.notifier.confirmRead}
邓晓峰's avatar
邓晓峰 committed
222
            handlerSysDetail={this.handlerSysDetail}
邓晓峰's avatar
邓晓峰 committed
223
            loadMore={this.notifier.loadMore}
邓晓峰's avatar
邓晓峰 committed
224
            hasMore={this.notifier.hasMore}
邓晓峰's avatar
邓晓峰 committed
225 226
          />
        </NoticeIcon>
邓晓峰's avatar
邓晓峰 committed
227 228
        {this.state.platformVisible && this.state.alarmMessage && (
          <Modal
229
            title={<FormattedMessage id='component.noticeIcon.modal.alarm.title'/>}
邓晓峰's avatar
邓晓峰 committed
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
            visible={this.state.platformVisible}
            zIndex={5000}
            className={styles.platformModal}
            footer={null}
            onCancel={() => this.handleClosePlatform()}
            centered
          >
            <div className={styles.alarmContent}>
              {/* eslint-disable-next-line jsx-a11y/alt-text */}
              <img
                src="https://panda-water.com/web4/assets/images/message/报警图标.svg"
                alt=""
              />
              <div className={styles.content}>
                <div className={styles['content-top']}>
                  <a
邓晓峰's avatar
邓晓峰 committed
246 247 248 249 250 251
                    onClick={event =>
                      this.handlerMointer(
                        event,
                        this.state.alarmMessage.message,
                        true,
                      )
邓晓峰's avatar
邓晓峰 committed
252 253 254 255 256 257 258
                    }
                  >
                    {this.state.alarmMessage &&
                      this.state.alarmMessage.messageContent &&
                      this.state.alarmMessage.messageContent.title}
                  </a>
                  <span
259
                    title={<FormattedMessage id='component.noticeIcon.messsage.statused'/>}
邓晓峰's avatar
邓晓峰 committed
260
                    onClick={event =>
邓晓峰's avatar
邓晓峰 committed
261
                      this.handlerMointer(
邓晓峰's avatar
邓晓峰 committed
262
                        event,
邓晓峰's avatar
邓晓峰 committed
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
                        this.state.alarmMessage.message,
                        false,
                      )
                    }
                  />
                </div>

                <div className={styles['content-mid']}>
                  <b>
                    {this.state.alarmMessage &&
                      this.state.alarmMessage.messageContent &&
                      this.state.alarmMessage.messageContent.alarmType}
                  </b>
                  {`|${this.state.alarmMessage &&
                    this.state.alarmMessage.messageContent &&
                    this.state.alarmMessage.messageContent.alarmContent}`}
                </div>
                <div className={styles['content-bottom']}>
                  <p>
                    <b>
                      {this.state.alarmMessage &&
                        this.state.alarmMessage.messageContent &&
                        this.state.alarmMessage.messageContent.alarmValue}
                      /
                    </b>
                    {this.state.alarmMessage &&
                      this.state.alarmMessage.messageContent &&
                      this.state.alarmMessage.messageContent.alarmThreshold}
                  </p>
292 293 294 295 296
                  <span>
                    {this.state.alarmMessage &&
                      this.state.alarmMessage.message &&
                      this.state.alarmMessage.message.time}
                  </span>
邓晓峰's avatar
邓晓峰 committed
297 298 299 300 301
                </div>
              </div>
            </div>
          </Modal>
        )}
邓晓峰's avatar
邓晓峰 committed
302

303
        {this.state.videoVisible && this.state.videoMessage && (
邓晓峰's avatar
邓晓峰 committed
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
          <Modal
            visible={this.state.videoVisible}
            title={this.state.videoMessage.name}
            footer={null}
            centered
            width="50%"
            zIndex={1500}
            ref={videoRef => (this.videoRef = videoRef)}
            className={styles.videoPopup}
            onCancel={() => this.handleCloseVideo()}
          >
            <div className="web4_console_component">
              {/* eslint-disable-next-line jsx-a11y/iframe-has-title */}
              <iframe
                id="videoIframe"
                style={{ width: '100%', height: '100%' }}
                frameBorder="0"
                src={this.state.videoMessage.url}
              />
            </div>
          </Modal>
        )}
326

327
        {this.state.sysTopVisible && this.state.sysMessage && !this.props.global.isNewYear && (
邓晓峰's avatar
邓晓峰 committed
328
          <Modal
329
            title={<FormattedMessage id='component.noticeIcon.model.system.title'/>}
邓晓峰's avatar
邓晓峰 committed
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
            visible
            zIndex={8000}
            className={styles.noticeModal}
            onCancel={() => this.setState({ sysTopVisible: false })}
            footer={null}
            centered
          >
            <div className={styles.alarmContent}>
              <div className={styles.title}>
                {this.state.sysMessage.noticeContent.noticeTitle}
              </div>
              <div
                className={styles.content}
                dangerouslySetInnerHTML={{
                  __html: this.state.sysMessage.noticeContent.noticeContent,
                }}
              />
              <div className={styles.time}>
                {this.state.sysMessage.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>
        )}
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429

        {this.state.sysTopVisible &&
          this.state.sysMessage &&
          this.props.global.isNewYear && (
            <Modal
              visible
              zIndex={9000}
              footer={null}
              centered
              className={styles.newYearMessage}
              width={876}
            >
            <div className={styles['topPopup-body']}>
              <div className={styles['topPopup-title']}>
                <img src="https://panda-water.com/web4/assets/images/message/%E5%85%B3%E9%97%AD%E6%8C%89%E9%92%AE.png" onClick={() => this.setState({ sysTopVisible: false })}/>
                <div className={styles['newYearTitle']}>
                  <img src="https://panda-water.com/web4/assets/images/message/%E7%83%9F%E8%8A%B1%E5%B7%A6.png"/>
                  <span title={this.state.sysMessage.noticeContent.noticeTitle}>{this.state.sysMessage.noticeContent.noticeTitle}</span>
                  <img src="https://panda-water.com/web4/assets/images/message/%E7%83%9F%E8%8A%B1%E5%8F%B3.png"/>
                </div>
              </div>
              <div className={styles['topPopup-content']}>
                <div className={styles['content']}>
                  <div className={styles['content-mid']}  dangerouslySetInnerHTML={{
                    __html: this.state.sysMessage.noticeContent.noticeContent,
                  }}></div>
                  <div className={styles['content-bottom']}>
                    <span className={styles['message-time']}>{this.state.sysMessage.message.time}</span>
                  </div>
                </div>
              </div>
              <div className={styles['feedbackBox']}>
                <Form layout="vertical" onFinish={this.handlerOptions}>
                  <div className={styles['question']}>您还有其他建议和反馈吗?</div>
                  <Form.Item
                    name="content"
                    rules={[{ required: true, message: '请填写反馈内容' }]}
                  >
                    <TextArea placeholder="请输入您的建议和反馈" rows={3}/>
                  </Form.Item>
                  <div className={styles['question']}>
                    请填写您的联系方式,以便我们及时与您沟通!
                  </div>
                  <div className={styles['horiztion']}>
                    <Form.Item name="phone">
                      <Input autoComplete='off' placeholder="请输入您的邮箱或者电话号码"/>
                    </Form.Item>
                    <Form.Item>
                      <Button htmlType="submit" type="primary"> </Button>
                    </Form.Item>
                  </div>

                </Form>
              </div>
            </div>
          </Modal>
        )}
邓晓峰's avatar
邓晓峰 committed
430
      </>
dengxiaofeng's avatar
dengxiaofeng committed
431 432 433 434
    );
  }
}

邓晓峰's avatar
邓晓峰 committed
435 436 437
const mapStateToProps = state => ({
  global: state.getIn(['global', 'globalConfig']),
});
叶飞's avatar
叶飞 committed
438

邓晓峰's avatar
邓晓峰 committed
439 440 441 442 443
const mapDispatchToProps = dispatch => ({
  updateConfig(config) {
    dispatch(actionCreators.getConfig(config));
  },
});
邓晓峰's avatar
邓晓峰 committed
444

邓晓峰's avatar
邓晓峰 committed
445 446
export default connect(
  mapStateToProps,
邓晓峰's avatar
邓晓峰 committed
447
  mapDispatchToProps,
邓晓峰's avatar
邓晓峰 committed
448
)(NoticeIconView);