| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- import { PageContainer } from '@ant-design/pro-layout';
- import { useEffect, useRef, useState } from 'react';
- import './index.less';
- import service from '../service';
- import DashBoard, { DashBoardTopCard } from '@/components/DashBoard';
- import type { EChartsOption } from 'echarts';
- type RefType = {
- getValues: Function;
- };
- const DeviceBoard = () => {
- const [channel, setChannel] = useState(0);
- const [errorChannel, setErrorChannel] = useState(0);
- const [collector, setCollector] = useState(0);
- const [errorCollector, setErrorCollector] = useState(0);
- const [point, setPoint] = useState(0);
- const [errorPoint, setErrorPoint] = useState(0);
- const ref = useRef<RefType>();
- const [options, setOptions] = useState<EChartsOption>({});
- const [timeToolOptions] = useState([
- { label: '最近1小时', value: 'hour' },
- { label: '今日', value: 'today' },
- { label: '近一周', value: 'week' },
- ]);
- //通道数量
- const channelStatus = async () => {
- const channelRes = await service.queryChannelCount({});
- if (channelRes.status === 200) {
- setChannel(channelRes.result);
- }
- const errorChannelRes = await service.queryChannelCount({
- terms: [
- {
- column: 'runningState',
- termType: 'not',
- value: 'running',
- },
- ],
- });
- if (errorChannelRes.status === 200) {
- setErrorChannel(errorChannelRes.result);
- }
- };
- //采集器数量
- const collectorStatus = async () => {
- const collectorRes = await service.queryCollectorCount({});
- if (collectorRes.status === 200) {
- setCollector(collectorRes.result);
- }
- const errorCollectorRes = await service.queryCollectorCount({
- terms: [
- {
- column: 'runningState',
- termType: 'not',
- value: 'running',
- },
- ],
- });
- if (errorCollectorRes.status === 200) {
- setErrorCollector(errorCollectorRes.result);
- }
- };
- // 点位
- const pointStatus = async () => {
- const pointRes = await service.queryPointCount({});
- if (pointRes.status === 200) {
- setPoint(pointRes.result);
- }
- const errorPointRes = await service.queryPointCount({
- terms: [
- {
- column: 'runningState',
- termType: 'not',
- value: 'running',
- },
- ],
- });
- if (errorPointRes.status === 200) {
- setErrorPoint(errorPointRes.result);
- }
- };
- const getParams = (dt: any) => {
- switch (dt.type) {
- case 'today':
- return {
- limit: 24,
- interval: '1h',
- format: 'HH:mm',
- };
- case 'week':
- return {
- limit: 7,
- interval: '1d',
- format: 'MM-dd',
- };
- case 'hour':
- return {
- limit: 60,
- interval: '1m',
- format: 'HH:mm',
- };
- default:
- const time = dt.end - dt.start;
- const hour = 60 * 60 * 1000;
- const days = hour * 24;
- if (time <= hour) {
- return {
- limit: Math.abs(Math.ceil(time / (60 * 60))),
- interval: '1m',
- format: 'HH:mm',
- };
- } else if (time > hour && time <= days) {
- return {
- limit: Math.abs(Math.ceil(time / hour)),
- interval: '1h',
- format: 'HH:mm',
- };
- } else {
- return {
- limit: Math.abs(Math.ceil(time / days)) + 1,
- interval: '1d',
- format: 'MM-dd',
- };
- }
- }
- };
- const getEcharts = async () => {
- const data = ref.current!.getValues();
- const res = await service.dashboard([
- {
- dashboard: 'collector',
- object: 'pointData',
- measurement: 'quantity',
- dimension: 'agg',
- params: {
- limit: getParams(data.time).limit,
- from: data.time.start,
- to: data.time.end,
- interval: getParams(data.time).interval,
- format: getParams(data.time).format,
- },
- },
- ]);
- if (res.status === 200) {
- const x = res.result.map((item: any) => item.data.timeString).reverse();
- const y = res.result.map((item: any) => item.data.value).reverse();
- setOptions({
- xAxis: {
- type: 'category',
- boundaryGap: false,
- data: x,
- },
- yAxis: {
- type: 'value',
- },
- tooltip: {
- trigger: 'axis',
- },
- grid: {
- top: '2%',
- bottom: '5%',
- left: '50px',
- right: '50px',
- },
- series: [
- {
- name: '消息量',
- data: y,
- type: 'line',
- smooth: true,
- color: '#60DFC7',
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [
- {
- offset: 0,
- color: '#60DFC7', // 100% 处的颜色
- },
- {
- offset: 1,
- color: '#FFFFFF', // 0% 处的颜色
- },
- ],
- global: false, // 缺省为 false
- },
- },
- },
- ],
- });
- }
- };
- useEffect(() => {
- channelStatus();
- collectorStatus();
- pointStatus();
- }, []);
- return (
- <PageContainer>
- <div className={'device-dash-board'}>
- <DashBoardTopCard>
- <DashBoardTopCard.Item
- title={'通道数量'}
- value={channel}
- footer={[
- {
- title: '异常通道',
- value: errorChannel,
- status: 'error',
- },
- ]}
- span={8}
- >
- <img src={require('/public/images/DataCollect/dashboard/channel.png')} />
- </DashBoardTopCard.Item>
- <DashBoardTopCard.Item
- title={'采集器数量'}
- value={collector}
- footer={[
- {
- title: '异常采集器',
- value: errorCollector,
- status: 'error',
- },
- ]}
- span={8}
- >
- <img src={require('/public/images/DataCollect/dashboard/collector.png')} />
- </DashBoardTopCard.Item>
- <DashBoardTopCard.Item
- title={'采集点位'}
- value={point}
- footer={[
- {
- title: '异常点位',
- value: errorPoint,
- status: 'error',
- },
- ]}
- span={8}
- >
- <img src={require('/public/images/DataCollect/dashboard/point.png')} />
- </DashBoardTopCard.Item>
- </DashBoardTopCard>
- <DashBoard
- title={'点位数据量'}
- options={options}
- ref={ref}
- height={500}
- defaultTime={'hour'}
- timeToolOptions={timeToolOptions}
- showTime={true}
- showTimeTool={true}
- onParamsChange={getEcharts}
- />
- </div>
- </PageContainer>
- );
- };
- export default DeviceBoard;
|