import './index.css'; // import { MouseEvent, Reducer, useEffect, useReducer, useState, useContext } from "react"; import { MouseEvent, Reducer, useEffect, useReducer, useState } from "react"; import { useNavigate, useSearchParams, Outlet } from "react-router-dom"; import { IMenuListItem, IMenuWithTopButton } from "../../interfaces/menu/IMenuWithTopButton.ts"; import MenuWithTopButton from "../../components/menu/MenuWithTopButton.tsx"; import MenuWithBottomButtom from '../../components/menu/MenuWithBottomButton.tsx' import MenuTreeWithTopButton from "../../components/menu/MenuTreeWithTopButton.tsx"; // import ListProj from "../../components/list/ListProj.tsx"; // import ListProjAgent from "../../components/list/ListProjAgent.tsx"; import { MenuProps } from 'antd'; import { IndexListContext, IndexListDataType, IndexListDispatchContext, ListAction, ListData, } from "../../context/IndexListContext.ts"; import { useLocation } from 'react-router-dom'; import gpsImg from '../../static/right/gps.png' import backImg from '../../static/right/back.png' import { Link } from "react-router-dom"; import { Input, Breadcrumb } from 'antd'; const { Search } = Input; export default function Index() { // const [keywords, setKeywords] = useState(''); // const indexListContext = useContext(IndexListContext); 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: '全部项目', active: true }, { 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, // keywords: '' }) // sessionStorage.setItem('listType', String(IndexListDataType.PROJ)); // sessionStorage.setItem('listType', String(IndexListDataType.AGENT)); // console.log(IndexListDataType.PROJ); // console.log(sessionStorage.getItem('listType')); // nav('/home', { // state: { // listType: '0', // } // }) }, }); 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, }) } }) const location = useLocation() const [now,setNow] = useState('首页') const [pathArray,setPathArray] = useState([ { title: 首页 }]) useEffect(()=>{ // const nowname = sessionStorage.getItem('now') console.log( '路由名字', location.pathname); if(location.pathname == '/home'){ setNow('首页') setPathArray([ { title: 首页 }]) }else if(location.pathname == '/proj-create'){ setNow('创建项目') setPathArray([ { title: 首页 },{title: 创建}]) } },[location.pathname]) useEffect(() => { sessionStorage.setItem('pathArray', JSON.stringify([ { title: 首页 }])); sessionStorage.setItem('now', '首页'); if (searchParams.get('type') == 'agent') { dispatch({ type: IndexListDataType.AGENT, value: 'ALL', }) } }, []); // useEffect(() => { // console.log('监听',keywords); // }, [keywords]); const handleSearch = (value: string) => { console.log(value); nav('/home',{state:{ keyword:value }}) } return ( <> {/* 首页} ]} /> */}
{/* 标签 */} {/* {renderStatus()} */}
当前位置:{ now}
首页 }, // ]} items={pathArray} />
{/* { listData.type === IndexListDataType.PROJ ? : ( listData.type == IndexListDataType.AGENT ? : <> ) } */}
) }