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

361 lines
16 KiB
TypeScript
Raw Normal View History

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-05-21 11:21:34 +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-05-12 07:45:51 +08:00
2024-05-07 17:00:32 +08:00
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);
2024-05-21 11:21:34 +08:00
sellMenu.list.forEach(item => item.active = false);
buyMenu.list.forEach(item => item.active = false);
2024-04-01 20:39:22 +08:00
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-04-29 17:22:26 +08:00
},
2024-03-27 18:56:48 +08:00
2024-05-07 17:00:32 +08:00
});
2024-05-21 11:21:34 +08:00
// const [agentMenu, setAgentMenu] = useState<IMenuWithTopButton>({
// button: {
// name: '代理服务',
// handle() {
// dispatch({
// type: IndexListDataType.PROJ,
// value: 'COMPLETE',
// })
// }
// },
// list: [
// { id: 'ALL', name: '全部项目' },
// { id: 'PROCESSING', name: '进行中的' },
// { id: 'COMPLETE', name: '已完成的' },
// ],
// handleListItem(_e: MouseEvent<HTMLLIElement>, _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 [sellMenu, setSellMenu] = useState<IMenuWithTopButton>({
2024-03-27 18:56:48 +08:00
button: {
2024-05-21 11:21:34 +08:00
name: '我要卖',
2024-03-27 18:56:48 +08:00
handle() {
2024-05-21 11:21:34 +08:00
// dispatch({
// type: IndexListDataType.PROJ,
// value: 'COMPLETE',
// })
2024-03-27 18:56:48 +08:00
}
},
list: [
2024-05-21 11:21:34 +08:00
{ id: '1', name: '商品发布', path: '/product-release' },
{ id: '2', name: '交易订单', path: '/transaction-order' },
// { 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);
2024-05-21 11:21:34 +08:00
sellMenu.list.forEach(item => item.active = false);
buyMenu.list.forEach(item => item.active = false);
2024-04-01 20:39:22 +08:00
item.active = true;
2024-05-21 11:21:34 +08:00
setSellMenu({
...sellMenu
2024-04-01 20:39:22 +08:00
})
2024-05-21 11:21:34 +08:00
// dispatch({
// type: IndexListDataType.AGENT,
// value: item.id,
2024-05-12 07:45:51 +08:00
2024-05-21 11:21:34 +08:00
// })
}
})
const [buyMenu, setBuyMenu] = useState<IMenuWithTopButton>({
button: {
name: '我要买',
handle() {
// dispatch({
// type: IndexListDataType.PROJ,
// value: 'COMPLETE',
// })
}
},
list: [
{ id: '1', name: '著作权商品', path: '/copyright-goods' },
{ id: '2', name: '交易商品', path: '/trading-goods' },
// { id: 'COMPLETE', name: '已完成的' },
],
handleListItem(_e: MouseEvent<HTMLLIElement>, _index: number, item: IMenuListItem) {
projMenu.list.forEach(item => item.active = false);
sellMenu.list.forEach(item => item.active = false);
buyMenu.list.forEach(item => item.active = false);
item.active = true;
setBuyMenu({
...buyMenu
2024-03-27 18:56:48 +08:00
})
2024-05-21 11:21:34 +08:00
// dispatch({
// type: IndexListDataType.AGENT,
// value: item.id,
// })
2024-03-27 18:56:48 +08:00
}
2024-04-01 20:39:22 +08:00
})
2024-05-21 11:21:34 +08:00
2024-05-07 17:00:32 +08:00
const location = useLocation()
2024-05-12 07:45:51 +08:00
const [now, setNow] = useState<string>('首页')
// 编辑项目路由名
// const [editname,setEditname] = useState('')
// 新建项目路由名字
// const [newname,setNewname] = useState('')
const [pathArray, setPathArray] = useState<any>([])
useEffect(() => {
2024-05-07 17:00:32 +08:00
// const nowname = sessionStorage.getItem('now')
2024-05-12 07:45:51 +08:00
console.log('路由名字', location.pathname);
if (location.pathname.includes('/home')) {
2024-05-07 17:00:32 +08:00
setNow('首页')
2024-05-12 07:45:51 +08:00
setPathArray([{ title: '首页' }])
} else if (location.pathname.includes('/proj-create')) {
2024-05-07 17:00:32 +08:00
setNow('创建项目')
2024-05-12 07:45:51 +08:00
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: '创建项目' }])
2024-05-21 11:21:34 +08:00
// /config-mod-list /config-menu-list
} else if (location.pathname.includes('/proj-edit')&& !location.pathname.includes('/config-mod-edit') && !location.pathname.includes('/step') && !location.pathname.includes('/config-loginpage')&& !location.pathname.includes('/config-mod-save')&& !location.pathname.includes('/config-mod-list')&& !location.pathname.includes('/config-menu-list')) {
2024-05-12 07:45:51 +08:00
setNow('编辑项目')
// setEditname(location.pathname)
2024-05-15 18:00:20 +08:00
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: <Link to={'/proj-create'}></Link> }, { title: '编辑项目' }])
2024-05-12 07:45:51 +08:00
} else if (location.pathname.includes('/proj-new')) {
setNow('新建项目')
// setNewname(location.pathname)
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: <Link to={'/proj-create'}></Link> }, { title: '新建项目' }])
2024-05-15 18:00:20 +08:00
} else if (location.pathname.includes('/proj-efree')) {
2024-05-12 07:45:51 +08:00
setNow('编辑项目')
// setNewname(location.pathname)
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: <Link to={'/proj-create'}></Link> }, { title: '编辑项目' }])
2024-05-15 18:00:20 +08:00
} else if (location.pathname.includes('/proj-eall')) {
2024-05-08 17:54:01 +08:00
setNow('编辑项目')
2024-05-12 07:45:51 +08:00
// setNewname(location.pathname)
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: <Link to={'/proj-create'}></Link> }, { title: '编辑项目' }])
2024-05-15 18:00:20 +08:00
} else if (location.pathname.includes('/proj-edit/step1')) {
2024-05-12 07:45:51 +08:00
setNow('标题简介')
// setNewname(location.pathname)
2024-05-15 18:00:20 +08:00
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: <Link to={'/proj-create'}></Link> }, { title: <a onClick={() => { nav(-1) }}></a> }, { title: '标题简介' }])
} else if (location.pathname.includes('/proj-edit/step2')) {
2024-05-12 07:45:51 +08:00
setNow('标题简介')
// setNewname(location.pathname)
2024-05-15 18:00:20 +08:00
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: <Link to={'/proj-create'}></Link> }, { title: <a onClick={() => { nav(-1) }}></a> }, { title: '基本信息' }])
2024-05-21 11:21:34 +08:00
} else if (location.pathname.includes('/proj-edit/config-loginpage')) {
2024-05-16 18:00:57 +08:00
setNow('登录界面设置')
// setNewname(location.pathname)
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: <Link to={'/proj-create'}></Link> }, { title: <a onClick={() => { nav(-1) }}></a> }, { title: '登录界面设置' }])
2024-05-21 11:21:34 +08:00
}else if (location.pathname.includes('/proj-edit/config-mod-list')) {
setNow('系统菜单管理')
// setNewname(location.pathname)
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: <Link to={'/proj-create'}></Link> }, { title: <a onClick={() => { nav(-1) }}></a> }, { title: '系统菜单管理' }])
}else if (location.pathname.includes('/proj-edit/config-menu-list')) {
setNow('系统菜单顺序')
// setNewname(location.pathname)
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: <Link to={'/proj-create'}></Link> }, { title: <a onClick={() => { nav(-1) }}></a> }, { title: '系统菜单顺序' }])
}else if (location.pathname.includes('/step3')) {
setNow('软件功能特点')
// setNewname(location.pathname)
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: <Link to={'/proj-create'}></Link> }, { title: <a onClick={() => { nav(-1) }}></a> }, { title: '软件功能特点' }])
}else if (location.pathname.includes('/proj-edit/config-mod-save')) {
setNow('添加菜单')
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: <Link to={'/proj-create'}></Link> }, { title: <a onClick={() => { nav(-1) }}></a> }, { title: '添加菜单' }])
}else if (location.pathname.includes('/proj-edit/config-mod-edit')) {
setNow('编辑菜单')
setPathArray([{ title: <Link to={'/home'}></Link> }, { title: <Link to={'/proj-create'}></Link> }, { title: <a onClick={() => { nav(-2) }}></a> },{ title: <a onClick={() => { nav(-1) }}></a> }, { title: '编辑菜单' }])
// /config-mod-edit
2024-05-07 17:00:32 +08:00
}
2024-05-12 07:45:51 +08:00
}, [location.pathname])
2024-03-28 19:35:54 +08:00
useEffect(() => {
2024-05-21 11:21:34 +08:00
// nav('/home')
// 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);
2024-05-12 07:45:51 +08:00
nav('/home', {
state: {
keyword: value
}
})
2024-05-07 17:00:32 +08:00
}
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">
2024-05-21 11:21:34 +08:00
<div style={{ height: '15px', width: '230px', background: 'white' }}></div>
2024-03-27 18:56:48 +08:00
<MenuWithTopButton
button={projMenu.button}
list={projMenu.list}
handleListItem={projMenu.handleListItem}
/>
2024-04-29 17:22:26 +08:00
<MenuTreeWithTopButton />
2024-05-15 18:00:20 +08:00
{/* <MenuWithBottomButtom
button={agentMenu.button}
list={agentMenu.list}
handleListItem={agentMenu.handleListItem}
/> */}
2024-05-21 11:21:34 +08:00
{/* <MenuWithBottomButtom
button={sellMenu.button}
list={sellMenu.list}
handleListItem={sellMenu.handleListItem}
/>
<MenuWithBottomButtom
button={buyMenu.button}
list={buyMenu.list}
handleListItem={buyMenu.handleListItem}
/> */}
2024-03-27 18:56:48 +08:00
</div>
<div className="right">
2024-05-07 17:00:32 +08:00
<div>
<div className="top">
{/* 标签 */}
{/* {renderStatus()} */}
<div className='gps'>
<img src={gpsImg} alt="" />
2024-05-12 07:45:51 +08:00
<div>:{now}</div>
2024-05-07 17:00:32 +08:00
</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
} */}
2024-05-12 07:45:51 +08:00
<div>
<Outlet></Outlet>
</div>
2024-03-27 18:56:48 +08:00
</div>
</div>
</IndexListDispatchContext.Provider>
</IndexListContext.Provider>
</>
)
}