assistant-todo-mobile/src/pages/TaskCount/index.js

132 lines
5.2 KiB
JavaScript
Raw Normal View History

2025-01-15 06:35:44 -05:00
import React, {Fragment, useContext, useEffect, useMemo} from "react";
2025-01-05 05:04:52 -05:00
import {getTaskCount} from "../../utils";
import dayjs from "dayjs";
2025-01-17 06:21:37 -05:00
import {DATE_FORMAT, dayStartUtcFormat, nextDayStartUtcFormat} from "../../utils/timeFormatUtil";
2025-01-06 05:54:22 -05:00
import {getDictionary} from "../../utils/dictUtil";
import {Tag} from "antd-mobile";
2025-01-13 06:33:16 -05:00
import {useNavigate} from "react-router-dom";
2025-01-15 06:35:44 -05:00
import {MyRootContext, UPDATE_SEARCH} from "../../components/MyRootContext";
2025-01-06 05:54:22 -05:00
2025-01-05 05:04:52 -05:00
const TaskCount = (props) => {
let currentDay = props.currentDay;
2025-01-13 06:33:16 -05:00
const navigate = useNavigate();
2025-01-05 05:04:52 -05:00
const [taskCount, setTaskCount] = React.useState([]);
2025-01-06 05:54:22 -05:00
const [stateMap, setStateMap] = React.useState(new Map);
const [priorityMap, setPriorityMap] = React.useState(new Map);
2025-01-15 06:35:44 -05:00
const {dispatch } = useContext(MyRootContext);
2025-01-06 05:54:22 -05:00
useEffect(() => {
console.log("useEffect");
if (currentDay) {
2025-01-17 06:21:37 -05:00
getTaskCount(dayStartUtcFormat(currentDay),
nextDayStartUtcFormat(currentDay))
2025-01-06 05:54:22 -05:00
.then(taskCount => {
setTaskCount(taskCount)
})
2025-01-11 04:53:51 -05:00
getDictionary("2").then(state => {
setStateMap(state)
})
getDictionary("1").then(priority => {
console.log(priority)
setPriorityMap(priority)
})
}else {
setTaskCount([])
2025-01-05 05:04:52 -05:00
}
2025-01-11 04:53:51 -05:00
2025-01-06 05:54:22 -05:00
}, [currentDay])
2025-01-13 06:33:16 -05:00
const todoDayDetail = ()=>{
let andSearchModel = {}
let orSearchModel = {andSearchModel}
if (currentDay) {
andSearchModel.andList = [{
"name": "expectedStartTime",
2025-01-17 06:21:37 -05:00
"value": nextDayStartUtcFormat(currentDay),
2025-01-13 06:33:16 -05:00
"operateType": "<"
}, {
"name": "expectedEndTime",
2025-01-17 06:21:37 -05:00
"value": dayStartUtcFormat(currentDay),
2025-01-13 06:33:16 -05:00
"operateType": ">"
}]
andSearchModel.orSearchModel = {
"andList": [
{
"name": "expectedStartTime",
2025-01-17 06:21:37 -05:00
"value": nextDayStartUtcFormat(currentDay),
2025-01-13 06:33:16 -05:00
"operateType": "<"
}, {
"name": "expectedStartTime",
2025-01-17 06:21:37 -05:00
"value": dayStartUtcFormat(currentDay),
2025-01-13 06:33:16 -05:00
"operateType": ">"
}, {
"name": "expectedEndTime",
"operateType": "NULL"
}
], orSearchModel: {
"andList": [
{
"name": "expectedEndTime",
2025-01-17 06:21:37 -05:00
"value": nextDayStartUtcFormat(currentDay),
2025-01-13 06:33:16 -05:00
"operateType": "<"
}, {
"name": "expectedEndTime",
2025-01-17 06:21:37 -05:00
"value": dayStartUtcFormat(currentDay),
2025-01-13 06:33:16 -05:00
"operateType": ">"
}, {
"name": "expectedStartTime",
"operateType": "NULL"
}
]
}
}
}
console.log({orSearchModel})
2025-01-15 06:35:44 -05:00
dispatch({type:UPDATE_SEARCH,search:{
"pageSize": 12,
"pageNumber": 1,
"data": {
orSearchModel
2025-01-13 06:33:16 -05:00
}
2025-01-15 06:35:44 -05:00
}})
2025-01-16 06:10:14 -05:00
navigate("/home/listTask")
2025-01-13 06:33:16 -05:00
}
2025-01-05 05:04:52 -05:00
return (
2025-01-06 05:54:22 -05:00
<div style={{margin:"20px"}}>
2025-01-13 06:33:16 -05:00
<h2>TODO日{currentDay && dayjs(currentDay).format(DATE_FORMAT)}代办
{currentDay&&<a onClick={todoDayDetail}>详情</a>}</h2>
2025-01-06 05:54:22 -05:00
<h3>任务状态</h3>
{
// taskCount.map(task => {
// // if (dayjs(task.todoDay).isSame(dayjs(currentDay))){
// // console.log(dict);
// // return <span key={task.todoDay}>{task.todoDay}</span>
// return Array.from(stateMap.entries()).map(([item,value]) => {
// console.log("key",item,"value",value,task.state)
// return <Tag color={value.josnValue?.color}>value.itemName</Tag> + task.state[item]
// })
//
// // return task.priority.map((key,value)=>getDictionary(2).get(key)+value)
// // }
// })
taskCount[0] && Object.keys(taskCount[0].state).map(ob => {
return <div style={{marginBottom:"20px"}} key={ob}><Tag color={
stateMap.get(ob).jsonValue?stateMap.get(ob).jsonValue.color:"default"
}>{stateMap.get(ob).itemName}</Tag>
{taskCount[0].state[ob]} 项代办;</div>;
})
}
<h3>优先级</h3>
{
taskCount[0] && Object.keys(taskCount[0].priority).map(ob => {
console.log("stateMap.get(ob).jsonValue?.color", priorityMap.get(ob))
return <div style={{marginBottom:"20px"}} key={ob}><Tag
color={priorityMap.get(ob).jsonValue.color}>{priorityMap.get(ob).itemName}</Tag>
{taskCount[0].priority[ob]} 项代办;</div>;
})
}
2025-01-05 05:04:52 -05:00
</div>
)
}
export {TaskCount};