assistant-todo/src/app/ui/task/project/DetailModelForm.tsx

160 lines
6.2 KiB
TypeScript
Raw Normal View History

2024-04-19 05:44:44 -04:00
import { PlusOutlined } from '@ant-design/icons';
import {
ModalForm,
ProForm,
2024-04-25 04:36:40 -04:00
ProFormDateRangePicker, ProFormDateTimeRangePicker,
2024-04-19 05:44:44 -04:00
ProFormSelect,
2024-04-24 01:54:59 -04:00
ProFormText, ProFormTextArea, ProFormTreeSelect,
2024-04-19 05:44:44 -04:00
} from '@ant-design/pro-components';
import { Button, Form, message } from 'antd';
import React from "react";
2024-04-25 04:36:40 -04:00
import {
addTask,
getTaskTreeResult,
OPERATION_BUTTON_TYPE,
taskPriorityList,
taskStateList
} from "@/app/lib/task/project/data";
2024-04-24 01:54:59 -04:00
import {DataType} from "@/app/lib/definitions";
2024-04-25 04:36:40 -04:00
import dayjs from "dayjs";
2024-04-19 05:44:44 -04:00
export type DetailModelFormProps={
itemId?: number,
pPid?:number,
operationId: number,
description:string,
2024-04-25 04:36:40 -04:00
reloadData?: () => void
2024-04-19 05:44:44 -04:00
}
2024-04-24 01:54:59 -04:00
export type PidSelectTree= { label: string; value: number; children?: PidSelectTree[] }
2024-04-19 05:44:44 -04:00
export const DetailModelForm: React.FC<DetailModelFormProps> = (props) => {
2024-04-24 01:54:59 -04:00
const [form] = Form.useForm<DataType>();
function childReduce(child:DataType[]):PidSelectTree[]{
const result:PidSelectTree[] = [];
child.map(data=> {
const resultData:PidSelectTree = {label:data.name,value:data.id};
if (data.children){
resultData.children=childReduce(data.children);
}
result.push(resultData);
})
return result;
}
2024-04-19 05:44:44 -04:00
return (
2024-04-24 01:54:59 -04:00
<ModalForm<DataType>
2024-04-19 05:44:44 -04:00
title={
props.operationId === OPERATION_BUTTON_TYPE.DETAIL ? "任务详情":
props.operationId === OPERATION_BUTTON_TYPE.ADD?"添加任务":
props.operationId === OPERATION_BUTTON_TYPE.ADD?"修改任务":''
}
trigger={
<Button type="primary">
<PlusOutlined />
{props.description}
</Button>
}
form={form}
autoFocusFirstInput
modalProps={{
destroyOnClose: true,
onCancel: () => console.log('run'),
}}
2024-04-24 01:54:59 -04:00
// submitTimeout={2000}
2024-04-19 05:44:44 -04:00
onFinish={async (values) => {
2024-04-25 04:36:40 -04:00
addTask(values).then(response => {
console.log('response', response)
if (response.status.success) {
message.success("添加任务成功:" + response.data)
// 树任务重新刷新
// 四象限任务重新刷新
// 如果可以直接更新列表而不请求。。。。。。
console.log('props.reloadData?.()',props.reloadData)
props.reloadData?.()
}
}
)
2024-04-19 05:44:44 -04:00
return true;
}}
>
2024-04-25 04:36:40 -04:00
<ProFormText width="sm" name="id" hidden={true} label="主键" />
<ProFormText width="sm" name="code" hidden={true} label="任务编码" />
<ProFormText width="sm" name="pPid" initialValue={props.pPid} hidden={true} label="祖宗id" />
2024-04-19 05:44:44 -04:00
<ProForm.Group>
2024-04-24 01:54:59 -04:00
<ProFormTreeSelect
2024-04-19 05:44:44 -04:00
width="md"
2024-04-24 01:54:59 -04:00
request={() =>{
return getTaskTreeResult(JSON.stringify(
{pageSize:1000,pageNumber:1,data:[{code:'pid',value:'0',operateType:'='},{code:'',value:true,operateType: "TREE"}]}
)).then(result=> childReduce(result.data.content))
}}
name="pid"
label="父级任务"
disabled ={props.operationId === OPERATION_BUTTON_TYPE.DETAIL}
2024-04-19 05:44:44 -04:00
/>
<ProFormText
width="md"
2024-04-24 01:54:59 -04:00
name="name"
label="任务名称"
tooltip="最长为 24 位"
placeholder="请输入任务名称"
disabled ={props.operationId === OPERATION_BUTTON_TYPE.DETAIL}
2024-04-19 05:44:44 -04:00
/>
</ProForm.Group>
2024-04-24 01:54:59 -04:00
<ProFormTextArea
// width="md"
name="description"
label="任务描述"
// tooltip="最长为 24 位"
placeholder="请输入任务描述"
disabled ={props.operationId === OPERATION_BUTTON_TYPE.DETAIL}
/>
2024-04-19 05:44:44 -04:00
<ProForm.Group>
2024-04-24 01:54:59 -04:00
<ProFormSelect
request={async () => taskPriorityList.map(taskState => {
return {
'label': taskState.name,
'value': taskState.code
}
})}
width="sm"
name="priority"
label="任务优先级"
2024-04-25 04:36:40 -04:00
initialValue='3'
2024-04-24 01:54:59 -04:00
disabled ={props.operationId === OPERATION_BUTTON_TYPE.DETAIL}
/>
<ProFormSelect
width="sm"
options={taskStateList.map(taskState => {
return {
'label': taskState.name,
'value': taskState.code
}
})}
name="state"
label="任务状态"
2024-04-25 04:36:40 -04:00
initialValue='8'
2024-04-24 01:54:59 -04:00
disabled ={props.operationId === OPERATION_BUTTON_TYPE.DETAIL}
2024-04-19 05:44:44 -04:00
/>
</ProForm.Group>
2024-04-24 01:54:59 -04:00
2024-04-19 05:44:44 -04:00
<ProForm.Group>
2024-04-25 04:36:40 -04:00
<ProFormDateTimeRangePicker
2024-04-24 01:54:59 -04:00
name="expectedTimeRange"
label="期望时间"
2024-04-25 04:36:40 -04:00
fieldProps={{allowEmpty:[true, true],defaultValue:[dayjs(), undefined]}}
placeholder={['开始时间','结束时间']}
2024-04-24 01:54:59 -04:00
disabled ={props.operationId === OPERATION_BUTTON_TYPE.DETAIL}
2024-04-19 05:44:44 -04:00
/>
2024-04-25 04:36:40 -04:00
<ProFormDateTimeRangePicker
2024-04-24 01:54:59 -04:00
name="actualTimeRange"
label="实际时间"
2024-04-25 04:36:40 -04:00
fieldProps={ {allowEmpty:[true, true]}}
placeholder={['开始时间','结束时间']}
2024-04-24 01:54:59 -04:00
disabled ={props.operationId === OPERATION_BUTTON_TYPE.DETAIL}
2024-04-19 05:44:44 -04:00
/>
</ProForm.Group>
2024-04-24 01:54:59 -04:00
2024-04-19 05:44:44 -04:00
</ModalForm>
);
};