diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b9329bf..7ce6770 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,31 +4,19 @@ - - diff --git a/package.json b/package.json index 61348bc..e705b14 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "assistant-todo-mobile", "version": "0.1.0", + "homepage": "/mobile", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.16.5", diff --git a/src/App.js b/src/App.js index 99d0ba4..91c1606 100644 --- a/src/App.js +++ b/src/App.js @@ -8,30 +8,34 @@ import DetailSearchContext from "./pages/DetailSearchContext"; import ToDoCal from "./pages/ToDoCal"; import ToDoTree from "./pages/ToDoTree"; import {PersonalCenter} from "./pages/PersonalCenter"; +import {MyRootProvider} from "./components/MyRootContext"; function App() { return ( - -
- - }> + + +
+ + }> - - }> - }/> - }> - }/> - }> - - }> - }> - }> - }> - }> - - -
-
+
+ }> + {/*} />*/} + }/> + }> + }/> + }> + + }> + }> + }> + }> + }> + +
+
+
+ ); } diff --git a/src/components/DetailSearchBar/index.js b/src/components/DetailSearchBar/index.js index 74d4448..f233d6c 100644 --- a/src/components/DetailSearchBar/index.js +++ b/src/components/DetailSearchBar/index.js @@ -1,18 +1,17 @@ import {Tag,} from "antd-mobile"; -import React, {Fragment, useEffect, useState} from "react"; +import React, {Fragment, useContext, useEffect, useState} from "react"; import {useLocation, useNavigate} from 'react-router-dom'; import {AddOutline, CloseOutline, SearchOutline} from "antd-mobile-icons"; import "./index.css" import {getDictionary} from "../../utils/dictUtil"; import dayjs from "dayjs"; +import {MyRootContext, UPDATE_SEARCH} from "../MyRootContext"; +import {getTaskById} from "../../utils"; const DetailSearchBar = (props) => { - // 从搜索设置中传来的search - // const location = useLocation(); - // const searchUpdate = location.state?.search; - // 父子传值从搜索框传来的search - const {search, updateSearch, pName} = props; - console.log("DetailSearchBar.search", search) + const { state, dispatch } = useContext(MyRootContext); + const search = state.search + const [tags, setTags] = useState([]); const showCloseOutline = search && search.data && (search.data.andList?.length > 0 || search.data.orList?.length > 0) @@ -27,9 +26,11 @@ const DetailSearchBar = (props) => { // 处理主要条件 const tagList = []; console.log("search.data.orSearchModel",search.data.orSearchModel) - search.data.orSearchModel?.andList?.forEach((searchObj) => { + await search.data.orSearchModel?.andList?.forEach((searchObj) => { if (searchObj.name === "pid") { - tagList.push({pName}) + getTaskById(searchObj.value).then(result=>{ + tagList.push({result[0].name}) + }) } else if (searchObj.name === "state") { const items = searchObj.value.split(','); items.forEach((item) => { @@ -84,29 +85,27 @@ const DetailSearchBar = (props) => {
{ - navigate("/detail/searchTask", {state: {"search": search}}); + navigate("/detail/searchTask"); }}> {/*根据search处理搜素框展示内容*/} {tags}
{showCloseOutline &&
{ - updateSearch({ + dispatch({type:UPDATE_SEARCH,search:{ "pageSize": 20, "pageNumber": 1, "data": { "andList": [], "orList": [] } - }); + }}); setTags([]); }}>
} - - - {/* {*/} + {/* {*/} {/* navigate("/detail/searchTask")*/} {/*}}*/} diff --git a/src/components/MyRootContext/index.js b/src/components/MyRootContext/index.js new file mode 100644 index 0000000..7699aef --- /dev/null +++ b/src/components/MyRootContext/index.js @@ -0,0 +1,94 @@ +import { createContext, useReducer } from 'react'; +import {dayStartUtcFormat, nextDayStartUtcFormat} from "../../utils/timeFormatUtil"; +import dayjs from "dayjs"; + +// 创建一个 context +export const MyRootContext = createContext(); +export const UPDATE_SEARCH = "UPDATE_SEARCH"; +// 定义初始状态和 reducer 函数 +const initialState = {"search":{ + "pageSize": 20, + "pageNumber": 1, + "data": { + "orSearchModel": { + "andList": [ + {"name": "state", "value": "8,9", "operateType": "IN"}, + ], + "andSearchModel": { + "andList": [ + { + "name": "expectedStartTime", + "value": nextDayStartUtcFormat(dayjs()), + "operateType": "<" + }, + { + "name": "expectedEndTime", + "value": dayStartUtcFormat(dayjs()), + "operateType": ">" + } + ], + "orSearchModel": { + "andList": [ + { + "name": "expectedStartTime", + "value": nextDayStartUtcFormat(dayjs()), + "operateType": "<" + }, + { + "name": "expectedStartTime", + "value": dayStartUtcFormat(dayjs()), + "operateType": ">" + }, + { + "name": "expectedEndTime", + "value": dayStartUtcFormat(dayjs()), + "operateType": "NULL" + } + ], + "orSearchModel": { + "andList": [ + { + "name": "expectedEndTime", + "value": nextDayStartUtcFormat(dayjs()), + "operateType": "<" + }, + { + "name": "expectedEndTime", + "value": dayStartUtcFormat(dayjs()), + "operateType": ">" + }, + { + "name": "expectedStartTime", + "value": dayStartUtcFormat(dayjs()), + "operateType": "NULL" + } + ], + } + } + }, + }, + "andList": [ + {"name": "state", "value": "10", "operateType": "="} + ] + } + }}; +function reducer(state, action) { + switch (action.type) { + case UPDATE_SEARCH: + return { ...state, search:action.search}; + case 'decrement': + return { count: state.count - 1 }; + default: + throw new Error(); + } +} + +// 创建一个 Provider 组件 +export function MyRootProvider({ children }) { + const [state, dispatch] = useReducer(reducer, initialState); + return ( + + {children} + + ); +} \ No newline at end of file diff --git a/src/pages/DetailSearchContext/index.js b/src/pages/DetailSearchContext/index.js index ff3afbb..c755ee5 100644 --- a/src/pages/DetailSearchContext/index.js +++ b/src/pages/DetailSearchContext/index.js @@ -1,19 +1,18 @@ import {Button, Checkbox, DatePicker, Form, Input, Space, Switch, Tag} from "antd-mobile"; import ParentTask from "../../components/ParentTask"; -import React, {useEffect} from "react"; +import React, {useContext, useEffect} from "react"; import dayjs from "dayjs"; import {CloseCircleFill} from "antd-mobile-icons"; import {useLocation, useNavigate, useOutletContext} from "react-router-dom"; import {getDictionary} from "../../utils/dictUtil"; +import {MyRootContext, UPDATE_SEARCH} from "../../components/MyRootContext"; const DetailSearchContext = () => { const navigate = useNavigate(); const [form] = Form.useForm(); const [visible, setVisible] = React.useState(false); - const location = useLocation(); - console.log("DetailSearchContext", location); - const {search} = location?.state || undefined; - console.log("DetailSearchContext.search", search) + const { state, dispatch } = useContext(MyRootContext); + const search = state.search const [stateList, setStateList] = React.useState([]); const [priorityList, setPriorityList] = React.useState([]); // 使用Outlet,传值修改标题 @@ -132,19 +131,15 @@ const DetailSearchContext = () => { if (allOverdueTasks) { andList.push({"name": "state", "value": "10", "operateType": "="}) } - navigate("/mobile/listTask", { - state: { - search: { - "pageSize": 12, - "pageNumber": 1, - "data": { - andList, - orSearchModel - } - } + dispatch({type:UPDATE_SEARCH,search:{ + "pageSize": 12, + "pageNumber": 1, + "data": { + andList, + orSearchModel } - } - ) + }}) + navigate("/mobile/listTask") }} footer={