assistant-todo-mobile/src/pages/ToDoCal/index.jsx

83 lines
3.2 KiB
React
Raw Normal View History

2025-01-22 06:24:51 -05:00
import {Calendar, Tag} from "antd-mobile";
2025-01-01 08:16:32 -05:00
import dayjs from "dayjs";
2025-01-05 05:04:52 -05:00
import {TaskCount} from "../TaskCount";
2025-01-22 06:24:51 -05:00
import React, {Fragment, useEffect, useLayoutEffect, useRef} from "react";
import {
dateStartUtcFormat,
nextDateStartUtcFormat,
} from "../../utils/timeFormatUtil";
import {getTaskCount} from "../../utils";
import {FrownFill, SmileFill} from "antd-mobile-icons";
import {NEW, OVERDUE, UNDER_WAY} from "../../utils/commonConstant";
2025-01-01 08:16:32 -05:00
const ToDoCal = (props) => {
2025-01-22 06:24:51 -05:00
const calRef = useRef(null);
2025-01-05 05:04:52 -05:00
const [currentDay, setCurrentDay] = React.useState(new Date())
2025-01-22 06:24:51 -05:00
const today = new Date()
const [allDay,setAllDay] = React.useState([])
const [taskCount,setTaskCount] = React.useState([])
function listTaskCount(){
if (allDay.length === 0){
return
}
getTaskCount(dateStartUtcFormat(allDay[0]),
nextDateStartUtcFormat(allDay[allDay.length-1]))
.then(res => {
setTaskCount(res)
})
}
useLayoutEffect(()=>{
console.log("useLayoutEffect",allDay)
listTaskCount();
},[])
function backToToday(){
calRef.current.jumpToToday();
setCurrentDay(today)
}
2025-01-01 08:16:32 -05:00
return (
2025-01-05 05:04:52 -05:00
<Fragment>
<Calendar
2025-01-22 06:24:51 -05:00
ref={calRef}
2025-01-05 05:04:52 -05:00
selectionMode='single'
renderLabel={date => {
2025-01-22 06:24:51 -05:00
allDay.push(date)
// 没有任务不显示
return taskCount.filter(taskC => dayjs(taskC.todoDay).isSame(dayjs(date), 'date'))?.map(taskC => {
// 如果有逾期的 红色
// Object.keys() 返回一个包含对象自身所有可枚举属性的数组
// Object.entries() 返回一个包含对象所有可枚举属性的键值对数组。
if (Object.keys(taskC.state).length>0){
console.log("taskC.state",taskC.state)
if (taskC.state[OVERDUE]){
return <FrownFill color='var(--adm-color-danger)'/>;
}
// 如果有未完成的任务 warn
if (taskC.state[NEW]||taskC.state[UNDER_WAY]){
return <SmileFill color='var(--adm-color-warning)'/>;
}
// 任务全部完成 绿色
return <SmileFill color='var(--adm-color-success)'/>;
}
})
// if (dayjs(date).isSame(today, 'day')) return '今天'
// if (date.getDay() === 0 || date.getDay() === 6) {
// return '周末'
// }
2025-01-05 05:04:52 -05:00
}}
2025-01-22 06:24:51 -05:00
// renderDate={date=>{
// return <span style={{"color":"red"}}>{dayjs(date).date()}</span>
// }}
2025-01-05 05:04:52 -05:00
defaultValue={currentDay}
onChange={val => {
setCurrentDay(val)
}}
2025-01-22 06:24:51 -05:00
2025-01-05 05:04:52 -05:00
/>
2025-01-22 06:24:51 -05:00
<TaskCount currentDay={currentDay} taskCount={taskCount} today={today} backToToday={backToToday}/>
2025-01-05 05:04:52 -05:00
</Fragment>
2025-01-01 08:16:32 -05:00
)
}
export default ToDoCal;