diff --git a/src/components/DataPickItemPopup/index.js b/src/components/DataPickItemPopup/index.js index 915b62a..fa5d54c 100644 --- a/src/components/DataPickItemPopup/index.js +++ b/src/components/DataPickItemPopup/index.js @@ -1,5 +1,5 @@ import React, {useState} from "react"; -import {Form, Calendar, CapsuleTabs, JumboTabs, Picker, PickerView, Popup} from "antd-mobile"; +import {Form, Calendar, CapsuleTabs, JumboTabs, Picker, PickerView, Popup, CalendarPickerView} from "antd-mobile"; import {basicColumns} from "./constant"; import "./index.css" import {CloseCircleFill} from "antd-mobile-icons"; @@ -15,7 +15,7 @@ export default function DataPickItemPopup(props) { return ( { - return prevValues.fieldName !== curValues.fieldName + return prevValues[fieldName] !== curValues[fieldName] }} > {({getFieldValue, setFieldsValue}) => ( @@ -32,9 +32,9 @@ export default function DataPickItemPopup(props) { fontSize: 14, }} onClick={e => { + e.stopPropagation() // 计算属性名:允许你在对象字面量中使用表达式来动态确定属性名。 setFieldsValue({[fieldName]: null}) - e.stopPropagation() }}/>) : true } onClick={() => { @@ -84,7 +84,7 @@ export default function DataPickItemPopup(props) { > - { diff --git a/src/components/DetailForm/index.js b/src/components/DetailForm/index.js index d480b7d..19f6f1d 100644 --- a/src/components/DetailForm/index.js +++ b/src/components/DetailForm/index.js @@ -8,14 +8,13 @@ import { Space, Tag, Radio } from 'antd-mobile' import ParentTask from "../ParentTask"; -import DatePickerItem from "../DataPickerItem" import "./index.css" import {addTask, getPTask, getTaskById, updateTask} from "../../utils"; import {useLocation, useNavigate, useOutletContext, useSearchParams} from "react-router-dom"; import dayjs from "dayjs"; import DataPickItemPopup from "../DataPickItemPopup"; -export default () => { +const DetailForm= () => { // 进入此页面的操作:添加,修改,详情(按钮为添加任务日志) const location = useLocation(); let [params] = useSearchParams(); @@ -29,6 +28,9 @@ export default () => { const navigate = useNavigate(); // 获取form引用 const [form] = Form.useForm(); + const addEditPName=(name)=>{ + setPName(name) + } useEffect(() => { window.scrollTo(0, 0); if (location.pathname.endsWith("addTask")) { @@ -83,6 +85,7 @@ export default () => { console.log({res, parentMessageVOList}); setPName(parentMessageVOList[parentMessageVOList.length - 1].name); setPidArray(parentMessageVOList.map(parent => parent.id)) + form.setFieldValue("pidArray",parentMessageVOList.map(parent => parent.id)) }) } @@ -136,6 +139,8 @@ export default () => { // 清空值 form.resetFields(); form.setFieldValue("pidArray", values.pidArray); + setPidArray(values.pidArray) + window.scrollTo(0, 0); } }, ], @@ -193,7 +198,10 @@ export default () => { name='code' hidden={true} > - + { ) -} \ No newline at end of file +} +export default DetailForm; \ No newline at end of file diff --git a/src/components/DetailSearchBar/index.js b/src/components/DetailSearchBar/index.js index 8c02710..28c1bfd 100644 --- a/src/components/DetailSearchBar/index.js +++ b/src/components/DetailSearchBar/index.js @@ -9,7 +9,7 @@ import {MyRootContext, UPDATE_SEARCH} from "../MyRootContext"; import {getTaskById} from "../../utils"; const DetailSearchBar = (props) => { - const { state, dispatch } = useContext(MyRootContext); + const {state, dispatch} = useContext(MyRootContext); const search = state.search const [tags, setTags] = useState([]); @@ -25,11 +25,12 @@ const DetailSearchBar = (props) => { const priorityDictionary = await getDictionary("1"); // 处理主要条件 const tagList = []; - console.log("search.data.orSearchModel",search.data.orSearchModel) - await search.data.orSearchModel?.andList?.forEach((searchObj) => { + console.log("search.data.orSearchModel", search.data.orSearchModel) + search.data.orSearchModel?.andList?.forEach((searchObj) => { if (searchObj.name === "pid") { getTaskById(searchObj.value).then(result=>{ - tagList.push({result[0].name}) + setTags([{result.content[0].name} + ,...tagList]) }) } else if (searchObj.name === "state") { const items = searchObj.value.split(','); @@ -68,8 +69,9 @@ const DetailSearchBar = (props) => { if (searchObj.name === "state" && searchObj.value === "10") { const dict = stateDictionary.get(searchObj.value); if (dict && tagList.length > 0) { - tagList.push() - } if (dict) { + tagList.push() + } + if (dict) { tagList.push( {dict.itemName} ); @@ -92,14 +94,16 @@ const DetailSearchBar = (props) => { {tags} {showCloseOutline &&
{ - dispatch({type:UPDATE_SEARCH,search:{ - "pageSize": 12, - "pageNumber": 1, - "data": { - "andList": [], - "orList": [] + dispatch({ + type: UPDATE_SEARCH, search: { + "pageSize": 12, + "pageNumber": 1, + "data": { + "andList": [], + "orList": [] + } } - }}); + }); setTags([]); }}> diff --git a/src/components/ParentTask/index.js b/src/components/ParentTask/index.js index b2a7e65..80073bd 100644 --- a/src/components/ParentTask/index.js +++ b/src/components/ParentTask/index.js @@ -1,4 +1,4 @@ -import {Cascader,Input, Toast} from "antd-mobile"; +import {Cascader, Input, Toast} from "antd-mobile"; import React, {useEffect, useMemo, useState} from "react"; import { Form, @@ -6,10 +6,10 @@ import { import {getTaskByPid} from "../../utils"; -const ParentTask = (props)=>{ +const ParentTask = (props) => { const [valueToOptions, setValueToOptions] = useState([]) - const {form,disabled,pName,pidArray} = props; - const [parentValue, setParentValue] = useState(pidArray??[]) + const {form, disabled, pName, pidArray, addEditPName} = props; + const [parentValue, setParentValue] = useState(pidArray ?? []) const [visible, setVisible] = useState(false) const options = useMemo(() => { @@ -26,6 +26,7 @@ const ParentTask = (props)=>{ children: generate(option.value), })) } + return generate('0') ?? [] }, [valueToOptions]) @@ -39,7 +40,7 @@ const ParentTask = (props)=>{ // return // } const data = await getTaskByPid(v) - console.log("await getTaskByPid(v)",data.content) + console.log("await getTaskByPid(v)", data.content) const options = data.content.length === 0 ? null @@ -47,7 +48,7 @@ const ParentTask = (props)=>{ value: task.id, label: task.name, })) - console.log("await getTaskByPid(v) options",options) + console.log("await getTaskByPid(v) options", options) setValueToOptions(prev => ({ ...prev, [v]: options, @@ -55,8 +56,18 @@ const ParentTask = (props)=>{ } useEffect(() => { - fetchOptionsForValue('0', 0) - }, []) + initDate() + }, [props]) + + async function initDate() { + await fetchOptionsForValue('0', 0) + if (pidArray && pidArray.length > 0) { + setParentValue(pidArray) + for (const taskId of pidArray) { + await fetchOptionsForValue(taskId, 0) + } + } + } return { { setVisible(false) }} value={parentValue} - onConfirm={(val)=>{ + onConfirm={(val) => { console.log(val) - setParentValue(val[val.length-1]) - form.setFieldValue('pidArray',val) + setParentValue(val[val.length - 1]) + form.setFieldValue('pidArray', val) }} // onSelect={(val, extend) => { // console.log('onSelect', val, extend.items) // }} onSelect={value => { - console.log("value",value) + console.log("value", value) value.forEach((v, index) => { fetchOptionsForValue(v, index + 1) }) @@ -91,11 +103,14 @@ const ParentTask = (props)=>{ > {items => { if (items.every(item => item === null)) { - return pName?({pName}): disabled ? - (主线任务选填): + return pName ? ({pName}) : disabled ? + (主线任务选填) : (主线任务选填) } else { - return items[items.length-1].label + if (addEditPName) { + addEditPName(items[items.length - 1].label) + } + return items[items.length - 1].label } }} diff --git a/src/pages/DetailLogTask/index.js b/src/pages/DetailLogTask/index.js index d1fe29c..f366759 100644 --- a/src/pages/DetailLogTask/index.js +++ b/src/pages/DetailLogTask/index.js @@ -19,7 +19,7 @@ export function DetailLogTask() { const [currentShow, setCurrentShow] = useState('need'); const textAreaRef = useRef(null); const [taskLogList, setTaskLogList] = useState([]); - const [sendValue, setSendValue] = useState([]); + const [sendValue, setSendValue] = useState(''); // 点击操作面板 const [actionSheetVisible, setActionSheetVisible] = useState(false) diff --git a/src/pages/DetailSearchContext/index.js b/src/pages/DetailSearchContext/index.js index 01e6006..971a720 100644 --- a/src/pages/DetailSearchContext/index.js +++ b/src/pages/DetailSearchContext/index.js @@ -1,4 +1,4 @@ -import {Button, Checkbox, DatePicker, Form, Input, Space, Switch, Tag} from "antd-mobile"; +import {Button, CalendarPicker, Checkbox, DatePicker, Form, Input, Space, Switch, Tag} from "antd-mobile"; import ParentTask from "../../components/ParentTask"; import React, {useContext, useEffect} from "react"; import dayjs from "dayjs"; @@ -7,6 +7,7 @@ import {useLocation, useNavigate, useOutletContext} from "react-router-dom"; import {getDictionary} from "../../utils/dictUtil"; import {MyRootContext, UPDATE_SEARCH} from "../../components/MyRootContext"; import {dayStartUtcFormat, nextDayStartUtcFormat} from "../../utils/timeFormatUtil"; +import {getPTask} from "../../utils"; const DetailSearchContext = () => { const navigate = useNavigate(); @@ -16,6 +17,8 @@ const DetailSearchContext = () => { const search = state.search const [stateList, setStateList] = React.useState([]); const [priorityList, setPriorityList] = React.useState([]); + const [pName, setPName] = React.useState(); + const [pidArray, setPidArray] = React.useState([]); // 使用Outlet,传值修改标题 const {setTitle} = useOutletContext(); useEffect(() => { @@ -24,6 +27,17 @@ const DetailSearchContext = () => { initDate() }, []) + function editParentTask(id) { + // 获取父任务信息 + getPTask(id).then(res => { + let parentMessageVOList = res[0].parentMessageVOList; + console.log({res, parentMessageVOList}); + setPName(parentMessageVOList[parentMessageVOList.length - 1].name); + setPidArray(parentMessageVOList.map(parent => parent.id)) + form.setFieldValue("pidArray",parentMessageVOList.map(parent => parent.id)) + }) + } + async function initDate() { let stateDictionary = await getDictionary("2"); let priorityDictionary = await getDictionary("1"); @@ -36,8 +50,7 @@ const DetailSearchContext = () => { let searchMap = new Map( search.data.orSearchModel.andList.map(searchObj => [searchObj.name, searchObj])); if (searchMap.has("pid")) { - - // form.setFieldValue(task.name); + editParentTask(searchMap.get("pid").value) } if (searchMap.has("state")) { form.setFieldValue("state", searchMap.get("state").value.split(',')) @@ -76,7 +89,7 @@ const DetailSearchContext = () => { const {pidArray, name, priority, state, todoDay, allOverdueTasks} = values; if (pidArray && pidArray.length !== 0) { - searchCondition.push({"name": "name", "value": pidArray[pidArray.length - 1], "operateType": "="}) + searchCondition.push({"name": "pid", "value": pidArray[pidArray.length - 1], "operateType": "="}) } if (name && name !== "") { searchCondition.push({"name": "name", "value": name, "operateType": "%"}) @@ -148,7 +161,7 @@ const DetailSearchContext = () => { } > - + { setVisible(true) }} > - { setVisible(false) }} - > - {value => - value ? dayjs(value).format('YYYY-MM-DD') : '请选择日期' - } - + onConfirm={(val)=>setFieldsValue({todoDay:val})} + /> + { + getFieldValue('todoDay') ? dayjs(getFieldValue('todoDay')).format('YYYY-MM-DD') : '请选择日期' + } )} diff --git a/src/pages/TaskCount/index.js b/src/pages/TaskCount/index.js index 5bf2523..05f4426 100644 --- a/src/pages/TaskCount/index.js +++ b/src/pages/TaskCount/index.js @@ -9,7 +9,7 @@ import {MyRootContext, UPDATE_SEARCH} from "../../components/MyRootContext"; const TaskCount = (props) => { - const {currentDay, taskCount, today, backToToday} = props; + const {currentDay, taskCount, today, backToToday, currentMonth} = props; const navigate = useNavigate(); const [stateMap, setStateMap] = React.useState(new Map); const [priorityMap, setPriorityMap] = React.useState(new Map); @@ -73,12 +73,10 @@ const TaskCount = (props) => { navigate("/home/listTask") } useEffect(() => { - console.log("useEffect"); getDictionary("2").then(state => { setStateMap(state) }) getDictionary("1").then(priority => { - console.log(priority) setPriorityMap(priority) }) }, []) @@ -87,10 +85,10 @@ const TaskCount = (props) => {

TODO日{currentDay && dayjs(currentDay).format(DATE_FORMAT)}代办: {currentDay && 详情} - {!dayjs(currentDay).isSame(today, 'date') && - backToToday()}>回到今天} + {!dayjs(currentMonth).isSame(today, 'months') && + backToToday()}>回到当月}

- {taskCount.filter(taskC => dayjs(taskC.todoDay).isSame(dayjs(currentDay), 'date'))?.map(taskC => { + {taskCount?.filter(taskC => dayjs(taskC.todoDay).isSame(dayjs(currentDay), 'date'))?.map(taskC => { return

任务状态

{ diff --git a/src/pages/ToDoCal/index.css b/src/pages/ToDoCal/index.css new file mode 100644 index 0000000..913a182 --- /dev/null +++ b/src/pages/ToDoCal/index.css @@ -0,0 +1,13 @@ +.cal-day-circle { + width: 30px; + height: 30px; + border-radius: 20px; + border-style: solid; + display: flex; + justify-content: center; + align-items: center; + + flex-direction: row; + flex-wrap: nowrap; + align-content: normal +} \ No newline at end of file diff --git a/src/pages/ToDoCal/index.jsx b/src/pages/ToDoCal/index.jsx index f69e0b9..f383f46 100644 --- a/src/pages/ToDoCal/index.jsx +++ b/src/pages/ToDoCal/index.jsx @@ -1,82 +1,129 @@ -import {Calendar, Tag} from "antd-mobile"; +import {Calendar, Cascader, Tag} from "antd-mobile"; import dayjs from "dayjs"; import {TaskCount} from "../TaskCount"; -import React, {Fragment, useEffect, useLayoutEffect, useRef} from "react"; - -import { - dateStartUtcFormat, - nextDateStartUtcFormat, -} from "../../utils/timeFormatUtil"; -import {getTaskCount} from "../../utils"; +import React, {Fragment, useEffect, useLayoutEffect, useMemo, useRef, useState} from "react"; +import {getTaskByPid, getTaskCount} from "../../utils"; import {FrownFill, SmileFill} from "antd-mobile-icons"; import {NEW, OVERDUE, UNDER_WAY} from "../../utils/commonConstant"; +import {dateStartUtcFormat} from "../../utils/timeFormatUtil"; + +import './index.css' + const ToDoCal = (props) => { + const today = new Date() const calRef = useRef(null); const [currentDay, setCurrentDay] = React.useState(new Date()) - 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) + const [currentMonth, setCurrentMonth] = React.useState(dayjs().set("date", 1).format('YYYY-MM-DD')); + // Map key为当前月value为当前月的向 + const [listTaskMap, setListTaskMap] = useState(new Map()); + // useLayoutEffect + useEffect(() => { + console.log("getCurrentShowDay", getCurrentShowDay()) + const {startDay, endDay} = getCurrentShowDay(); + listTaskCount(startDay, endDay); + }, [currentMonth]) + let loading = false - listTaskCount(); - },[]) - function backToToday(){ + async function listTaskCount(start, end) { + if (loading) { + return; + } + loading = true; + if (listTaskMap.has(currentMonth)) return + const res = await getTaskCount(start, end); + setListTaskMap(prevState => { + const newMap = new Map(prevState); + newMap.set(currentMonth, res); + return newMap; + }) + loading = false; + } + + /* + 获取当前展示的日期 + */ + function getCurrentShowDay() { + const firstDay = dayjs(currentMonth).set("date", 1); + const startDay = firstDay.subtract(firstDay.day(), 'day'); + const endDay = startDay.add(6 * 7, 'day'); + return {startDay: dateStartUtcFormat(startDay), endDay: dateStartUtcFormat(endDay)}; + } + + function backToToday() { calRef.current.jumpToToday(); setCurrentDay(today) } + return ( + { - allDay.push(date) - - // 没有任务不显示 - return taskCount.filter(taskC => dayjs(taskC.todoDay).isSame(dayjs(date), 'date'))?.map(taskC => { + // renderLabel={date => { + // // 没有任务不显示 + // return listTaskMap?.get(currentMonth)?.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 ; + // } + // // 如果有未完成的任务 warn + // if (taskC.state[NEW] || taskC.state[UNDER_WAY]) { + // return ; + // } + // // 任务全部完成 绿色 + // return ; + // } + // }) + // + // // if (dayjs(date).isSame(today, 'day')) return '今天' + // // if (date.getDay() === 0 || date.getDay() === 6) { + // // return '周末' + // // } + // }} + renderDate={date => { + return listTaskMap?.get(currentMonth)?.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 ; + if (Object.keys(taskC.state).length > 0) { + console.log("taskC.state", taskC.state) + if (taskC.state[OVERDUE]) { + return
{dayjs(date).date()}
; } // 如果有未完成的任务 warn - if (taskC.state[NEW]||taskC.state[UNDER_WAY]){ - return ; + if (taskC.state[NEW] || taskC.state[UNDER_WAY]) { + return
{dayjs(date).date()}
; } // 任务全部完成 绿色 - return ; + return
{dayjs(date).date()}
; } + return {dayjs(date).date()}; }) - - // if (dayjs(date).isSame(today, 'day')) return '今天' - // if (date.getDay() === 0 || date.getDay() === 6) { - // return '周末' - // } }} - // renderDate={date=>{ - // return {dayjs(date).date()} - // }} defaultValue={currentDay} onChange={val => { setCurrentDay(val) }} + onPageChange={(year, month) => { + console.log(year, month) + setCurrentMonth(`${year}-${month}-01`) + }} /> - +
) } diff --git a/src/utils/dictUtil.js b/src/utils/dictUtil.js index 9a032f7..54d20bf 100644 --- a/src/utils/dictUtil.js +++ b/src/utils/dictUtil.js @@ -4,7 +4,6 @@ import {requestUtil} from "./requestUtil"; export const getDictionary = async (typeId) => { let item1 = localStorage.getItem("huayu-dict-" + typeId); - console.log("item1: ", item1); if (item1) { return new Map(JSON.parse(item1).map(item => { return [item.itemCode, item]