system-copyright-react/src/route/index/Index.tsx

149 lines
5.4 KiB
TypeScript
Raw Normal View History

2024-03-27 18:56:48 +08:00
import './index.css';
2024-04-01 20:39:22 +08:00
import {MouseEvent, Reducer, useEffect, useReducer, useState} from "react";
2024-04-29 17:22:26 +08:00
import { useNavigate, useSearchParams} from "react-router-dom";
2024-03-27 18:56:48 +08:00
import {IMenuListItem, IMenuWithTopButton} from "../../interfaces/menu/IMenuWithTopButton.ts";
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";
import ListProj from "../../components/list/ListProj.tsx";
import ListProjAgent from "../../components/list/ListProjAgent.tsx";
2024-04-29 17:22:26 +08:00
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";
export default function Index() {
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-04-29 17:22:26 +08:00
{id: 'ALL', name: '全部项目',active:true},
2024-03-27 18:56:48 +08:00
{id: 'PROCESSING', name: '进行中的'},
{id: 'COMPLETE', name: '已完成的'}
],
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,
value: item.id
})
2024-04-29 17:22:26 +08:00
},
2024-04-01 20:39:22 +08:00
});
2024-03-27 18:56:48 +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,
value: 'COMPLETE'
})
2024-03-27 18:56:48 +08:00
}
},
list: [
{id: 'ALL', name: '全部项目'},
{id: 'PROCESSING', name: '进行中的'},
{id: 'COMPLETE', name: '已完成的'},
],
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,
value: item.id
})
}
2024-04-01 20:39:22 +08:00
})
2024-03-28 19:35:54 +08:00
useEffect(() => {
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,
value: 'ALL'
})
}
}, []);
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-03-27 18:56:48 +08:00
<IndexListContext.Provider value={listData}>
<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">
{
listData.type === IndexListDataType.PROJ ? <ListProj/> : (
listData.type == IndexListDataType.AGENT ? <ListProjAgent/> : <></>
)
}
</div>
</div>
</IndexListDispatchContext.Provider>
</IndexListContext.Provider>
</>
)
}