import './index.css'; import {MouseEvent, Reducer, useEffect, useReducer} 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} 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; } else if(action.type == IndexListDataType.AGENT) { state.type = IndexListDataType.AGENT; state.status = action.value; } return { ...state }; } const [listData, dispatch] = useReducer>(listReducer, { type: IndexListDataType.PROJ }); const projMenu: IMenuWithTopButton = { button: { name: '创建项目', handle() { nav('/proj-create') } }, list: [ {id: 'ALL', name: '全部项目'}, {id: 'PROCESSING', name: '进行中的'}, {id: 'COMPLETE', name: '已完成的'} ], handleListItem(_e, _index,item: IMenuListItem) { dispatch({ type: IndexListDataType.PROJ, value: item.id }) } } const agentMenu: IMenuWithTopButton = { 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) { 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 ? : <> ) }
) }