From 8f062b0e8cacdcd43fc614f3d7df1731cb6fae70 Mon Sep 17 00:00:00 2001 From: Dawn1Ocean <1785590531@qq.com> Date: Tue, 7 May 2024 19:49:48 +0800 Subject: [PATCH] add dutyinfo page --- doc/api.md | 4 +- mock/requestRecord.mock.js | 17 +- src/pages/Admin/DutyInfo/index.tsx | 246 ++++++++++++++++++----------- src/pages/Admin/DutyInfo/info.ts | 15 +- src/services/api.ts | 13 +- 5 files changed, 194 insertions(+), 101 deletions(-) diff --git a/doc/api.md b/doc/api.md index 1c730d0..8d286b9 100644 --- a/doc/api.md +++ b/doc/api.md @@ -65,7 +65,7 @@ data: ```json { "isNormalDuty": true, // 判断是否是正常值班时间 - "currentDuty": "1", // 判断是否正在值班 / 值哪一班 "1" | "2" | "3" => 正在值班,"off" => 值班下班 + "currentDuty": "1", // 判断是否正在值班 / 值哪一班 "1" | "2" | "3" => 正在值班,"off" => 暂停值班, "0" => 值班下班 "inDutyCnt": 3, "otherDutyTime": [], // 正常值班时为空 "offDutyReason": "", @@ -81,7 +81,7 @@ data: ```json { "isNormalDuty": false, // 判断是否是正常值班时间 - "currentDuty": "others", // 判断是否正在值班 / 值哪一班 "others" => 正在值班,"off" => 值班下班 + "currentDuty": "others", // 判断是否正在值班 / 值哪一班 "others" => 正在值班,"off" => 暂停值班, "0" => 值班下班 "inDutyCnt": 3, "otherDutyTime": [ { diff --git a/mock/requestRecord.mock.js b/mock/requestRecord.mock.js index 1d3e3fa..9637fdf 100644 --- a/mock/requestRecord.mock.js +++ b/mock/requestRecord.mock.js @@ -36,26 +36,31 @@ module.exports = { 'GET /admin/duty/current': { success: true, data: { - isNormalDuty: false, + isNormalDuty: true, currentDuty: 'off', inDutyCnt: 3, otherDutyTime: [ { - name: '第一班', + id: 1, + title: '第一班', + place: 'fsaf', 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'], }, { - name: '第三班', + id: 3, + title: '第三班', + place: 'fdshq', range: ['2024-03-07T19:52:48.523303', '2024-03-07T19:52:48.523303'], }, ], offDutyReason: '期中考试周', - place: '', - dutyRecoverTime: '下周一', + dutyRecoverTime: '2024-03-07T19:52:48.523303', }, }, 'POST /admin/duty/update': { diff --git a/src/pages/Admin/DutyInfo/index.tsx b/src/pages/Admin/DutyInfo/index.tsx index 347360d..c4960d3 100644 --- a/src/pages/Admin/DutyInfo/index.tsx +++ b/src/pages/Admin/DutyInfo/index.tsx @@ -1,33 +1,71 @@ -import { getDutyInfo } from '@/services/api'; +import { getDutyInfo, updateDutyInfo } from '@/services/api'; import { + EditableProTable, PageContainer, + ProColumns, ProForm, - ProFormDateTimeRangePicker, + ProFormDateTimePicker, + ProFormDependency, ProFormDigit, ProFormRadio, ProFormText, } from '@ant-design/pro-components'; -import { Card, Col, Row, Space, message } from 'antd'; +import { Card, message } from 'antd'; import { useEffect, useState } from 'react'; import { Info } from './info'; -const waitTime = (time: number = 100) => { - return new Promise((resolve) => { - setTimeout(() => { - resolve(true); - }, time); - }); +type Shift = { + id: React.Key; + title: string; + place: string; + range: string[]; }; +const columns: ProColumns[] = [ + { + 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, setDutyInfo] = useState(); const [loading, setLoading] = useState(true); const [messageApi, contextHolder] = message.useMessage(); + + const [editableKeys, setEditableRowKeys] = useState(() => []); + useEffect(() => { getDutyInfo() .then((res) => { - console.log(res.data); - setDutyInfo(res.data); + const data = 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); }) .catch((err) => { @@ -37,90 +75,122 @@ const DutyInfo: React.FC = () => { }); }); }, []); - // const [editableKeys, setEditableRowKeys] = useState(() => - // defaultData.map((item) => item.id), - // ); + return ( {contextHolder} {!loading && ( - - submitter={{ - render: (props, doms) => { - return ( - - - {doms} - - - ); - }, - }} - onFinish={async (values) => { - await waitTime(2000); - console.log(values); - message.success('提交成功'); - }} - initialValues={dutyInfo} - > - - - - - - - {/* - 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]; + + submitter={{ + resetButtonProps: { style: { display: 'none' } }, + submitButtonProps: { + style: { width: '31%' }, + }, + render: (_, doms) => { + return
{doms}
; }, }} - /> */} -
- - + onFinish={updateDutyInfo} + initialValues={dutyInfo} + > +
+ +
+
+ + {({ dutyStatus }) => { + if (dutyStatus === 'pause') { + return ( +
+ + +
+ ); + } + return ( + + ); + }} +
+
+ + {({ dutyStatus }) => { + if (dutyStatus === 'others') { + return ( +
+ + + rowKey="id" + toolBarRender={false} + columns={columns} + recordCreatorProps={{ + newRecordType: 'dataSource', + position: 'bottom', + creatorButtonText: '新建一个值班班次', + style: { width: '100%', margin: 'auto', marginTop: '2%' }, + record: () => ({ + id: Date.now(), + title: '', + place: '', + range: [], + }), + }} + editable={{ + type: 'multiple', + editableKeys, + onChange: setEditableRowKeys, + actionRender: (row, _, dom) => { + return [dom.delete]; + }, + }} + /> + +
+ ); + } + }} +
+ )}
diff --git a/src/pages/Admin/DutyInfo/info.ts b/src/pages/Admin/DutyInfo/info.ts index c7917e2..9febc44 100644 --- a/src/pages/Admin/DutyInfo/info.ts +++ b/src/pages/Admin/DutyInfo/info.ts @@ -1,13 +1,22 @@ export type Shift = { - name: string; + id: React.Key; + title: string; + place: string; range: string[]; }; -export type Info = { +export type ServerInfo = { isNormalDuty: boolean; inDutyCnt: number; currentDuty: string; - place: string; + otherDutyTime: Shift[]; + offDutyReason: string; + dutyRecoverTime: string; +} + +export type Info = { + dutyStatus: string; + inDutyCnt: number; otherDutyTime: Shift[]; offDutyReason: string; dutyRecoverTime: string; diff --git a/src/services/api.ts b/src/services/api.ts index 36a022e..6d9138c 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -1,6 +1,6 @@ // @ts-ignore /* eslint-disable */ -import { Info } from '@/pages/Admin/DutyInfo/info'; +import { Info, ServerInfo } from '@/pages/Admin/DutyInfo/info'; import { Stat } from '@/pages/Welcome/stat'; import { request } from '@umijs/max'; import { API } from './typings'; @@ -48,9 +48,18 @@ export async function getStat(options?: { [key: string]: any }) { /** 获取当前值班信息 GET /admin/duty/current */ export async function getDutyInfo(options?: { [key: string]: any }) { return request<{ - data: Info; + data: ServerInfo; }>('/admin/duty/current', { method: 'GET', ...(options || {}), }); } + +/** 上传当前值班信息 POST /admin/duty/update */ +export async function updateDutyInfo(body: Info, options?: { [key: string]: any }) { + return request('/admin/duty/update', { + method: 'POST', + data: body, + ...(options || {}), + }); +}