diff --git a/src/components/StepSort.tsx b/src/components/StepSort.tsx index 91c3424..889fad2 100644 --- a/src/components/StepSort.tsx +++ b/src/components/StepSort.tsx @@ -1,16 +1,9 @@ -import React, {CSSProperties, Fragment, useState} from "react"; +import React, {CSSProperties, Fragment, useEffect, useState} from "react"; import {DragDropContext, Droppable, Draggable, DropResult, DraggingStyle, NotDraggingStyle} from "react-beautiful-dnd"; import {TaskStepSortVO} from "@/components/type/TaskSort.d"; -import {Button, Drawer, Modal} from "antd"; +import {Button, Drawer, message, Modal} from "antd"; import TextArea from "antd/es/input/TextArea"; - -// fake data generator -const getItems = (count: number, offset = 0) => - Array.from({length: count}, (v, k) => k).map(k => ({ - id: `item-${k + offset}-${new Date().getTime()}`, - stepDesc: `item ${k + offset}`, - sortIndex: k + offset, - })); +import {addStepItemAPI} from "@/components/service/StepSort"; const reorder = (list: TaskStepSortVO[], startIndex: number, endIndex: number) => { const result = Array.from(list); @@ -34,11 +27,23 @@ const getListStyle = (isDraggingOver: boolean) => ({ width: "100%" }); -const StepSort = (props: { taskId: string }) => { - const [state, setState] = useState(getItems(5, 10)); +const StepSort = (props: { taskId: string, stepList: TaskStepSortVO[] }) => { + const [state, setState] = useState(props.stepList); // 抽屉 start const [open, setOpen] = useState(false); const [dialogueOpen, setDialogueOpen] = useState(false); + const [sortItemList, setSortItemList] = useState([]); + const [modalText, setModalText] = useState({ + id: "", + stepDesc: undefined, + sortIndex: undefined, + taskId: props.taskId, + }); + + useEffect(() => { + // 根据任务id查找步骤 + + }, []); function onDragEnd(result: DropResult) { const {source, destination} = result; @@ -50,16 +55,64 @@ const StepSort = (props: { taskId: string }) => { let newState = [...state]; newState = items; setState(newState); + props.stepList.length=0 + props.stepList.push(...newState) + } + + const [confirmButtonLoading, setConfirmButtonLoading] = useState(false); + const confirmModalTextArea = () => { + setConfirmButtonLoading(true) + addStepItemAPI(modalText).then(res => { + if (res.data.status.success) { + message.info("添加步骤成功") + setModalText( + {...modalText, stepDesc: undefined}) + setState([...state, res.data.data]) + props.stepList.length=0 + props.stepList.push(...state, res.data.data) + setDialogueOpen(false); + } else { + message.error(res.data.status.message) + } + }).finally(()=>{ + setConfirmButtonLoading(false) + }) } return ( - { + setDialogueOpen(false); + } + } + destroyOnClose={true} + onOk={confirmModalTextArea} > -