index.js 6.79 KB
Newer Older
1
import React, {useState, useEffect, useRef} from 'react';
2 3
import styles from './index.less';
import PropTypes from 'prop-types';
4 5 6
import {Tag, Tooltip, Modal} from 'antd';
import {EnvironmentOutlined} from '@ant-design/icons';
import {monitorService} from './api';
7 8
import moment from 'moment';
import classnames from 'classnames';
9
import {switchTimeToPeriod} from './utils';
10
import NormChart from './NormChart/NormChart';
11
import {Swiper, SwiperSlide} from 'swiper/react';
12 13 14
import 'swiper/swiper.min.css';
import 'swiper/components/pagination/pagination.min.css';
import 'swiper/components/navigation/navigation.min.css';
15
import SwiperCore, {Autoplay, Pagination, Navigation} from 'swiper/core';
16 17 18 19 20 21 22 23

SwiperCore.use([Autoplay, Pagination, Navigation]);
/*
 *   1. 获取当前所有数据;
 *   2. 倒序滚动播放;
 *   3. 初始化进入时,取截止到当前时间为止的所有的实时报警数据。
 *   4. 播放结束后,重新获取实时报警数据进行第二轮的播放。
 * */
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
const InfoItem = ({info}) => {
    const returnClassName = (type, key) => {
        let _className = '';
        if (type === '普通') {
            _className = 'normal';
        } else if (type === '紧急') {
            _className = 'warning';
        }
        return `${_className}${key}`;
    };
    const {alertLevel, startTime, stationName, alertMsg, deviceAddress} = info;
    return (
        <div className={styles[returnClassName(alertLevel, 'Wrapper')]}>
            <Tag className={styles[returnClassName(alertLevel, 'Tag')]}>{alertLevel}</Tag>
            <span className={classnames(styles.time, styles.fontSize13)}>{startTime}</span>
            <Tooltip title={deviceAddress} placement={'topLeft'}>
40 41
        <span className={styles.location}>
          <EnvironmentOutlined
42
              style={{fontSize: 12, color: '#666666', marginRight: 5, verticalAlign: 'middle'}}
43
          />
44
            {deviceAddress || ' - '}
45
        </span>
46 47 48 49 50 51 52 53 54
            </Tooltip>
            <Tooltip title={alertMsg} placement={'topLeft'}>
                <span className={styles[returnClassName(alertLevel, 'Content')]}>{alertMsg}</span>
            </Tooltip>
            <div className={styles.periodWrapper}>
                <span className={styles.period}>{switchTimeToPeriod(startTime)}</span>
            </div>
        </div>
    );
55 56
};
const AlarmScrollAssembly = (props) => {
57 58 59 60 61 62 63
    const [modalVisible, setModalVisible] = useState(false);
    const [currentInfo, setCurrentInfo] = useState({});
    const constanceRef = useRef({
        level: '1,2',
        type: '直接取值,取变化量,取变化率,取是否',
        userID: window.globalConfig.userInfo.OID,
        userAccess: true,
64
    });
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    const [realTimeDataList, setRealTimeDataList] = useState(null);
    const getDeviceNumber = () => {
        return monitorService.getEquipmentInfo({
            deviceTypes: props.deviceType,
            pageIndex: 1,
            pageSize: 1,
            ...constanceRef.current,
        });
    };
    const getRealTimeData = (pagination) => {
        return monitorService.GetAlarmListRealTime({
            deviceType: props.deviceType,
            ...constanceRef.current,
            pageIndex: pagination.pageIndex,
            pageSize: pagination.pageSize,
            userAccess: props.userAccess === void 0 ? true : props.userAccess,
            /*            dateFrom: moment().subtract(1, 'days').format('YYYY-MM-DD 00:00:00'),
                              dateTo: moment().format('YYYY-MM-DD 23:59:59'),*/
        });
    };
    const getData = async () => {
        let firstRequest = await getDeviceNumber();
        let secondRequest = await getRealTimeData({
            pageIndex: 1,
            pageSize: firstRequest.data.totalCount,
        });
        setRealTimeDataList(secondRequest?.data?.list || []);
    };
    useEffect(() => {
        getData();
    }, []);
    return (
97 98
        <div className={styles.alarmScrollAssemblyWrapper}>
            {realTimeDataList && realTimeDataList.length ? <div className={styles.content} style={{display: 'flex'}}>
99
                {
100 101
                    props.prefix ?
                        <span style={{...props.style, flex: 'none', marginRight: 10}}>{props.prefix}</span> : ''
102 103
                }
                <div
104
                    className={classnames(styles.alarmScrollAssembly, (realTimeDataList?.length > 1000 ? styles.moreThan1000 : styles.lessThan1000))}
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
                    id={'alarmListDiv'}>
                    <Swiper
                        slidesPerView={1}
                        modules={[Pagination]}
                        pagination={{
                            type: 'fraction',
                            formatFractionCurrent: (num) => `第${num}条`,
                            formatFractionTotal: (num) => `共${num}条`,
                        }}
                        navigation
                        autoplay={{
                            delay: 3000,
                            disableOnInteraction: false,
                        }}
                        loop
                        direction="vertical"
                        onSlideChange={(e) => {
                            if (e.activeIndex === realTimeDataList.length - 1) getData();
                        }}
124
                    >
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
                        {realTimeDataList.map((item, index) => {
                            return (
                                <SwiperSlide
                                    key={index}
                                    virtualIndex={index}
                                    onClick={() => {
                                        setCurrentInfo(item);
                                        setModalVisible(true);
                                    }}
                                >
                                    <InfoItem key={index} info={item}/>
                                </SwiperSlide>
                            );
                        })}
                    </Swiper>
                    {modalVisible && (
                        <Modal
                            visible={modalVisible}
                            onCancel={() => setModalVisible(false)}
                            width={'80%'}
                            destroyOnClose
                        >
                            <NormChart
                                info={currentInfo}
                                deviceType={currentInfo.deviceType}
                                deviceCode={currentInfo.stationCode}
                            />
                        </Modal>
                    )}
                </div>
155 156
            </div> : ''}
        </div>
157
    );
158 159
};
AlarmScrollAssembly.defaultProps = {
160
    deviceType: '二供泵房,二供机组',
161
    prefix: ''
162 163
};
AlarmScrollAssembly.propTypes = {
164
    deviceType: PropTypes.string,
165
    prefix: PropTypes.string
166 167
};
export default AlarmScrollAssembly;