add dutyinfo page
parent
1ff36f366d
commit
8f062b0e8c
|
|
@ -65,7 +65,7 @@ data:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"isNormalDuty": true, // 判断是否是正常值班时间
|
"isNormalDuty": true, // 判断是否是正常值班时间
|
||||||
"currentDuty": "1", // 判断是否正在值班 / 值哪一班 "1" | "2" | "3" => 正在值班,"off" => 值班下班
|
"currentDuty": "1", // 判断是否正在值班 / 值哪一班 "1" | "2" | "3" => 正在值班,"off" => 暂停值班, "0" => 值班下班
|
||||||
"inDutyCnt": 3,
|
"inDutyCnt": 3,
|
||||||
"otherDutyTime": [], // 正常值班时为空
|
"otherDutyTime": [], // 正常值班时为空
|
||||||
"offDutyReason": "",
|
"offDutyReason": "",
|
||||||
|
|
@ -81,7 +81,7 @@ data:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"isNormalDuty": false, // 判断是否是正常值班时间
|
"isNormalDuty": false, // 判断是否是正常值班时间
|
||||||
"currentDuty": "others", // 判断是否正在值班 / 值哪一班 "others" => 正在值班,"off" => 值班下班
|
"currentDuty": "others", // 判断是否正在值班 / 值哪一班 "others" => 正在值班,"off" => 暂停值班, "0" => 值班下班
|
||||||
"inDutyCnt": 3,
|
"inDutyCnt": 3,
|
||||||
"otherDutyTime": [
|
"otherDutyTime": [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -36,26 +36,31 @@ module.exports = {
|
||||||
'GET /admin/duty/current': {
|
'GET /admin/duty/current': {
|
||||||
success: true,
|
success: true,
|
||||||
data: {
|
data: {
|
||||||
isNormalDuty: false,
|
isNormalDuty: true,
|
||||||
currentDuty: 'off',
|
currentDuty: 'off',
|
||||||
inDutyCnt: 3,
|
inDutyCnt: 3,
|
||||||
otherDutyTime: [
|
otherDutyTime: [
|
||||||
{
|
{
|
||||||
name: '第一班',
|
id: 1,
|
||||||
|
title: '第一班',
|
||||||
|
place: 'fsaf',
|
||||||
range: ['2024-03-07T19:52:48.523303', '2024-03-07T19:52:48.523303'],
|
range: ['2024-03-07T19:52:48.523303', '2024-03-07T19:52:48.523303'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '第二班',
|
id: 2,
|
||||||
|
title: '第二班',
|
||||||
|
place: 'fsdhhv',
|
||||||
range: ['2024-03-07T19:52:48.523303', '2024-03-07T19:52:48.523303'],
|
range: ['2024-03-07T19:52:48.523303', '2024-03-07T19:52:48.523303'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '第三班',
|
id: 3,
|
||||||
|
title: '第三班',
|
||||||
|
place: 'fdshq',
|
||||||
range: ['2024-03-07T19:52:48.523303', '2024-03-07T19:52:48.523303'],
|
range: ['2024-03-07T19:52:48.523303', '2024-03-07T19:52:48.523303'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
offDutyReason: '期中考试周',
|
offDutyReason: '期中考试周',
|
||||||
place: '',
|
dutyRecoverTime: '2024-03-07T19:52:48.523303',
|
||||||
dutyRecoverTime: '下周一',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'POST /admin/duty/update': {
|
'POST /admin/duty/update': {
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,71 @@
|
||||||
import { getDutyInfo } from '@/services/api';
|
import { getDutyInfo, updateDutyInfo } from '@/services/api';
|
||||||
import {
|
import {
|
||||||
|
EditableProTable,
|
||||||
PageContainer,
|
PageContainer,
|
||||||
|
ProColumns,
|
||||||
ProForm,
|
ProForm,
|
||||||
ProFormDateTimeRangePicker,
|
ProFormDateTimePicker,
|
||||||
|
ProFormDependency,
|
||||||
ProFormDigit,
|
ProFormDigit,
|
||||||
ProFormRadio,
|
ProFormRadio,
|
||||||
ProFormText,
|
ProFormText,
|
||||||
} from '@ant-design/pro-components';
|
} from '@ant-design/pro-components';
|
||||||
import { Card, Col, Row, Space, message } from 'antd';
|
import { Card, message } from 'antd';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Info } from './info';
|
import { Info } from './info';
|
||||||
|
|
||||||
const waitTime = (time: number = 100) => {
|
type Shift = {
|
||||||
return new Promise((resolve) => {
|
id: React.Key;
|
||||||
setTimeout(() => {
|
title: string;
|
||||||
resolve(true);
|
place: string;
|
||||||
}, time);
|
range: string[];
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const columns: ProColumns<Shift>[] = [
|
||||||
|
{
|
||||||
|
title: '值班名称',
|
||||||
|
dataIndex: 'title',
|
||||||
|
width: '15%',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '值班地点',
|
||||||
|
dataIndex: 'place',
|
||||||
|
width: '15%',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '值班时间',
|
||||||
|
dataIndex: 'range',
|
||||||
|
valueType: 'dateTimeRange',
|
||||||
|
width: '40%',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
valueType: 'option',
|
||||||
|
width: '10%',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const DutyInfo: React.FC = () => {
|
const DutyInfo: React.FC = () => {
|
||||||
const [dutyInfo, setDutyInfo] = useState<Info>();
|
const [dutyInfo, setDutyInfo] = useState<Info>();
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
|
|
||||||
|
const [editableKeys, setEditableRowKeys] = useState<React.Key[]>(() => []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getDutyInfo()
|
getDutyInfo()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res.data);
|
const data = res.data;
|
||||||
setDutyInfo(res.data);
|
console.log(data);
|
||||||
|
setDutyInfo({
|
||||||
|
dutyStatus:
|
||||||
|
data.currentDuty === 'off' ? 'pause' : data.isNormalDuty ? 'others' : 'normal',
|
||||||
|
inDutyCnt: data.inDutyCnt,
|
||||||
|
otherDutyTime: data.otherDutyTime,
|
||||||
|
offDutyReason: data.offDutyReason,
|
||||||
|
dutyRecoverTime: data.dutyRecoverTime,
|
||||||
|
});
|
||||||
|
setEditableRowKeys(data.otherDutyTime.map((item) => item.id));
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|
@ -37,9 +75,7 @@ const DutyInfo: React.FC = () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
// const [editableKeys, setEditableRowKeys] = useState<React.Key[]>(() =>
|
|
||||||
// defaultData.map((item) => item.id),
|
|
||||||
// );
|
|
||||||
return (
|
return (
|
||||||
<PageContainer>
|
<PageContainer>
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
|
|
@ -47,66 +83,96 @@ const DutyInfo: React.FC = () => {
|
||||||
{!loading && (
|
{!loading && (
|
||||||
<ProForm<Info>
|
<ProForm<Info>
|
||||||
submitter={{
|
submitter={{
|
||||||
render: (props, doms) => {
|
resetButtonProps: { style: { display: 'none' } },
|
||||||
return (
|
submitButtonProps: {
|
||||||
<Row>
|
style: { width: '31%' },
|
||||||
<Col span={14} offset={4}>
|
},
|
||||||
<Space>{doms}</Space>
|
render: (_, doms) => {
|
||||||
</Col>
|
return <div style={{ textAlign: 'center' }}>{doms}</div>;
|
||||||
</Row>
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
onFinish={async (values) => {
|
onFinish={updateDutyInfo}
|
||||||
await waitTime(2000);
|
|
||||||
console.log(values);
|
|
||||||
message.success('提交成功');
|
|
||||||
}}
|
|
||||||
initialValues={dutyInfo}
|
initialValues={dutyInfo}
|
||||||
>
|
>
|
||||||
|
<div style={{ justifyContent: 'center', display: 'flex' }}>
|
||||||
<ProFormRadio.Group
|
<ProFormRadio.Group
|
||||||
style={{
|
name="dutyStatus"
|
||||||
margin: 16,
|
label="值班状态"
|
||||||
}}
|
options={[
|
||||||
/>
|
{
|
||||||
<ProFormDigit
|
label: '正常值班',
|
||||||
label="值班人数"
|
value: 'normal',
|
||||||
name="inDutyCnt"
|
},
|
||||||
placeholder="请输入值班人数"
|
{
|
||||||
width="sm"
|
label: '特殊值班',
|
||||||
min={0}
|
value: 'others',
|
||||||
max={10}
|
},
|
||||||
|
{
|
||||||
|
label: '值班暂停',
|
||||||
|
value: 'pause',
|
||||||
|
},
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
<div style={{ justifyContent: 'center', display: 'flex' }}>
|
||||||
|
<ProFormDependency name={['dutyStatus']}>
|
||||||
|
{({ dutyStatus }) => {
|
||||||
|
if (dutyStatus === 'pause') {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
<ProFormText
|
<ProFormText
|
||||||
width="md"
|
width="md"
|
||||||
name="offDutyReason"
|
name="offDutyReason"
|
||||||
label="暂停值班原因"
|
label="值班暂停原因"
|
||||||
placeholder="请输入暂停值班的原因"
|
placeholder="请输入暂停值班的原因"
|
||||||
/>
|
/>
|
||||||
<ProFormText
|
<ProFormDateTimePicker
|
||||||
width="md"
|
|
||||||
name="place"
|
|
||||||
label="其他值班地点"
|
|
||||||
placeholder="请输入特殊值班地点"
|
|
||||||
/>
|
|
||||||
<ProFormText
|
|
||||||
name="dutyRecoverTime"
|
name="dutyRecoverTime"
|
||||||
width="md"
|
width="md"
|
||||||
label="值班恢复时间"
|
label="值班恢复时间"
|
||||||
placeholder="请输入值班恢复的时间"
|
|
||||||
/>
|
/>
|
||||||
<ProForm.Item label="值班时间" name="dataSource" trigger="onValuesChange">
|
</div>
|
||||||
{/* <EditableProTable<DataSourceType>
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<ProFormDigit
|
||||||
|
label="当前值班人数"
|
||||||
|
name="inDutyCnt"
|
||||||
|
placeholder="请输入值班人数"
|
||||||
|
width="md"
|
||||||
|
min={0}
|
||||||
|
max={10}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</ProFormDependency>
|
||||||
|
</div>
|
||||||
|
<ProFormDependency name={['dutyStatus']}>
|
||||||
|
{({ dutyStatus }) => {
|
||||||
|
if (dutyStatus === 'others') {
|
||||||
|
return (
|
||||||
|
<div style={{ justifyContent: 'center', display: 'flex' }}>
|
||||||
|
<ProForm.Item
|
||||||
|
label="其他值班班次"
|
||||||
|
name="dataSource"
|
||||||
|
initialValue={dutyInfo?.otherDutyTime}
|
||||||
|
trigger="onValuesChange"
|
||||||
|
style={{ width: '80%' }}
|
||||||
|
>
|
||||||
|
<EditableProTable<Shift>
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
toolBarRender={false}
|
toolBarRender={false}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
recordCreatorProps={{
|
recordCreatorProps={{
|
||||||
newRecordType: 'dataSource',
|
newRecordType: 'dataSource',
|
||||||
position: 'top',
|
position: 'bottom',
|
||||||
|
creatorButtonText: '新建一个值班班次',
|
||||||
|
style: { width: '100%', margin: 'auto', marginTop: '2%' },
|
||||||
record: () => ({
|
record: () => ({
|
||||||
id: Date.now(),
|
id: Date.now(),
|
||||||
addonBefore: 'ccccccc',
|
title: '',
|
||||||
decs: 'testdesc',
|
place: '',
|
||||||
|
range: [],
|
||||||
}),
|
}),
|
||||||
}}
|
}}
|
||||||
editable={{
|
editable={{
|
||||||
|
|
@ -117,9 +183,13 @@ const DutyInfo: React.FC = () => {
|
||||||
return [dom.delete];
|
return [dom.delete];
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/> */}
|
/>
|
||||||
</ProForm.Item>
|
</ProForm.Item>
|
||||||
<ProFormDateTimeRangePicker name="dateTimeRange" label="值班时间" />
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
</ProFormDependency>
|
||||||
</ProForm>
|
</ProForm>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,22 @@
|
||||||
export type Shift = {
|
export type Shift = {
|
||||||
name: string;
|
id: React.Key;
|
||||||
|
title: string;
|
||||||
|
place: string;
|
||||||
range: string[];
|
range: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Info = {
|
export type ServerInfo = {
|
||||||
isNormalDuty: boolean;
|
isNormalDuty: boolean;
|
||||||
inDutyCnt: number;
|
inDutyCnt: number;
|
||||||
currentDuty: string;
|
currentDuty: string;
|
||||||
place: string;
|
otherDutyTime: Shift[];
|
||||||
|
offDutyReason: string;
|
||||||
|
dutyRecoverTime: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Info = {
|
||||||
|
dutyStatus: string;
|
||||||
|
inDutyCnt: number;
|
||||||
otherDutyTime: Shift[];
|
otherDutyTime: Shift[];
|
||||||
offDutyReason: string;
|
offDutyReason: string;
|
||||||
dutyRecoverTime: string;
|
dutyRecoverTime: string;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import { Info } from '@/pages/Admin/DutyInfo/info';
|
import { Info, ServerInfo } from '@/pages/Admin/DutyInfo/info';
|
||||||
import { Stat } from '@/pages/Welcome/stat';
|
import { Stat } from '@/pages/Welcome/stat';
|
||||||
import { request } from '@umijs/max';
|
import { request } from '@umijs/max';
|
||||||
import { API } from './typings';
|
import { API } from './typings';
|
||||||
|
|
@ -48,9 +48,18 @@ export async function getStat(options?: { [key: string]: any }) {
|
||||||
/** 获取当前值班信息 GET /admin/duty/current */
|
/** 获取当前值班信息 GET /admin/duty/current */
|
||||||
export async function getDutyInfo(options?: { [key: string]: any }) {
|
export async function getDutyInfo(options?: { [key: string]: any }) {
|
||||||
return request<{
|
return request<{
|
||||||
data: Info;
|
data: ServerInfo;
|
||||||
}>('/admin/duty/current', {
|
}>('/admin/duty/current', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
...(options || {}),
|
...(options || {}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 上传当前值班信息 POST /admin/duty/update */
|
||||||
|
export async function updateDutyInfo(body: Info, options?: { [key: string]: any }) {
|
||||||
|
return request<boolean | void>('/admin/duty/update', {
|
||||||
|
method: 'POST',
|
||||||
|
data: body,
|
||||||
|
...(options || {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue