feat: stats service in index page

mgy
Dawn1Ocean 2024-04-16 20:47:54 +08:00
parent 0ea7eff03d
commit f5c6f75779
2 changed files with 32 additions and 46 deletions

View File

@ -2,7 +2,7 @@ import { getStat } from '@/services/api';
import type { TinyRingConfig } from '@ant-design/charts'; import type { TinyRingConfig } from '@ant-design/charts';
import { Tiny } from '@ant-design/charts'; import { Tiny } from '@ant-design/charts';
import { PageContainer, ProCard, StatisticCard } from '@ant-design/pro-components'; import { PageContainer, ProCard, StatisticCard } from '@ant-design/pro-components';
import { Card, Statistic } from 'antd'; import { Card, Statistic, message } from 'antd';
import RcResizeObserver from 'rc-resize-observer'; import RcResizeObserver from 'rc-resize-observer';
import { useLayoutEffect, useState } from 'react'; import { useLayoutEffect, useState } from 'react';
@ -31,26 +31,10 @@ const percentRing = (percent: number, frontColor: string): React.JSX.Element =>
return <TinyRing {...config} />; return <TinyRing {...config} />;
}; };
interface IndexData {
todayPT: number;
report: number;
oreo: number;
totalPT: number;
allSuccess: number;
all: number;
}
const indexData: IndexData = {
todayPT: 14,
report: 8,
oreo: 93,
totalPT: 1145,
allSuccess: 1818,
all: 1919,
};
const Logs: React.FC = () => { const Logs: React.FC = () => {
const [responsive, setResponsive] = useState(false); const [responsive, setResponsive] = useState(false);
const [messageApi, contextHolder] = message.useMessage();
const [todayPT, setTodayPT] = useState(0); const [todayPT, setTodayPT] = useState(0);
const [report, setReport] = useState(0); const [report, setReport] = useState(0);
const [oreo, setOreo] = useState(0); const [oreo, setOreo] = useState(0);
@ -59,18 +43,26 @@ const Logs: React.FC = () => {
const [all, setAll] = useState(0); const [all, setAll] = useState(0);
useLayoutEffect(() => { useLayoutEffect(() => {
getStat().then((res) => { getStat()
const data = res.data; .then((res) => {
setTodayPT(data.todayPT); const data = res.data;
setReport(data.report); setTodayPT(data.todayPT);
setOreo(data.oreo); setReport(data.report);
setTotalPT(data.totalPT); setOreo(data.oreo);
setAllSuccess(data.allSuccess); setTotalPT(data.totalPT);
setAll(data.all); setAllSuccess(data.allSuccess);
}) setAll(data.all);
})
.catch((err) => {
messageApi.open({
type: 'error',
content: '获取失败!' + err,
});
});
}); });
return ( return (
<PageContainer> <PageContainer>
{contextHolder}
<Card style={{ color: '#f5f5f5' }}> <Card style={{ color: '#f5f5f5' }}>
<RcResizeObserver <RcResizeObserver
key="resize-observer" key="resize-observer"
@ -79,52 +71,46 @@ const Logs: React.FC = () => {
}} }}
> >
<ProCard split={responsive ? 'horizontal' : 'vertical'}> <ProCard split={responsive ? 'horizontal' : 'vertical'}>
<ProCard colSpan="45%"> <ProCard colSpan="Auto">
<ProCard hoverable></ProCard> <ProCard hoverable></ProCard>
</ProCard> </ProCard>
<ProCard colSpan="20%"> <ProCard colSpan="170px">
<StatisticCard <StatisticCard
hoverable hoverable
style={{ marginTop: '0vh' }} style={{ marginTop: '0vh' }}
statistic={{ statistic={{
title: '今日预填写工单数', title: '今日预填写工单数',
value: indexData.todayPT, value: todayPT,
description: ( description: (
<Statistic <Statistic
style={{ marginTop: '15vh', marginBottom: '8vh' }} style={{ marginTop: '15vh', marginBottom: '8vh' }}
title="今日反馈数" title="今日反馈数"
value={indexData.report} value={report}
/> />
), ),
}} }}
/> />
</ProCard> </ProCard>
<ProCard> <ProCard colSpan="360px">
<StatisticCard.Group direction={responsive ? 'row' : 'column'}> <StatisticCard.Group direction={responsive ? 'row' : 'column'}>
<StatisticCard <StatisticCard
hoverable hoverable
chart={percentRing( chart={percentRing(Math.round(((oreo / totalPT) * 1000) / 10), '#00CC66')}
Math.round(((indexData.oreo / indexData.totalPT) * 1000) / 10),
'#00CC66',
)}
statistic={{ statistic={{
title: '加入 Oreo 工单数', title: '加入 Oreo 工单数',
value: indexData.oreo, value: oreo,
description: <Statistic title="预填写工单总数" value={indexData.totalPT} />, description: <Statistic title="预填写工单总数" value={totalPT} />,
}} }}
chartPlacement="left" chartPlacement="left"
/> />
<StatisticCard <StatisticCard
hoverable hoverable
style={{ marginTop: '3vh' }} style={{ marginTop: '3vh' }}
chart={percentRing( chart={percentRing(Math.round((allSuccess / all) * 1000) / 10, '#66AFF4')}
Math.round((indexData.allSuccess / indexData.all) * 1000) / 10,
'#66AFF4',
)}
statistic={{ statistic={{
title: '维修成功次数', title: '维修成功次数',
value: indexData.allSuccess, value: allSuccess,
description: <Statistic title="Oreo、ETA 总工单数" value={indexData.all} />, description: <Statistic title="Oreo、ETA 总工单数" value={all} />,
}} }}
chartPlacement="left" chartPlacement="left"
/> />

View File

@ -37,7 +37,7 @@ export async function login(body: API.LoginParams, options?: { [key: string]: an
export async function getStat(options?: { [key: string]: any }) { export async function getStat(options?: { [key: string]: any }) {
return request<{ return request<{
data: API.Stat; data: API.Stat;
}>('/stat', { }>('/stats', {
method: 'GET', method: 'GET',
...(options || {}), ...(options || {}),
}); });