2024-04-12 06:43:55 -04:00
|
|
|
import React, {Fragment} from "react";
|
2024-04-16 04:11:21 -04:00
|
|
|
import {Button, Dropdown, MenuProps, message, Modal, Popconfirm, Space} from "antd";
|
2024-04-12 06:43:55 -04:00
|
|
|
import {DownOutlined, QuestionCircleOutlined} from "@ant-design/icons";
|
|
|
|
import {DetailForm} from "@/app/ui/task/project/DetailForm";
|
2024-04-16 04:11:21 -04:00
|
|
|
import {deleteTask, OPERATION_BUTTON_TYPE} from "@/app/lib/task/project/data";
|
2024-04-12 06:43:55 -04:00
|
|
|
|
|
|
|
export interface OperationButtonProps {
|
2024-04-16 04:11:21 -04:00
|
|
|
itemId: number,
|
|
|
|
pid: number,
|
|
|
|
pPid: number,
|
|
|
|
operationId?: string,
|
|
|
|
refreshDate?: () => void
|
2024-04-12 06:43:55 -04:00
|
|
|
}
|
2024-04-16 04:11:21 -04:00
|
|
|
|
2024-04-12 06:43:55 -04:00
|
|
|
interface OperationModelProps {
|
2024-04-16 04:11:21 -04:00
|
|
|
operationId: number | undefined,
|
|
|
|
pPid:number,
|
|
|
|
pid: number,
|
|
|
|
openModal: boolean
|
2024-04-12 06:43:55 -04:00
|
|
|
}
|
2024-04-16 04:11:21 -04:00
|
|
|
|
|
|
|
class OperationButton extends React.Component<OperationButtonProps, OperationModelProps> {
|
2024-04-12 06:43:55 -04:00
|
|
|
|
|
|
|
constructor(props: OperationButtonProps) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2024-04-16 04:11:21 -04:00
|
|
|
pid: props.pid,
|
|
|
|
pPid: props.pPid,
|
|
|
|
operationId: undefined,
|
|
|
|
openModal: false
|
2024-04-12 06:43:55 -04:00
|
|
|
};
|
|
|
|
}
|
2024-04-16 04:11:21 -04:00
|
|
|
|
2024-04-12 06:43:55 -04:00
|
|
|
render() {
|
2024-04-16 04:11:21 -04:00
|
|
|
const handleCancel = () => {
|
|
|
|
this.setState({...this.state, openModal: false})
|
|
|
|
if (this.state.operationId !== OPERATION_BUTTON_TYPE.DETAIL) {
|
|
|
|
this.props.refreshDate?.()
|
|
|
|
}
|
2024-04-12 06:43:55 -04:00
|
|
|
}
|
2024-04-16 04:11:21 -04:00
|
|
|
const onClick: MenuProps['onClick'] = ({key}) => {
|
|
|
|
console.log(key)
|
|
|
|
};
|
2024-04-12 06:43:55 -04:00
|
|
|
const items: MenuProps['items'] = [
|
|
|
|
{
|
2024-04-16 04:11:21 -04:00
|
|
|
key: OPERATION_BUTTON_TYPE.DETAIL,
|
2024-04-12 06:43:55 -04:00
|
|
|
label: <a onClick={(e) => {
|
2024-04-16 04:11:21 -04:00
|
|
|
this.setState({openModal: true, operationId: OPERATION_BUTTON_TYPE.DETAIL})
|
|
|
|
}}>任务详情</a>,
|
2024-04-12 06:43:55 -04:00
|
|
|
},
|
|
|
|
{
|
2024-04-16 04:11:21 -04:00
|
|
|
key: OPERATION_BUTTON_TYPE.ADD_CHILD,
|
2024-04-12 06:43:55 -04:00
|
|
|
label: <a onClick={(e) => {
|
2024-04-16 04:11:21 -04:00
|
|
|
this.setState({openModal: true, operationId: OPERATION_BUTTON_TYPE.ADD_CHILD})
|
|
|
|
}}>添加支线任务</a>,
|
2024-04-12 06:43:55 -04:00
|
|
|
},
|
|
|
|
{
|
2024-04-16 04:11:21 -04:00
|
|
|
key: OPERATION_BUTTON_TYPE.UPDATE,
|
2024-04-12 06:43:55 -04:00
|
|
|
label: <a onClick={(e) => {
|
2024-04-16 04:11:21 -04:00
|
|
|
this.setState({openModal: true, operationId: OPERATION_BUTTON_TYPE.UPDATE})
|
|
|
|
}}>修改任务</a>,
|
2024-04-12 06:43:55 -04:00
|
|
|
}
|
|
|
|
,
|
|
|
|
{
|
2024-04-16 04:11:21 -04:00
|
|
|
key: OPERATION_BUTTON_TYPE.DELETE,
|
2024-04-12 06:43:55 -04:00
|
|
|
label: <Popconfirm
|
|
|
|
title="删除任务"
|
|
|
|
description="确认要删除任务?"
|
|
|
|
icon={<QuestionCircleOutlined style={{color: 'red'}}/>}
|
|
|
|
okText="确认"
|
|
|
|
cancelText="取消"
|
2024-04-16 04:11:21 -04:00
|
|
|
onConfirm={() => {
|
|
|
|
deleteTask(this.props.itemId).then((response => {
|
|
|
|
console.log('response', response)
|
|
|
|
if (response.status.success) {
|
|
|
|
message.success("删除任务成功:" + response.data)
|
|
|
|
this.props.refreshDate?.()
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}}
|
|
|
|
><a>删除任务</a></Popconfirm>,
|
|
|
|
},
|
2024-04-12 06:43:55 -04:00
|
|
|
{
|
2024-04-16 04:11:21 -04:00
|
|
|
key: OPERATION_BUTTON_TYPE.COMPLETE,
|
2024-04-12 06:43:55 -04:00
|
|
|
label: <Popconfirm
|
|
|
|
title="完成任务"
|
|
|
|
description="确认要完成任务?"
|
|
|
|
okText="确认"
|
|
|
|
cancelText="取消"
|
2024-04-16 04:11:21 -04:00
|
|
|
><a>完成任务</a></Popconfirm>,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: OPERATION_BUTTON_TYPE.SHOW_FOUR,
|
|
|
|
label: <a>四象限显示子任务</a>,
|
2024-04-12 06:43:55 -04:00
|
|
|
}
|
|
|
|
];
|
|
|
|
return <Fragment>
|
2024-04-16 04:11:21 -04:00
|
|
|
<Dropdown menu={{items, onClick}}>
|
2024-04-12 06:43:55 -04:00
|
|
|
<a onClick={(e) => {
|
|
|
|
e.preventDefault()
|
|
|
|
}}>
|
|
|
|
<Space>
|
|
|
|
操作<DownOutlined/>
|
|
|
|
</Space>
|
|
|
|
</a>
|
|
|
|
</Dropdown>
|
|
|
|
<Modal
|
2024-04-16 04:11:21 -04:00
|
|
|
maskClosable={false}
|
|
|
|
destroyOnClose={true}
|
2024-04-12 06:43:55 -04:00
|
|
|
open={this.state.openModal}
|
2024-04-16 04:11:21 -04:00
|
|
|
title={this.state.operationId === OPERATION_BUTTON_TYPE.DETAIL ? '任务详情' :
|
|
|
|
this.state.operationId === OPERATION_BUTTON_TYPE.ADD_CHILD ? '添加支线任务' :
|
|
|
|
this.state.operationId === OPERATION_BUTTON_TYPE.UPDATE ? '修改任务' : '未知操作'}
|
2024-04-12 06:43:55 -04:00
|
|
|
// open={open}
|
|
|
|
// onOk={handleOk}
|
|
|
|
onCancel={handleCancel}
|
2024-04-16 04:11:21 -04:00
|
|
|
footer={[]}
|
|
|
|
width={800}
|
2024-04-12 06:43:55 -04:00
|
|
|
// footer={[
|
|
|
|
// <Button key="back" onClick={handleCancel}>
|
|
|
|
// Return
|
|
|
|
// </Button>,
|
|
|
|
// <Button key="submit" type="primary" loading={loading} onClick={handleOk}>
|
|
|
|
// Submit
|
|
|
|
// </Button>,
|
|
|
|
// <Button
|
|
|
|
// key="link"
|
|
|
|
// href="https://google.com"
|
|
|
|
// type="primary"
|
|
|
|
// loading={loading}
|
|
|
|
// onClick={handleOk}
|
|
|
|
// >
|
|
|
|
// Search on Google
|
|
|
|
// </Button>,
|
|
|
|
// ]}
|
|
|
|
>
|
2024-04-16 04:11:21 -04:00
|
|
|
<DetailForm itemId={this.props.itemId}
|
|
|
|
operationId={this.state.operationId}
|
|
|
|
handleCancel={handleCancel}
|
|
|
|
pPid={this.props.pPid}
|
|
|
|
/>
|
2024-04-12 06:43:55 -04:00
|
|
|
</Modal>
|
|
|
|
</Fragment>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default OperationButton;
|