2024-12-29 08:14:08 -05:00
|
|
|
import {Card, Dialog, Image, InfiniteScroll, List, PullToRefresh, SwipeAction} from 'antd-mobile'
|
2024-12-29 04:48:35 -05:00
|
|
|
import React, {Fragment, useEffect, useRef, useState} from 'react'
|
2024-12-27 06:06:20 -05:00
|
|
|
import {
|
|
|
|
DragDropContext,
|
|
|
|
Draggable,
|
|
|
|
Droppable,
|
|
|
|
// DropResult,
|
|
|
|
} from 'react-beautiful-dnd'
|
|
|
|
import {getTaskList} from "../../utils";
|
|
|
|
import "./index.css"
|
|
|
|
|
|
|
|
const reorder = (
|
|
|
|
list,
|
|
|
|
startIndex,
|
|
|
|
endIndex
|
|
|
|
) => {
|
|
|
|
const result = Array.from(list)
|
|
|
|
const [removed] = result.splice(startIndex, 1)
|
|
|
|
result.splice(endIndex, 0, removed)
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
const ToDoList = () => {
|
|
|
|
const [taskList, setTaskList] = useState([])
|
2024-12-29 04:48:35 -05:00
|
|
|
const [hasMore, setHasMore] = useState(true)
|
|
|
|
const [pageNumber, setPageNumber] = useState(1)
|
2024-12-29 08:14:08 -05:00
|
|
|
|
2024-12-29 04:48:35 -05:00
|
|
|
async function loadMore() {
|
2024-12-29 08:14:08 -05:00
|
|
|
getTaskList(pageNumber+1).then(result => {
|
2024-12-29 04:48:35 -05:00
|
|
|
setTaskList(val => [...val, ...result.data.data.content])
|
|
|
|
setHasMore(result.data.data.content.length > 0)
|
|
|
|
})
|
2024-12-29 08:14:08 -05:00
|
|
|
setPageNumber(pageNumber + 1)
|
2024-12-29 04:48:35 -05:00
|
|
|
}
|
2024-12-29 08:14:08 -05:00
|
|
|
|
2024-12-27 06:06:20 -05:00
|
|
|
useEffect(() => {
|
2024-12-29 04:48:35 -05:00
|
|
|
getTaskList(pageNumber).then(result => {
|
2024-12-27 06:06:20 -05:00
|
|
|
setTaskList(result.data.data.content)
|
|
|
|
})
|
|
|
|
}, [])
|
|
|
|
const onDragEnd = (result) => {
|
|
|
|
if (!result.destination) return
|
|
|
|
const newList = reorder(taskList, result.source.index, result.destination.index)
|
|
|
|
setTaskList([...newList])
|
|
|
|
}
|
|
|
|
const ref = useRef(null)
|
|
|
|
return (
|
2024-12-29 04:48:35 -05:00
|
|
|
<Fragment>
|
|
|
|
<PullToRefresh
|
|
|
|
onRefresh={async () => {
|
|
|
|
getTaskList(1).then(result => {
|
|
|
|
console.log("getTaskList()", result)
|
|
|
|
setTaskList(result.data.data.content)
|
2024-12-29 08:14:08 -05:00
|
|
|
setPageNumber(1)
|
2024-12-29 04:48:35 -05:00
|
|
|
setHasMore(true)
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
>
|
2024-12-29 08:14:08 -05:00
|
|
|
<List
|
|
|
|
// header='任务清单'
|
|
|
|
>
|
|
|
|
<DragDropContext onDragEnd={onDragEnd}>
|
|
|
|
<Droppable droppableId='droppable'>
|
|
|
|
{droppableProvided => (
|
|
|
|
<div ref={droppableProvided.innerRef}>
|
|
|
|
{taskList.map((item, index) => (
|
|
|
|
<Draggable key={item.id} draggableId={item.id} index={index}>
|
|
|
|
{(provided, snapshot) => (
|
|
|
|
<div
|
|
|
|
ref={provided.innerRef}
|
|
|
|
{...provided.draggableProps}
|
|
|
|
{...provided.dragHandleProps}
|
|
|
|
style={{
|
|
|
|
...provided.draggableProps.style,
|
|
|
|
opacity: snapshot.isDragging ? 0.8 : 1,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<SwipeAction
|
|
|
|
ref={ref}
|
|
|
|
closeOnAction={false}
|
|
|
|
closeOnTouchOutside={false}
|
|
|
|
rightActions={[
|
|
|
|
{
|
|
|
|
key: 'delete',
|
|
|
|
text: '删除',
|
|
|
|
color: 'danger',
|
|
|
|
onClick: async () => {
|
|
|
|
await Dialog.confirm({
|
|
|
|
content: '确定要关闭吗?',
|
|
|
|
})
|
|
|
|
ref.current?.close()
|
|
|
|
},
|
2024-12-29 04:48:35 -05:00
|
|
|
},
|
2024-12-29 08:14:08 -05:00
|
|
|
{
|
|
|
|
key: 'close',
|
|
|
|
text: '关闭',
|
|
|
|
color: 'warning',
|
|
|
|
onClick: async () => {
|
|
|
|
await Dialog.confirm({
|
|
|
|
content: '确定要关闭吗?',
|
|
|
|
})
|
|
|
|
ref.current?.close()
|
|
|
|
},
|
2024-12-29 04:48:35 -05:00
|
|
|
},
|
2024-12-29 08:14:08 -05:00
|
|
|
{
|
|
|
|
key: 'update',
|
|
|
|
text: '修改',
|
|
|
|
color: 'primary',
|
|
|
|
onClick: async () => {
|
|
|
|
await Dialog.confirm({
|
|
|
|
content: '确定要修改吗?',
|
|
|
|
})
|
|
|
|
ref.current?.close()
|
|
|
|
},
|
2024-12-29 04:48:35 -05:00
|
|
|
},
|
2024-12-29 08:14:08 -05:00
|
|
|
{
|
|
|
|
key: 'complete',
|
|
|
|
text: '完成',
|
|
|
|
color: 'success',
|
|
|
|
onClick: async () => {
|
|
|
|
await Dialog.confirm({
|
|
|
|
content: '确定要完成吗?',
|
|
|
|
})
|
|
|
|
ref.current?.close()
|
|
|
|
},
|
2024-12-29 04:48:35 -05:00
|
|
|
},
|
2024-12-29 08:14:08 -05:00
|
|
|
]}
|
|
|
|
>
|
|
|
|
<List.Item
|
|
|
|
key={item.id}
|
|
|
|
// prefix={
|
|
|
|
// <Image
|
|
|
|
// src={item.avatar}
|
|
|
|
// style={{ borderRadius: 20 }}
|
|
|
|
// fit='cover'
|
|
|
|
// width={40}
|
|
|
|
// height={40}
|
|
|
|
// />
|
|
|
|
// }
|
|
|
|
// title={<span style={{color: "red"}}>{item.name}</span>}
|
|
|
|
// children={item.description}
|
|
|
|
// description={item.state}
|
|
|
|
// onClick={
|
|
|
|
// () => {
|
|
|
|
// console.log("dianji")
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
title={
|
|
|
|
<div style={{
|
|
|
|
display: "flex",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
alignItems: "center",
|
|
|
|
flexDirection: "row",
|
|
|
|
flexWrap: "nowrap",
|
|
|
|
fontSize: "large",
|
|
|
|
color: "black"
|
|
|
|
}}>
|
|
|
|
<span>{item.name}</span>
|
|
|
|
{item.expectedEndTime && <span>
|
|
|
|
结束时间:{item.expectedEndTime}</span>}
|
|
|
|
</div>}
|
|
|
|
description={item.description}
|
|
|
|
>
|
|
|
|
{/*<Card style={{width: "100%"}} title={*/}
|
|
|
|
{/* <div style={{*/}
|
|
|
|
{/* display: "flex",*/}
|
|
|
|
{/* justifyContent: "space-between",*/}
|
|
|
|
{/* alignItems: "center",*/}
|
|
|
|
{/* flexDirection: "row",*/}
|
|
|
|
{/* flexWrap: "nowrap"*/}
|
|
|
|
{/* }}>*/}
|
|
|
|
{/* <span>{item.name}</span>*/}
|
|
|
|
{/* {item.expectedEndTime && <span>*/}
|
|
|
|
{/* 结束时间:{item.expectedEndTime}</span>}*/}
|
|
|
|
|
|
|
|
{/* </div>}*/}
|
|
|
|
{/*>*/}
|
|
|
|
{/* {item.description}*/}
|
|
|
|
{/*</Card>*/}
|
|
|
|
</List.Item>
|
|
|
|
</SwipeAction>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Draggable>
|
|
|
|
))}
|
|
|
|
{droppableProvided.placeholder}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Droppable>
|
|
|
|
</DragDropContext>
|
|
|
|
</List>
|
|
|
|
<InfiniteScroll loadMore={loadMore} hasMore={hasMore}/>
|
2024-12-29 04:48:35 -05:00
|
|
|
</PullToRefresh>
|
|
|
|
</Fragment>
|
2024-12-27 06:06:20 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
export default ToDoList;
|