refactor: request in DutyInfo & Welcome
parent
311d67a1b1
commit
9fc19a3ebd
|
|
@ -1,7 +1,14 @@
|
||||||
import { PageContainer, ProForm, ProFormRadio, ProFormText } from '@ant-design/pro-components';
|
import { getDutyInfo } from '@/services/api';
|
||||||
|
import {
|
||||||
|
PageContainer,
|
||||||
|
ProForm,
|
||||||
|
ProFormDateTimeRangePicker,
|
||||||
|
ProFormDigit,
|
||||||
|
ProFormRadio,
|
||||||
|
ProFormText,
|
||||||
|
} from '@ant-design/pro-components';
|
||||||
import { Card, Col, Row, Space, message } from 'antd';
|
import { Card, Col, Row, Space, message } from 'antd';
|
||||||
// import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import request from 'umi-request';
|
|
||||||
import { Info } from './info';
|
import { Info } from './info';
|
||||||
|
|
||||||
const waitTime = (time: number = 100) => {
|
const waitTime = (time: number = 100) => {
|
||||||
|
|
@ -13,10 +20,30 @@ const waitTime = (time: number = 100) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const DutyInfo: React.FC = () => {
|
const DutyInfo: React.FC = () => {
|
||||||
// const [isNormalDuty, setIsNormalDuty] = useState(true);
|
const [dutyInfo, setDutyInfo] = useState<Info>();
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
|
useEffect(() => {
|
||||||
|
getDutyInfo()
|
||||||
|
.then((res) => {
|
||||||
|
setDutyInfo(res.data);
|
||||||
|
setLoading(false);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
messageApi.open({
|
||||||
|
type: 'error',
|
||||||
|
content: '获取失败!' + err,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// const [editableKeys, setEditableRowKeys] = useState<React.Key[]>(() =>
|
||||||
|
// defaultData.map((item) => item.id),
|
||||||
|
// );
|
||||||
return (
|
return (
|
||||||
<PageContainer>
|
<PageContainer>
|
||||||
|
{contextHolder}
|
||||||
<Card>
|
<Card>
|
||||||
|
{!loading && (
|
||||||
<ProForm<Info>
|
<ProForm<Info>
|
||||||
submitter={{
|
submitter={{
|
||||||
render: (props, doms) => {
|
render: (props, doms) => {
|
||||||
|
|
@ -34,24 +61,20 @@ const DutyInfo: React.FC = () => {
|
||||||
console.log(values);
|
console.log(values);
|
||||||
message.success('提交成功');
|
message.success('提交成功');
|
||||||
}}
|
}}
|
||||||
params={{}}
|
initialValues={dutyInfo}
|
||||||
request={async (params = {} as Record<string, any>) =>
|
|
||||||
request<Info>('/admin/duty/current', {
|
|
||||||
params,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<ProFormRadio.Group
|
<ProFormRadio.Group
|
||||||
style={{
|
style={{
|
||||||
margin: 16,
|
margin: 16,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ProFormText
|
<ProFormDigit
|
||||||
width="md"
|
|
||||||
name="inDutyCnt"
|
|
||||||
label="值班人数"
|
label="值班人数"
|
||||||
tooltip="请输入数字"
|
name="inDutyCnt"
|
||||||
placeholder="请输入值班人数"
|
placeholder="请输入值班人数"
|
||||||
|
width="sm"
|
||||||
|
min={0}
|
||||||
|
max={10}
|
||||||
/>
|
/>
|
||||||
<ProFormText
|
<ProFormText
|
||||||
width="md"
|
width="md"
|
||||||
|
|
@ -59,13 +82,45 @@ const DutyInfo: React.FC = () => {
|
||||||
label="暂停值班原因"
|
label="暂停值班原因"
|
||||||
placeholder="请输入暂停值班的原因"
|
placeholder="请输入暂停值班的原因"
|
||||||
/>
|
/>
|
||||||
|
<ProFormText
|
||||||
|
width="md"
|
||||||
|
name="place"
|
||||||
|
label="其他值班地点"
|
||||||
|
placeholder="请输入特殊值班地点"
|
||||||
|
/>
|
||||||
<ProFormText
|
<ProFormText
|
||||||
name="dutyRecoverTime"
|
name="dutyRecoverTime"
|
||||||
width="md"
|
width="md"
|
||||||
label="值班恢复时间"
|
label="值班恢复时间"
|
||||||
placeholder="请输入值班恢复的时间"
|
placeholder="请输入值班恢复的时间"
|
||||||
/>
|
/>
|
||||||
|
<ProForm.Item label="值班时间" name="dataSource" trigger="onValuesChange">
|
||||||
|
{/* <EditableProTable<DataSourceType>
|
||||||
|
rowKey="id"
|
||||||
|
toolBarRender={false}
|
||||||
|
columns={columns}
|
||||||
|
recordCreatorProps={{
|
||||||
|
newRecordType: 'dataSource',
|
||||||
|
position: 'top',
|
||||||
|
record: () => ({
|
||||||
|
id: Date.now(),
|
||||||
|
addonBefore: 'ccccccc',
|
||||||
|
decs: 'testdesc',
|
||||||
|
}),
|
||||||
|
}}
|
||||||
|
editable={{
|
||||||
|
type: 'multiple',
|
||||||
|
editableKeys,
|
||||||
|
onChange: setEditableRowKeys,
|
||||||
|
actionRender: (row, _, dom) => {
|
||||||
|
return [dom.delete];
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/> */}
|
||||||
|
</ProForm.Item>
|
||||||
|
<ProFormDateTimeRangePicker name="dateTimeRange" label="值班时间" />
|
||||||
</ProForm>
|
</ProForm>
|
||||||
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { PageContainer, ProCard, StatisticCard } from '@ant-design/pro-component
|
||||||
import { Card, Statistic, message } 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';
|
||||||
|
import { Stat } from './stat';
|
||||||
|
|
||||||
const percentRing = (percent: number, frontColor: string): React.JSX.Element => {
|
const percentRing = (percent: number, frontColor: string): React.JSX.Element => {
|
||||||
const TinyRing = Tiny.Ring as (props: TinyRingConfig) => JSX.Element;
|
const TinyRing = Tiny.Ring as (props: TinyRingConfig) => JSX.Element;
|
||||||
|
|
@ -34,24 +35,21 @@ const percentRing = (percent: number, frontColor: string): React.JSX.Element =>
|
||||||
const Logs: React.FC = () => {
|
const Logs: React.FC = () => {
|
||||||
const [responsive, setResponsive] = useState(false);
|
const [responsive, setResponsive] = useState(false);
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
|
const [stat, setStat] = useState<Stat>({
|
||||||
const [todayPT, setTodayPT] = useState(0);
|
todayPT: 0,
|
||||||
const [report, setReport] = useState(0);
|
totalPT: 0,
|
||||||
const [oreo, setOreo] = useState(0);
|
oreo: 0,
|
||||||
const [totalPT, setTotalPT] = useState(0);
|
report: 0,
|
||||||
const [allSuccess, setAllSuccess] = useState(0);
|
allSuccess: 0,
|
||||||
const [all, setAll] = useState(0);
|
all: 0,
|
||||||
|
});
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
getStat()
|
getStat()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const data = res.data;
|
setStat(res.data);
|
||||||
setTodayPT(data.todayPT);
|
setLoading(false);
|
||||||
setReport(data.report);
|
|
||||||
setOreo(data.oreo);
|
|
||||||
setTotalPT(data.totalPT);
|
|
||||||
setAllSuccess(data.allSuccess);
|
|
||||||
setAll(data.all);
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
messageApi.open({
|
messageApi.open({
|
||||||
|
|
@ -63,6 +61,7 @@ const Logs: React.FC = () => {
|
||||||
return (
|
return (
|
||||||
<PageContainer>
|
<PageContainer>
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
|
{!loading && (
|
||||||
<Card style={{ color: '#f5f5f5' }}>
|
<Card style={{ color: '#f5f5f5' }}>
|
||||||
<RcResizeObserver
|
<RcResizeObserver
|
||||||
key="resize-observer"
|
key="resize-observer"
|
||||||
|
|
@ -80,12 +79,12 @@ const Logs: React.FC = () => {
|
||||||
style={{ marginTop: '0vh' }}
|
style={{ marginTop: '0vh' }}
|
||||||
statistic={{
|
statistic={{
|
||||||
title: '今日预填写工单数',
|
title: '今日预填写工单数',
|
||||||
value: todayPT,
|
value: stat.todayPT,
|
||||||
description: (
|
description: (
|
||||||
<Statistic
|
<Statistic
|
||||||
style={{ marginTop: '15vh', marginBottom: '8vh' }}
|
style={{ marginTop: '15vh', marginBottom: '8vh' }}
|
||||||
title="今日反馈数"
|
title="今日反馈数"
|
||||||
value={report}
|
value={stat.report}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
|
|
@ -95,22 +94,28 @@ const Logs: React.FC = () => {
|
||||||
<StatisticCard.Group direction={responsive ? 'row' : 'column'}>
|
<StatisticCard.Group direction={responsive ? 'row' : 'column'}>
|
||||||
<StatisticCard
|
<StatisticCard
|
||||||
hoverable
|
hoverable
|
||||||
chart={percentRing(Math.round(((oreo / totalPT) * 1000) / 10), '#00CC66')}
|
chart={percentRing(
|
||||||
|
Math.round(((stat.oreo / stat.totalPT) * 1000) / 10),
|
||||||
|
'#00CC66',
|
||||||
|
)}
|
||||||
statistic={{
|
statistic={{
|
||||||
title: '加入 Oreo 工单数',
|
title: '加入 Oreo 工单数',
|
||||||
value: oreo,
|
value: stat.oreo,
|
||||||
description: <Statistic title="预填写工单总数" value={totalPT} />,
|
description: <Statistic title="预填写工单总数" value={stat.totalPT} />,
|
||||||
}}
|
}}
|
||||||
chartPlacement="left"
|
chartPlacement="left"
|
||||||
/>
|
/>
|
||||||
<StatisticCard
|
<StatisticCard
|
||||||
hoverable
|
hoverable
|
||||||
style={{ marginTop: '3vh' }}
|
style={{ marginTop: '3vh' }}
|
||||||
chart={percentRing(Math.round((allSuccess / all) * 1000) / 10, '#66AFF4')}
|
chart={percentRing(
|
||||||
|
Math.round((stat.allSuccess / stat.all) * 1000) / 10,
|
||||||
|
'#66AFF4',
|
||||||
|
)}
|
||||||
statistic={{
|
statistic={{
|
||||||
title: '维修成功次数',
|
title: '维修成功次数',
|
||||||
value: allSuccess,
|
value: stat.allSuccess,
|
||||||
description: <Statistic title="Oreo、ETA 总工单数" value={all} />,
|
description: <Statistic title="Oreo、ETA 总工单数" value={stat.all} />,
|
||||||
}}
|
}}
|
||||||
chartPlacement="left"
|
chartPlacement="left"
|
||||||
/>
|
/>
|
||||||
|
|
@ -119,6 +124,7 @@ const Logs: React.FC = () => {
|
||||||
</ProCard>
|
</ProCard>
|
||||||
</RcResizeObserver>
|
</RcResizeObserver>
|
||||||
</Card>
|
</Card>
|
||||||
|
)}
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
export type Stat = {
|
||||||
|
todayPT: number;
|
||||||
|
totalPT: number;
|
||||||
|
oreo: number;
|
||||||
|
report: number;
|
||||||
|
allSuccess: number;
|
||||||
|
all: number;
|
||||||
|
};
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import { Info } from '@/pages/Admin/DutyInfo/info';
|
import { Info } from '@/pages/Admin/DutyInfo/info';
|
||||||
|
import { Stat } from '@/pages/Welcome/stat';
|
||||||
import { request } from '@umijs/max';
|
import { request } from '@umijs/max';
|
||||||
import { API } from './typings';
|
import { API } from './typings';
|
||||||
|
|
||||||
|
|
@ -37,7 +38,7 @@ export async function login(body: API.LoginParams, options?: { [key: string]: an
|
||||||
/** 获取首页信息 GET /stats */
|
/** 获取首页信息 GET /stats */
|
||||||
export async function getStat(options?: { [key: string]: any }) {
|
export async function getStat(options?: { [key: string]: any }) {
|
||||||
return request<{
|
return request<{
|
||||||
data: API.Stat;
|
data: Stat;
|
||||||
}>('/stats', {
|
}>('/stats', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
...(options || {}),
|
...(options || {}),
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,4 @@ declare namespace API {
|
||||||
size: number;
|
size: number;
|
||||||
data: LogsItem[];
|
data: LogsItem[];
|
||||||
};
|
};
|
||||||
type Stat = {
|
|
||||||
todayPT: number;
|
|
||||||
totalPT: number;
|
|
||||||
oreo: number;
|
|
||||||
report: number;
|
|
||||||
allSuccess: number;
|
|
||||||
all: number;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue