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

3
import { Button, Form, Input, Modal, notification } from 'antd';
dengxiaofeng's avatar
dengxiaofeng committed
4
import { connect } from 'react-redux';
邓晓峰's avatar
邓晓峰 committed
5 6 7
import { Notifier, NoticeIcon, FormattedMessage } from '@wisdom-utils/components';
import { ERR_OK, MESSAGE_TYPE, NEW_MESSAGE } from '@wisdom-utils/components/lib/AppLayout/notifier/constants';
import { findPathByWidget, isJSON } from '@wisdom-utils/components/lib/AppLayout/helpers';
8 9
import service from '../../api/service/notification';
import { actionCreators } from '../../containers/App/store';
邓晓峰's avatar
邓晓峰 committed
10
import isProd from '../../utils/env';
邓晓峰's avatar
邓晓峰 committed
11
// import NoticeIcon from '../NoticeIcon';
dengxiaofeng's avatar
dengxiaofeng committed
12
import styles from './index.less';
13
import { history } from '@wisdom-utils/runtime';
14 15 16

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

叶飞's avatar
叶飞 committed
50
  async componentDidMount() {
邓晓峰's avatar
邓晓峰 committed
51
    this.notifier.subscribe(NEW_MESSAGE, this.onNewMessage.bind(this));
叶飞's avatar
叶飞 committed
52
    this.notifier.start();
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    window.share && window.share.event && window.share.event.on('reloadNotice', () => {
      try {
        // eslint-disable-next-line no-unused-expressions
        this.notifier && this.notifier.stop();
      } catch (error) {
        // eslint-disable-next-line no-empty
      } finally {
        this.notifier = new Notifier(
          this.props.global.userInfo,
          this.renderVideo,
          this.renderPlatform,
          this.renderSysPlatform,
          this.props,
        );
        this.notifier.subscribe(NEW_MESSAGE, this.onNewMessage.bind(this));
        this.notifier.start();
      }
    });
叶飞's avatar
叶飞 committed
71
  }
叶飞's avatar
叶飞 committed
72

邓晓峰's avatar
邓晓峰 committed
73
  componentWillUnmount() {
邓晓峰's avatar
邓晓峰 committed
74
    try {
邓晓峰's avatar
邓晓峰 committed
75
      // eslint-disable-next-line no-unused-expressions
邓晓峰's avatar
邓晓峰 committed
76
      this.notifier && this.notifier.stop();
邓晓峰's avatar
邓晓峰 committed
77 78 79
    } catch (error) {
      // eslint-disable-next-line no-empty
    } finally {
80
      window.share.event.removeAllListeners('reloadNotice');
邓晓峰's avatar
邓晓峰 committed
81
    }
邓晓峰's avatar
邓晓峰 committed
82
  }
dengxiaofeng's avatar
dengxiaofeng committed
83

叶飞's avatar
叶飞 committed
84 85
  onNewMessage = messages => {
    this.setState({
邓晓峰's avatar
邓晓峰 committed
86 87
      count: messages.totalCount,
      noticeData: messages.messages,
邓晓峰's avatar
邓晓峰 committed
88
    });
叶飞's avatar
叶飞 committed
89 90
  };

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

邓晓峰's avatar
邓晓峰 committed
94 95
    return data.length > 0;
  };
邓晓峰's avatar
邓晓峰 committed
96 97

  handleCloseVideo = () => {
邓晓峰's avatar
邓晓峰 committed
98 99 100
    this.setState({ videoVisible: false });
    this.notifier.destoryVideo();
  };
邓晓峰's avatar
邓晓峰 committed
101

邓晓峰's avatar
邓晓峰 committed
102 103 104 105
  handleClosePlatform = event => {
    this.setState({ platformVisible: false });
    this.notifier.destoryPlatform();
  };
邓晓峰's avatar
邓晓峰 committed
106

邓晓峰's avatar
邓晓峰 committed
107
  renderPlatform = message => {
108 109 110 111 112
    const messageContent =
      this.props.global.mqtt_mess.MessageLevel === '2.0' &&
      isJSON(message.infoContent)
        ? JSON.parse(message.infoContent)
        : message.infoContent;
邓晓峰's avatar
邓晓峰 committed
113

邓晓峰's avatar
邓晓峰 committed
114
    this.setState({
邓晓峰's avatar
邓晓峰 committed
115
      platformVisible: true,
邓晓峰's avatar
邓晓峰 committed
116 117 118 119
      alarmMessage: {
        message,
        messageContent,
      },
邓晓峰's avatar
邓晓峰 committed
120 121 122 123
    });
  };

  renderVideo = message => {
邓晓峰's avatar
邓晓峰 committed
124
    this.setState({
邓晓峰's avatar
邓晓峰 committed
125
      videoVisible: true,
邓晓峰's avatar
邓晓峰 committed
126
    });
邓晓峰's avatar
邓晓峰 committed
127
    const { props } = this;
邓晓峰's avatar
邓晓峰 committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
    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
144 145
    const id = data[3];
    const name = data[0];
邓晓峰's avatar
邓晓峰 committed
146 147 148 149 150 151
    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
152 153 154 155 156 157 158 159

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

162 163 164 165 166 167 168 169 170 171 172 173 174
  // 消息弹窗Footer
  renderNotifierFooter = () => {
    const toNotifications = e => {
      e.stopPropagation();
      history.push && history.push('/system/notifications')
    }
    return (
      <div className={styles.notificationFoter}>
        <a onClick={toNotifications}>查看全部历史消息</a>
      </div>
    )
  }

邓晓峰's avatar
邓晓峰 committed
175 176
  handlerOptions = value => {
    // eslint-disable-next-line no-undef
邓晓峰's avatar
邓晓峰 committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    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
194 195
  };

196 197
  renderSysPlatform = message => {
    const noticeContent =
邓晓峰's avatar
邓晓峰 committed
198 199
      this.props.global.mqtt_mess.MessageLevel === '2.0' &&
      isJSON(message.infoContent)
200 201 202 203 204
        ? JSON.parse(message.infoContent)
        : message.infoContent;
    this.setState({
      sysTopVisible: true,
      platformVisible: false,
邓晓峰's avatar
邓晓峰 committed
205 206 207 208 209
      videoVisible: false,
      sysMessage: {
        message,
        noticeContent,
      },
210
    });
邓晓峰's avatar
邓晓峰 committed
211
  };
邓晓峰's avatar
邓晓峰 committed
212

邓晓峰's avatar
邓晓峰 committed
213 214
  handlerMointer = (event, item, detail) => {
    event.stopPropagation();
邓晓峰's avatar
邓晓峰 committed
215
    this.notifier.confirmRead(false, [item.id]);
邓晓峰's avatar
邓晓峰 committed
216 217
    if (detail) {
      const widgetID = 'widget_city_综合运营_管网监控_实时监控_报警监控';
邓晓峰's avatar
邓晓峰 committed
218
      const webPath = 'product/scada/AlertMonitoring/AlertMonitoring';
邓晓峰's avatar
邓晓峰 committed
219 220 221 222 223 224
      const widget = findPathByWidget(
        'productex/water/IOTMonitor/RealTimeAlarm/RealTimeAlarm',
        this.props.global.widgets,
        '',
        'url',
      );
邓晓峰's avatar
邓晓峰 committed
225
      window.share.event.emit('listenerMointer', {
邓晓峰's avatar
邓晓峰 committed
226
        widgetId: widgetID,
邓晓峰's avatar
邓晓峰 committed
227
        label: '实时报警',
邓晓峰's avatar
邓晓峰 committed
228
        url: widget.url || webPath,
邓晓峰's avatar
邓晓峰 committed
229 230
      });
    }
邓晓峰's avatar
邓晓峰 committed
231
    this.setState({
邓晓峰's avatar
邓晓峰 committed
232 233 234
      platformVisible: false,
    });
  };
邓晓峰's avatar
邓晓峰 committed
235

邓晓峰's avatar
邓晓峰 committed
236
  handlerSysDetail = message => {
邓晓峰's avatar
邓晓峰 committed
237
    this.setState({
邓晓峰's avatar
邓晓峰 committed
238
      sysTopVisible: true,
邓晓峰's avatar
邓晓峰 committed
239
    });
邓晓峰's avatar
邓晓峰 committed
240
    this.renderSysPlatform(message);
邓晓峰's avatar
邓晓峰 committed
241
  };
邓晓峰's avatar
邓晓峰 committed
242

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
  handlerUnknowDetail = message => {
    // 需要有跳转路径
    if (!message.webPath)
      return notification.info({ message: '提示', duration: 3, description: '未配置跳转路径' });

    const parsePath = url => {
      const [path, param = ''] = url.split('|');
      let params = param.split('&').reduce((pre, item) => {
        if(!item) return pre;
        const [key, value] = item.split('=');
        pre[key] = value;
        return pre;
      }, {});
      return [path, param, params];
    }
    const [path,,params] = parsePath(message.webPath);
    // 需要有widget参数
    if (!params.widget)
      return notification.info({ message: '提示', duration: 3, description: '未配置跳转路径' });
    // 根据widget匹配菜单
    const menu = (this.props.flatMenu || []).find(item => item.params && item.params.widget === params.widget);
    // const menu = (this.props.flatMenu || []).find(item => item.path.indexOf(path) > -1);
    let targetMenuPath = menu ? menu.path.replace(/^\//, '') : '';
    if (targetMenuPath == '') {
      notification.info({ message: '提示', duration: 3, description: '你没有跳转菜单权限,请联系管理员添加权限' });
      return;
    }
    params._source = '消息通知';
    params._target = message.webPath;
    sessionStorage.setItem('routerParams', JSON.stringify(params));
    window.history.pushState(params, '', `/civbase/${targetMenuPath}`);
  }

dengxiaofeng's avatar
dengxiaofeng committed
276 277
  render() {
    return (
邓晓峰's avatar
邓晓峰 committed
278 279 280 281
      <>
        <NoticeIcon
          className={styles.action}
          count={this.state.count}
叶飞's avatar
叶飞 committed
282
          confirmRead={this.notifier.confirmRead}
邓晓峰's avatar
邓晓峰 committed
283
          config={this.props.global}
邓晓峰's avatar
邓晓峰 committed
284
          bell={this.props.bell}
285
          renderFooter={this.renderNotifierFooter}
邓晓峰's avatar
邓晓峰 committed
286 287 288
        >
          <NoticeIcon.Tab
            list={this.state.noticeData}
289
            title={<FormattedMessage id='component.noticeIcon.title'/>}
邓晓峰's avatar
邓晓峰 committed
290
            emptyText={<FormattedMessage id='component.noticeIcon.allClear'/>}
邓晓峰's avatar
邓晓峰 committed
291
            confirmRead={this.notifier.confirmRead}
邓晓峰's avatar
邓晓峰 committed
292
            handlerSysDetail={this.handlerSysDetail}
293
            handlerUnknowDetail={this.handlerUnknowDetail.bind(this)}
邓晓峰's avatar
邓晓峰 committed
294
            loadMore={this.notifier.loadMore}
邓晓峰's avatar
邓晓峰 committed
295
            hasMore={this.notifier.hasMore}
邓晓峰's avatar
邓晓峰 committed
296 297
          />
        </NoticeIcon>
邓晓峰's avatar
邓晓峰 committed
298 299
        {this.state.platformVisible && this.state.alarmMessage && (
          <Modal
300
            title={<FormattedMessage id='component.noticeIcon.modal.alarm.title'/>}
邓晓峰's avatar
邓晓峰 committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
            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
317 318 319 320 321 322
                    onClick={event =>
                      this.handlerMointer(
                        event,
                        this.state.alarmMessage.message,
                        true,
                      )
邓晓峰's avatar
邓晓峰 committed
323 324 325 326 327 328 329
                    }
                  >
                    {this.state.alarmMessage &&
                      this.state.alarmMessage.messageContent &&
                      this.state.alarmMessage.messageContent.title}
                  </a>
                  <span
330
                    title={<FormattedMessage id='component.noticeIcon.messsage.statused'/>}
邓晓峰's avatar
邓晓峰 committed
331
                    onClick={event =>
邓晓峰's avatar
邓晓峰 committed
332
                      this.handlerMointer(
邓晓峰's avatar
邓晓峰 committed
333
                        event,
邓晓峰's avatar
邓晓峰 committed
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
                        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>
363 364 365 366 367
                  <span>
                    {this.state.alarmMessage &&
                      this.state.alarmMessage.message &&
                      this.state.alarmMessage.message.time}
                  </span>
邓晓峰's avatar
邓晓峰 committed
368 369 370 371 372
                </div>
              </div>
            </div>
          </Modal>
        )}
邓晓峰's avatar
邓晓峰 committed
373

374
        {this.state.videoVisible && this.state.videoMessage && (
邓晓峰's avatar
邓晓峰 committed
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
          <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>
        )}
397

398
        {this.state.sysTopVisible && this.state.sysMessage && !this.props.global.isNewYear && (
邓晓峰's avatar
邓晓峰 committed
399
          <Modal
400
            title={<FormattedMessage id='component.noticeIcon.model.system.title'/>}
邓晓峰's avatar
邓晓峰 committed
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 430 431 432 433 434 435 436 437 438 439 440 441 442 443
            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>
        )}
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500

        {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
501
      </>
dengxiaofeng's avatar
dengxiaofeng committed
502 503 504 505
    );
  }
}

邓晓峰's avatar
邓晓峰 committed
506 507
const mapStateToProps = state => ({
  global: state.getIn(['global', 'globalConfig']),
508
  flatMenu: state.getIn(['global', 'flatMenu']),
邓晓峰's avatar
邓晓峰 committed
509
});
叶飞's avatar
叶飞 committed
510

邓晓峰's avatar
邓晓峰 committed
511 512 513 514 515
const mapDispatchToProps = dispatch => ({
  updateConfig(config) {
    dispatch(actionCreators.getConfig(config));
  },
});
邓晓峰's avatar
邓晓峰 committed
516

邓晓峰's avatar
邓晓峰 committed
517 518
export default connect(
  mapStateToProps,
邓晓峰's avatar
邓晓峰 committed
519
  mapDispatchToProps,
邓晓峰's avatar
邓晓峰 committed
520
)(NoticeIconView);