import './index.css'; import {MouseEvent, Reducer, useEffect, useReducer, useState} from "react"; import {Link, useNavigate, useSearchParams} from "react-router-dom"; import {IMenuListItem, IMenuWithTopButton} from "../../interfaces/menu/IMenuWithTopButton.ts"; import MenuWithTopButton from "../../components/menu/MenuWithTopButton.tsx"; import MenuTreeWithTopButton from "../../components/menu/MenuTreeWithTopButton.tsx"; import ListProj from "../../components/list/ListProj.tsx"; import ListProjAgent from "../../components/list/ListProjAgent.tsx"; import {Breadcrumb, MenuProps} from 'antd'; import { IndexListContext, IndexListDataType, IndexListDispatchContext, ListAction, ListData, } from "../../context/IndexListContext.ts"; export default function Index() { const nav = useNavigate(); const [searchParams] = useSearchParams(); const listReducer = (state: ListData, action: ListAction) => { if (action.type == IndexListDataType.PROJ) { state.type = IndexListDataType.PROJ; state.status = action.value as string; } else if (action.type == IndexListDataType.AGENT) { state.type = IndexListDataType.AGENT; state.status = action.value as string; } else if (action.type == IndexListDataType.CATEGORY) { state.categorys = action.value as MenuProps['items']; state.categoryChangeCount++; } else if (action.type == IndexListDataType.CATEGORY_CHANGE) { state.category = action.value as string; state.categoryChangeCount++; } else if (action.type == IndexListDataType.CATEGORY_DELETE) { state.categorys = action.value as MenuProps['items']; state.category = ''; state.categoryChangeCount++; } return { ...state }; } const [listData, dispatch] = useReducer>(listReducer, { type: IndexListDataType.PROJ, categoryChangeCount: 0 }); const [projMenu, setProjMenu] = useState({ button: { name: '创建项目', handle() { nav('/proj-create') } }, list: [ {id: 'ALL', name: '全部项目'}, {id: 'PROCESSING', name: '进行中的'}, {id: 'COMPLETE', name: '已完成的'} ], handleListItem(_e, _index, item: IMenuListItem) { projMenu.list.forEach(item => item.active = false); agentMenu.list.forEach(item => item.active = false); item.active = true; setProjMenu({ ...projMenu }) dispatch({ type: IndexListDataType.PROJ, value: item.id }) } }); const [agentMenu, setAgentMenu] = useState({ button: { name: '代理服务', handle() { dispatch({ type: IndexListDataType.PROJ, value: 'COMPLETE' }) } }, list: [ {id: 'ALL', name: '全部项目'}, {id: 'PROCESSING', name: '进行中的'}, {id: 'COMPLETE', name: '已完成的'}, ], handleListItem(_e: MouseEvent, _index: number, item: IMenuListItem) { projMenu.list.forEach(item => item.active = false); agentMenu.list.forEach(item => item.active = false); item.active = true; setAgentMenu({ ...agentMenu }) dispatch({ type: IndexListDataType.AGENT, value: item.id }) } }) useEffect(() => { if (searchParams.get('type') == 'agent') { dispatch({ type: IndexListDataType.AGENT, value: 'ALL' }) } }, []); return ( <> 首页} ]} />
{ listData.type === IndexListDataType.PROJ ? : ( listData.type == IndexListDataType.AGENT ? : <> ) }
) }