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

130 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";
2025-01-22 06:24:51 -05:00
import {Divider, 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) => {
2025-01-23 06:32:24 -05:00
const {currentDay, taskCount, today, backToToday, currentMonth} = props;
2025-01-13 06:33:16 -05:00
const navigate = useNavigate();
2025-01-06 05:54:22 -05:00
const [stateMap, setStateMap] = React.useState(new Map);
const [priorityMap, setPriorityMap] = React.useState(new Map);
2025-01-22 06:24:51 -05:00
const {dispatch} = useContext(MyRootContext);
2025-01-11 04:53:51 -05:00
2025-01-22 06:24:51 -05:00
const todoDayDetail = () => {
2025-01-13 06:33:16 -05:00
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-26 08:16:29 -05:00
let setting = localStorage.getItem('huayu-todo-setting');
if (setting && JSON.parse(setting).columnSort) {
dispatch({
type: UPDATE_SEARCH, search: {
"pageSize": 12,
"pageNumber": 1,
"sortList":[{"property":"expectedStartTime","direction":"ASC"}],
"data": {
orSearchModel
}
2025-01-13 06:33:16 -05:00
}
2025-01-26 08:16:29 -05:00
})
}else {
dispatch({
type: UPDATE_SEARCH, search: {
"pageSize": 12,
"pageNumber": 1,
"data": {
orSearchModel
}
}
})
}
2025-01-16 06:10:14 -05:00
navigate("/home/listTask")
2025-01-13 06:33:16 -05:00
}
2025-01-22 06:24:51 -05:00
useEffect(() => {
getDictionary("2").then(state => {
setStateMap(state)
})
getDictionary("1").then(priority => {
setPriorityMap(priority)
})
}, [])
2025-01-13 06:33:16 -05:00
2025-01-05 05:04:52 -05:00
return (
2025-01-22 06:24:51 -05:00
<div style={{margin: "20px"}}>
2025-01-13 06:33:16 -05:00
<h2>TODO日{currentDay && dayjs(currentDay).format(DATE_FORMAT)}代办
2025-02-05 06:10:17 -05:00
{/*{currentDay && <a onClick={todoDayDetail}>详情</a>}*/}
2025-01-23 06:32:24 -05:00
{!dayjs(currentMonth).isSame(today, 'months') &&
<Fragment><Divider direction='vertical'/><a onClick={() => backToToday()}>回到当月</a></Fragment>}
2025-01-22 06:24:51 -05:00
</h2>
2025-01-23 06:32:24 -05:00
{taskCount?.filter(taskC => dayjs(taskC.todoDay).isSame(dayjs(currentDay), 'date'))?.map(taskC => {
2025-01-22 06:24:51 -05:00
return <Fragment>
<h3>任务状态</h3>
{
Object.keys(taskC.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>
{taskC.state[ob]} 项代办;</div>;
})}
<h3>优先级</h3>
{
Object.keys(taskC.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>
{taskC.priority[ob]} 项代办;</div>;
})
}
</Fragment>
})
2025-01-06 05:54:22 -05:00
}
2025-01-05 05:04:52 -05:00
</div>
)
}
export {TaskCount};