2024-03-27 18:56:48 +08:00
|
|
|
import './index.css';
|
2024-05-07 17:00:32 +08:00
|
|
|
// 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";
|
2024-03-27 18:56:48 +08:00
|
|
|
import MenuWithTopButton from "../../components/menu/MenuWithTopButton.tsx";
|
2024-04-29 17:22:26 +08:00
|
|
|
import MenuWithBottomButtom from '../../components/menu/MenuWithBottomButton.tsx'
|
2024-03-27 18:56:48 +08:00
|
|
|
import MenuTreeWithTopButton from "../../components/menu/MenuTreeWithTopButton.tsx";
|
2024-05-07 17:00:32 +08:00
|
|
|
// import ListProj from "../../components/list/ListProj.tsx";
|
|
|
|
// import ListProjAgent from "../../components/list/ListProjAgent.tsx";
|
|
|
|
import { MenuProps } from 'antd';
|
2024-03-27 18:56:48 +08:00
|
|
|
import {
|
|
|
|
IndexListContext,
|
|
|
|
IndexListDataType,
|
|
|
|
IndexListDispatchContext,
|
|
|
|
ListAction,
|
2024-04-01 20:39:22 +08:00
|
|
|
ListData,
|
2024-03-27 18:56:48 +08:00
|
|
|
} from "../../context/IndexListContext.ts";
|
|
|
|
|
2024-05-07 17:00:32 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-27 18:56:48 +08:00
|
|
|
export default function Index() {
|
2024-05-07 17:00:32 +08:00
|
|
|
|
|
|
|
// const [keywords, setKeywords] = useState('');
|
|
|
|
// const indexListContext = useContext(IndexListContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-27 18:56:48 +08:00
|
|
|
const nav = useNavigate();
|
2024-03-28 19:35:54 +08:00
|
|
|
const [searchParams] = useSearchParams();
|
2024-03-27 18:56:48 +08:00
|
|
|
|
|
|
|
const listReducer = (state: ListData, action: ListAction) => {
|
2024-04-01 20:39:22 +08:00
|
|
|
if (action.type == IndexListDataType.PROJ) {
|
2024-03-27 18:56:48 +08:00
|
|
|
state.type = IndexListDataType.PROJ;
|
2024-04-01 20:39:22 +08:00
|
|
|
state.status = action.value as string;
|
|
|
|
} else if (action.type == IndexListDataType.AGENT) {
|
2024-03-27 18:56:48 +08:00
|
|
|
state.type = IndexListDataType.AGENT;
|
2024-04-01 20:39:22 +08:00
|
|
|
state.status = action.value as string;
|
|
|
|
} else if (action.type == IndexListDataType.CATEGORY) {
|
|
|
|
state.categorys = action.value as MenuProps['items'];
|
2024-04-02 18:45:46 +08:00
|
|
|
state.categoryChangeCount++;
|
2024-04-01 20:39:22 +08:00
|
|
|
} else if (action.type == IndexListDataType.CATEGORY_CHANGE) {
|
2024-04-02 18:45:46 +08:00
|
|
|
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++;
|
2024-03-27 18:56:48 +08:00
|
|
|
}
|
|
|
|
return {
|
|
|
|
...state
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const [listData, dispatch] = useReducer<Reducer<ListData, ListAction>>(listReducer, {
|
2024-04-02 18:45:46 +08:00
|
|
|
type: IndexListDataType.PROJ,
|
|
|
|
categoryChangeCount: 0
|
2024-03-27 18:56:48 +08:00
|
|
|
});
|
|
|
|
|
2024-04-01 20:39:22 +08:00
|
|
|
const [projMenu, setProjMenu] = useState<IMenuWithTopButton>({
|
2024-03-27 18:56:48 +08:00
|
|
|
button: {
|
2024-04-29 17:22:26 +08:00
|
|
|
name: '项目',
|
2024-03-27 18:56:48 +08:00
|
|
|
handle() {
|
|
|
|
nav('/proj-create')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
list: [
|
2024-05-07 17:00:32 +08:00
|
|
|
{ id: 'ALL', name: '全部项目', active: true },
|
|
|
|
{ id: 'PROCESSING', name: '进行中的' },
|
|
|
|
{ id: 'COMPLETE', name: '已完成的' }
|
2024-03-27 18:56:48 +08:00
|
|
|
],
|
2024-04-01 20:39:22 +08:00
|
|
|
handleListItem(_e, _index, item: IMenuListItem) {
|
|
|
|
projMenu.list.forEach(item => item.active = false);
|
|
|
|
agentMenu.list.forEach(item => item.active = false);
|
|
|
|
item.active = true;
|
|
|
|
setProjMenu({
|
|
|
|
...projMenu
|
|
|
|
})
|
2024-03-27 18:56:48 +08:00
|
|
|
dispatch({
|
|
|
|
type: IndexListDataType.PROJ,
|
2024-05-07 17:00:32 +08:00
|
|
|
value: item.id,
|
|
|
|
// keywords: ''
|
|
|
|
|
2024-03-27 18:56:48 +08:00
|
|
|
})
|
2024-05-07 17:00:32 +08:00
|
|
|
// 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',
|
|
|
|
// }
|
|
|
|
|
|
|
|
// })
|
2024-04-29 17:22:26 +08:00
|
|
|
},
|
2024-03-27 18:56:48 +08:00
|
|
|
|
2024-05-07 17:00:32 +08:00
|
|
|
});
|
2024-04-01 20:39:22 +08:00
|
|
|
const [agentMenu, setAgentMenu] = useState<IMenuWithTopButton>({
|
2024-03-27 18:56:48 +08:00
|
|
|
button: {
|
|
|
|
name: '代理服务',
|
|
|
|
handle() {
|
2024-03-28 19:35:54 +08:00
|
|
|
dispatch({
|
|
|
|
type: IndexListDataType.PROJ,
|
2024-05-07 17:00:32 +08:00
|
|
|
value: 'COMPLETE',
|
2024-03-28 19:35:54 +08:00
|
|
|
})
|
2024-03-27 18:56:48 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
list: [
|
2024-05-07 17:00:32 +08:00
|
|
|
{ id: 'ALL', name: '全部项目' },
|
|
|
|
{ id: 'PROCESSING', name: '进行中的' },
|
|
|
|
{ id: 'COMPLETE', name: '已完成的' },
|
2024-03-27 18:56:48 +08:00
|
|
|
],
|
|
|
|
handleListItem(_e: MouseEvent<HTMLLIElement>, _index: number, item: IMenuListItem) {
|
2024-04-01 20:39:22 +08:00
|
|
|
projMenu.list.forEach(item => item.active = false);
|
|
|
|
agentMenu.list.forEach(item => item.active = false);
|
|
|
|
item.active = true;
|
|
|
|
setAgentMenu({
|
|
|
|
...agentMenu
|
|
|
|
})
|
2024-03-27 18:56:48 +08:00
|
|
|
dispatch({
|
|
|
|
type: IndexListDataType.AGENT,
|
2024-05-07 17:00:32 +08:00
|
|
|
value: item.id,
|
|
|
|
|
2024-03-27 18:56:48 +08:00
|
|
|
})
|
|
|
|
}
|
2024-04-01 20:39:22 +08:00
|
|
|
})
|
2024-05-07 17:00:32 +08:00
|
|
|
const location = useLocation()
|
|
|
|
const [now,setNow] = useState<string>('首页')
|
|
|
|
const [pathArray,setPathArray] = useState([ { title: <Link to={'/home'}>首页</Link> }])
|
|
|
|
useEffect(()=>{
|
|
|
|
// const nowname = sessionStorage.getItem('now')
|
|
|
|
console.log( '路由名字', location.pathname);
|
2024-05-08 17:54:01 +08:00
|
|
|
if(location.pathname.includes('/home') ){
|
2024-05-07 17:00:32 +08:00
|
|
|
setNow('首页')
|
|
|
|
setPathArray([ { title: <Link to={'/home'}>首页</Link> }])
|
2024-05-08 17:54:01 +08:00
|
|
|
}else if(location.pathname.includes('/proj-create') ){
|
2024-05-07 17:00:32 +08:00
|
|
|
setNow('创建项目')
|
2024-05-08 17:54:01 +08:00
|
|
|
setPathArray([ { title: <Link to={'/home'}>首页</Link> },{title: <Link to={'/proj-create'}>创建项目</Link>}])
|
|
|
|
//
|
|
|
|
}else if(location.pathname.includes('/proj-edit')){
|
|
|
|
setNow('编辑项目')
|
|
|
|
setPathArray([ { title: <Link to={'/home'}>首页</Link> },{title: <Link to={'/proj-create'}>创建项目</Link>},{title: <Link to={location.pathname}>编辑项目</Link>}])
|
2024-05-07 17:00:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
},[location.pathname])
|
2024-03-28 19:35:54 +08:00
|
|
|
useEffect(() => {
|
2024-05-07 17:00:32 +08:00
|
|
|
|
|
|
|
sessionStorage.setItem('pathArray', JSON.stringify([ { title: <Link to={'/home'}>首页</Link> }]));
|
|
|
|
sessionStorage.setItem('now', '首页');
|
2024-04-01 20:39:22 +08:00
|
|
|
if (searchParams.get('type') == 'agent') {
|
2024-03-28 19:35:54 +08:00
|
|
|
dispatch({
|
|
|
|
type: IndexListDataType.AGENT,
|
2024-05-07 17:00:32 +08:00
|
|
|
value: 'ALL',
|
|
|
|
|
2024-03-28 19:35:54 +08:00
|
|
|
})
|
2024-05-07 17:00:32 +08:00
|
|
|
|
2024-03-28 19:35:54 +08:00
|
|
|
}
|
2024-05-07 17:00:32 +08:00
|
|
|
|
|
|
|
|
2024-03-28 19:35:54 +08:00
|
|
|
}, []);
|
2024-05-07 17:00:32 +08:00
|
|
|
|
|
|
|
// useEffect(() => {
|
|
|
|
// console.log('监听',keywords);
|
|
|
|
// }, [keywords]);
|
|
|
|
|
|
|
|
const handleSearch = (value: string) => {
|
|
|
|
console.log(value);
|
|
|
|
nav('/home',{state:{
|
|
|
|
keyword:value
|
|
|
|
}})
|
|
|
|
}
|
2024-03-27 18:56:48 +08:00
|
|
|
return (
|
|
|
|
<>
|
2024-04-29 17:22:26 +08:00
|
|
|
{/* <Breadcrumb
|
2024-03-27 18:56:48 +08:00
|
|
|
items={[
|
|
|
|
{title: <Link to={'/'}>首页</Link>}
|
|
|
|
]}
|
2024-04-29 17:22:26 +08:00
|
|
|
/> */}
|
2024-05-07 17:00:32 +08:00
|
|
|
<IndexListContext.Provider value={listData} >
|
2024-03-27 18:56:48 +08:00
|
|
|
<IndexListDispatchContext.Provider value={dispatch}>
|
|
|
|
<div className="index">
|
|
|
|
<div className="left">
|
|
|
|
<MenuWithTopButton
|
|
|
|
button={projMenu.button}
|
|
|
|
list={projMenu.list}
|
|
|
|
handleListItem={projMenu.handleListItem}
|
|
|
|
/>
|
2024-04-29 17:22:26 +08:00
|
|
|
<MenuTreeWithTopButton />
|
|
|
|
<MenuWithBottomButtom
|
2024-03-27 18:56:48 +08:00
|
|
|
button={agentMenu.button}
|
|
|
|
list={agentMenu.list}
|
|
|
|
handleListItem={agentMenu.handleListItem}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="right">
|
2024-05-07 17:00:32 +08:00
|
|
|
<div>
|
|
|
|
<div className="top">
|
|
|
|
{/* 标签 */}
|
|
|
|
{/* {renderStatus()} */}
|
|
|
|
<div className='gps'>
|
|
|
|
<img src={gpsImg} alt="" />
|
|
|
|
<div>当前位置:{ now}</div>
|
|
|
|
</div>
|
|
|
|
<div className='line'></div>
|
|
|
|
<Search placeholder="输入项目名称" onSearch={handleSearch} style={{
|
|
|
|
width: '253px',
|
|
|
|
height: '31px',
|
|
|
|
}} />
|
|
|
|
<div className='nowPosition'>
|
|
|
|
<img src={backImg} alt="" />
|
|
|
|
<div>
|
|
|
|
<Breadcrumb
|
|
|
|
separator="|"
|
|
|
|
// items={[
|
|
|
|
// { title: <Link to={'/home'}>首页</Link> },
|
|
|
|
// ]}
|
|
|
|
items={pathArray}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/* {
|
2024-03-27 18:56:48 +08:00
|
|
|
listData.type === IndexListDataType.PROJ ? <ListProj/> : (
|
|
|
|
listData.type == IndexListDataType.AGENT ? <ListProjAgent/> : <></>
|
|
|
|
)
|
2024-05-07 17:00:32 +08:00
|
|
|
} */}
|
|
|
|
<Outlet></Outlet>
|
2024-03-27 18:56:48 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</IndexListDispatchContext.Provider>
|
|
|
|
</IndexListContext.Provider>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|