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';
|
2024-05-29 04:44:23 -04:00
|
|
|
import React, {useEffect, useState} from "react";
|
2024-04-25 04:36:40 -04:00
|
|
|
import {
|
2024-05-29 04:44:23 -04:00
|
|
|
addTask, getTask,
|
2024-04-25 04:36:40 -04:00
|
|
|
getTaskTreeResult,
|
|
|
|
OPERATION_BUTTON_TYPE,
|
|
|
|
taskPriorityList,
|
|
|
|
taskStateList
|
2024-05-10 04:00:35 -04:00
|
|
|
} from "@/lib/task/project/data";
|
|
|
|
import {DataType} from "@/lib/definitions";
|
2024-05-29 04:44:23 -04:00
|
|
|
import dayjs, {Dayjs} from "dayjs";
|
2024-04-19 05:44:44 -04:00
|
|
|
|
|
|
|
export type DetailModelFormProps={
|
2024-05-29 04:44:23 -04:00
|
|
|
// 当前内容id
|
2024-04-19 05:44:44 -04:00
|
|
|
itemId?: number,
|
2024-05-29 04:44:23 -04:00
|
|
|
// 父任务id
|
2024-04-19 05:44:44 -04:00
|
|
|
pPid?:number,
|
2024-05-29 04:44:23 -04:00
|
|
|
// 操作id
|
2024-04-19 05:44:44 -04:00
|
|
|
operationId: number,
|
2024-05-29 04:44:23 -04:00
|
|
|
// 标题描述
|
2024-04-19 05:44:44 -04:00
|
|
|
description:string,
|
2024-05-29 04:44:23 -04:00
|
|
|
// 是否打开界面,用于非按钮操作
|
|
|
|
open:boolean,
|
|
|
|
// 使用按钮操作
|
|
|
|
haveButton:boolean,
|
|
|
|
expectedStartTime?:Dayjs,
|
|
|
|
expectedEndTime?:Dayjs,
|
|
|
|
// 重新加载数据
|
2024-04-25 04:36:40 -04:00
|
|
|
reloadData?: () => void
|
2024-04-19 05:44:44 -04:00
|
|
|
}
|
2024-04-25 23:17:44 -04:00
|
|
|
export type PidSelectTree= { label: string; value: number;pPid:number; children?: PidSelectTree[] }
|
2024-05-29 04:44:23 -04:00
|
|
|
|
2024-04-19 05:44:44 -04:00
|
|
|
export const DetailModelForm: React.FC<DetailModelFormProps> = (props) => {
|
2024-05-29 04:44:23 -04:00
|
|
|
console.log("DetailModelForm:props:",props,props.itemId!=undefined&&(
|
|
|
|
props.operationId === OPERATION_BUTTON_TYPE.DETAIL || props.operationId === OPERATION_BUTTON_TYPE.UPDATE))
|
2024-04-24 01:54:59 -04:00
|
|
|
const [form] = Form.useForm<DataType>();
|
2024-04-25 23:17:44 -04:00
|
|
|
const [pPid, setPPid] = useState<number>(0);
|
2024-05-29 04:44:23 -04:00
|
|
|
useEffect(() => {
|
|
|
|
if (props.itemId!=undefined&&(
|
|
|
|
props.operationId === OPERATION_BUTTON_TYPE.DETAIL || props.operationId === OPERATION_BUTTON_TYPE.UPDATE)) {
|
|
|
|
getTask(props.itemId).then(task => {
|
|
|
|
console.log('DetailModelForm:getTask(props.itemId)', props.itemId, task);
|
|
|
|
if (task.status.success) {
|
|
|
|
// setTaskMessage(task.data)
|
|
|
|
task.data.state = taskStateList.find(taskState => taskState.code === task.data.state?.toString())?.name;
|
|
|
|
task.data.priority = taskPriorityList.find(taskPriority => taskPriority.code === task.data.priority?.toString())?.name;
|
|
|
|
task.data.actualTimeRange = [task.data.actualStartTime ? dayjs(task.data.actualStartTime) : undefined,
|
|
|
|
task.data.actualEndTime ? dayjs(task.data.actualEndTime) : undefined];
|
|
|
|
task.data.expectedTimeRange = [task.data.expectedStartTime ? dayjs(task.data.expectedStartTime) : undefined,
|
|
|
|
task.data.expectedEndTime ? dayjs(task.data.expectedEndTime) : undefined];
|
|
|
|
form.setFieldsValue(task.data)
|
|
|
|
} else {
|
|
|
|
message.error(task.status.message);
|
|
|
|
props.reloadData?.()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}else if(props.operationId === OPERATION_BUTTON_TYPE.ADD|| props.operationId === OPERATION_BUTTON_TYPE.ADD_CHILD){
|
|
|
|
let data={'expectedTimeRange':[props.expectedStartTime?props.expectedStartTime:dayjs(), props.expectedEndTime]};
|
|
|
|
form.setFieldsValue(data)
|
|
|
|
}
|
|
|
|
}, [props])
|
2024-04-24 01:54:59 -04:00
|
|
|
function childReduce(child:DataType[]):PidSelectTree[]{
|
|
|
|
const result:PidSelectTree[] = [];
|
|
|
|
child.map(data=> {
|
2024-04-25 23:17:44 -04:00
|
|
|
const resultData:PidSelectTree = {label:data.name,value:data.id,pPid:data.pPid};
|
2024-04-24 01:54:59 -04:00
|
|
|
if (data.children){
|
|
|
|
resultData.children=childReduce(data.children);
|
|
|
|
}
|
|
|
|
result.push(resultData);
|
|
|
|
})
|
|
|
|
return result;
|
|
|
|
}
|
2024-05-29 04:44:23 -04:00
|
|
|
// 如果不是添加任务需要回显
|
2024-04-19 05:44:44 -04:00
|
|
|
return (
|
2024-04-24 01:54:59 -04:00
|
|
|
<ModalForm<DataType>
|
2024-05-29 04:44:23 -04:00
|
|
|
title={props.description}
|
|
|
|
open={props.open&&!props.haveButton}
|
|
|
|
trigger={props.haveButton?
|
2024-04-19 05:44:44 -04:00
|
|
|
<Button type="primary">
|
|
|
|
<PlusOutlined />
|
|
|
|
{props.description}
|
2024-05-29 04:44:23 -04:00
|
|
|
</Button>:undefined
|
2024-04-19 05:44:44 -04:00
|
|
|
}
|
|
|
|
form={form}
|
|
|
|
autoFocusFirstInput
|
|
|
|
modalProps={{
|
|
|
|
destroyOnClose: true,
|
2024-05-29 04:44:23 -04:00
|
|
|
onCancel: () => {
|
|
|
|
console.log('run');
|
|
|
|
props.reloadData?.();
|
|
|
|
},
|
2024-04-19 05:44:44 -04:00
|
|
|
}}
|
|
|
|
onFinish={async (values) => {
|
2024-04-25 23:17:44 -04:00
|
|
|
console.log('Received values of form: ', values);
|
|
|
|
if (values.pid===undefined){
|
|
|
|
values.pid=0
|
|
|
|
}
|
|
|
|
if (values.expectedTimeRange?.[0]!=undefined) {
|
|
|
|
values.expectedStartTime=dayjs(values.expectedTimeRange[0]).toDate()
|
|
|
|
}
|
|
|
|
if (values.expectedTimeRange?.[1]!=undefined) {
|
|
|
|
values.expectedEndTime=dayjs(values.expectedTimeRange[1]).toDate()
|
|
|
|
}
|
|
|
|
if (values.actualTimeRange?.[0]!=undefined) {
|
|
|
|
values.actualStartTime=dayjs(values.actualTimeRange[0]).toDate()
|
|
|
|
}
|
|
|
|
if (values.actualTimeRange?.[1]!=undefined) {
|
|
|
|
values.actualEndTime=dayjs(values.actualTimeRange[1]).toDate()
|
|
|
|
}
|
|
|
|
values.pPid=pPid;
|
|
|
|
var result:boolean=false;
|
2024-05-30 05:55:55 -04:00
|
|
|
// todo 修改
|
2024-04-25 23:17:44 -04:00
|
|
|
await addTask(values).then(response => {
|
2024-04-25 04:36:40 -04:00
|
|
|
console.log('response', response)
|
|
|
|
if (response.status.success) {
|
|
|
|
message.success("添加任务成功:" + response.data)
|
|
|
|
// 树任务重新刷新
|
|
|
|
// 四象限任务重新刷新
|
|
|
|
// 如果可以直接更新列表而不请求。。。。。。
|
|
|
|
console.log('props.reloadData?.()',props.reloadData)
|
|
|
|
props.reloadData?.()
|
2024-04-25 23:17:44 -04:00
|
|
|
result= true
|
|
|
|
}else {
|
|
|
|
message.error(response.status.message)
|
|
|
|
result= false
|
2024-04-25 04:36:40 -04:00
|
|
|
}
|
|
|
|
}
|
2024-04-25 23:17:44 -04:00
|
|
|
);
|
|
|
|
return result;
|
2024-04-19 05:44:44 -04:00
|
|
|
}}
|
|
|
|
>
|
2024-04-25 04:36:40 -04:00
|
|
|
<ProFormText width="sm" name="id" hidden={true} label="主键" />
|
2024-05-29 04:44:23 -04:00
|
|
|
<ProFormText width="sm" name="code" initialValue={props.itemId} hidden={true} label="任务编码" />
|
2024-04-25 04:36:40 -04:00
|
|
|
<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="父级任务"
|
2024-04-25 23:17:44 -04:00
|
|
|
fieldProps={{onSelect: (e,node) => {console.log('onSelect',e,node);setPPid(node.pPid)}}}
|
2024-04-24 01:54:59 -04:00
|
|
|
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-25 23:17:44 -04:00
|
|
|
initialValue={[dayjs(), undefined]}
|
2024-04-24 01:54:59 -04:00
|
|
|
name="expectedTimeRange"
|
|
|
|
label="期望时间"
|
2024-04-25 23:17:44 -04:00
|
|
|
fieldProps={{allowEmpty:[true, true],showTime:true,needConfirm:false}}
|
2024-04-25 04:36:40 -04:00
|
|
|
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 23:17:44 -04:00
|
|
|
fieldProps={ {allowEmpty:[true, true],showTime:true,needConfirm:false}}
|
2024-04-25 04:36:40 -04:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
};
|