|
@@ -5,33 +5,64 @@ import './index.less';
|
|
|
import Service from './service';
|
|
import Service from './service';
|
|
|
import encodeQuery from '@/utils/encodeQuery';
|
|
import encodeQuery from '@/utils/encodeQuery';
|
|
|
import { useRequest } from 'umi';
|
|
import { useRequest } from 'umi';
|
|
|
|
|
+import DashBoard from '@/components/DashBoard';
|
|
|
|
|
+import type { EChartsOption } from 'echarts';
|
|
|
|
|
+import Echarts from '@/components/DashBoard/echarts';
|
|
|
|
|
|
|
|
interface TopCardProps {
|
|
interface TopCardProps {
|
|
|
- url?: string;
|
|
|
|
|
isEcharts: boolean;
|
|
isEcharts: boolean;
|
|
|
title: string;
|
|
title: string;
|
|
|
- total: number | string;
|
|
|
|
|
|
|
+ total?: number | string;
|
|
|
|
|
+ topRender?: any;
|
|
|
bottomRender: () => React.ReactNode;
|
|
bottomRender: () => React.ReactNode;
|
|
|
}
|
|
}
|
|
|
const service = new Service('device/instance');
|
|
const service = new Service('device/instance');
|
|
|
const TopCard = (props: TopCardProps) => {
|
|
const TopCard = (props: TopCardProps) => {
|
|
|
return (
|
|
return (
|
|
|
<div className={'top-card-item'}>
|
|
<div className={'top-card-item'}>
|
|
|
- <div className={'top-card-top'}>
|
|
|
|
|
- {!props.isEcharts && <div className={'top-card-top-left'}></div>}
|
|
|
|
|
- <div className={'top-card-top-right'}>
|
|
|
|
|
- <div className={'top-card-title'}>{props.title}</div>
|
|
|
|
|
- <div className={'top-card-total'}>{props.total}</div>
|
|
|
|
|
|
|
+ {props.isEcharts ? (
|
|
|
|
|
+ <div className={'top-card-top'}>
|
|
|
|
|
+ <div className={'top-card-top-charts'}>
|
|
|
|
|
+ <div>{props.title}</div>
|
|
|
|
|
+ <div className={'top-card-top-charts-total'}>{props.total}</div>
|
|
|
|
|
+ <div style={{ height: 40 }}>{props.topRender}</div>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
- </div>
|
|
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <div className={'top-card-top'}>
|
|
|
|
|
+ <div className={'top-card-top-left'}></div>
|
|
|
|
|
+ <div className={'top-card-top-right'}>
|
|
|
|
|
+ <div className={'top-card-title'}>{props.title}</div>
|
|
|
|
|
+ <div className={'top-card-total'}>{props.total}</div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )}
|
|
|
|
|
+
|
|
|
<div className={'top-card-bottom'}>{props.bottomRender()}</div>
|
|
<div className={'top-card-bottom'}>{props.bottomRender()}</div>
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const DashBoard = () => {
|
|
|
|
|
|
|
+const DeviceBoard = () => {
|
|
|
const [deviceOnline, setDeviceOnline] = useState(0);
|
|
const [deviceOnline, setDeviceOnline] = useState(0);
|
|
|
const [deviceOffline, setDeviceOffline] = useState(0);
|
|
const [deviceOffline, setDeviceOffline] = useState(0);
|
|
|
|
|
+ const [options, setOptions] = useState<EChartsOption>({
|
|
|
|
|
+ xAxis: {
|
|
|
|
|
+ type: 'category',
|
|
|
|
|
+ boundaryGap: false,
|
|
|
|
|
+ data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
|
|
|
+ },
|
|
|
|
|
+ yAxis: {
|
|
|
|
|
+ type: 'value',
|
|
|
|
|
+ },
|
|
|
|
|
+ series: [
|
|
|
|
|
+ {
|
|
|
|
|
+ data: [820, 932, 901, 934, 1290, 1330, 1320],
|
|
|
|
|
+ type: 'line',
|
|
|
|
|
+ areaStyle: {},
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
const { data: deviceTotal } = useRequest(service.deviceCount, {
|
|
const { data: deviceTotal } = useRequest(service.deviceCount, {
|
|
|
formatResult: (res) => res.result,
|
|
formatResult: (res) => res.result,
|
|
@@ -48,13 +79,37 @@ const DashBoard = () => {
|
|
|
setDeviceOffline(offlineRes.result);
|
|
setDeviceOffline(offlineRes.result);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+ const getEcharts = async (params: any) => {
|
|
|
|
|
+ // 请求数据
|
|
|
|
|
+ console.log(params);
|
|
|
|
|
+
|
|
|
|
|
+ setOptions({
|
|
|
|
|
+ xAxis: {
|
|
|
|
|
+ type: 'category',
|
|
|
|
|
+ boundaryGap: false,
|
|
|
|
|
+ data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
|
|
|
+ },
|
|
|
|
|
+ yAxis: {
|
|
|
|
|
+ type: 'value',
|
|
|
|
|
+ },
|
|
|
|
|
+ series: [
|
|
|
|
|
+ {
|
|
|
|
|
+ data: [820, 932, 901, 934, 1290, 1330, 1320],
|
|
|
|
|
+ type: 'line',
|
|
|
|
|
+ areaStyle: {},
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
deviceStatus();
|
|
deviceStatus();
|
|
|
}, []);
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<PageContainer>
|
|
<PageContainer>
|
|
|
- <div className={'media-dash-board'}>
|
|
|
|
|
|
|
+ <div className={'device-dash-board'}>
|
|
|
<Card className={'top-card-items'} bodyStyle={{ display: 'flex', gap: 12 }}>
|
|
<Card className={'top-card-items'} bodyStyle={{ display: 'flex', gap: 12 }}>
|
|
|
<TopCard
|
|
<TopCard
|
|
|
title={'产品数量'}
|
|
title={'产品数量'}
|
|
@@ -83,19 +138,34 @@ const DashBoard = () => {
|
|
|
/>
|
|
/>
|
|
|
<TopCard
|
|
<TopCard
|
|
|
title={'当前在线'}
|
|
title={'当前在线'}
|
|
|
- total={1}
|
|
|
|
|
|
|
+ total={22}
|
|
|
isEcharts={true}
|
|
isEcharts={true}
|
|
|
|
|
+ topRender={
|
|
|
|
|
+ <div style={{ height: 50 }}>
|
|
|
|
|
+ <Echarts options={options} />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ }
|
|
|
bottomRender={() => <>昨日在线: </>}
|
|
bottomRender={() => <>昨日在线: </>}
|
|
|
/>
|
|
/>
|
|
|
<TopCard
|
|
<TopCard
|
|
|
title={'今日设备消息量'}
|
|
title={'今日设备消息量'}
|
|
|
- total={1}
|
|
|
|
|
|
|
+ total={2221}
|
|
|
isEcharts={true}
|
|
isEcharts={true}
|
|
|
bottomRender={() => <>当月设备消息量: </>}
|
|
bottomRender={() => <>当月设备消息量: </>}
|
|
|
/>
|
|
/>
|
|
|
</Card>
|
|
</Card>
|
|
|
|
|
+ <DashBoard
|
|
|
|
|
+ title={'设备消息'}
|
|
|
|
|
+ options={options}
|
|
|
|
|
+ height={500}
|
|
|
|
|
+ initialValues={{
|
|
|
|
|
+ test: '2',
|
|
|
|
|
+ }}
|
|
|
|
|
+ onParamsChange={getEcharts}
|
|
|
|
|
+ />
|
|
|
|
|
+ {/* <Echarts options={options} /> */}
|
|
|
</div>
|
|
</div>
|
|
|
</PageContainer>
|
|
</PageContainer>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
-export default DashBoard;
|
|
|
|
|
|
|
+export default DeviceBoard;
|