system-copyright-react/src/components/list/ListProj.tsx

145 lines
5.3 KiB
TypeScript
Raw Normal View History

2024-03-13 16:11:28 +08:00
import './list-proj.css'
import CardProj from "../card/CardProj.tsx";
2024-04-29 17:22:26 +08:00
import { useRef, MutableRefObject, useState, useEffect, useContext } from "react";
import { Input, Pagination, message, Spin, Image } from 'antd';
import { get } from "../../util/AjaxUtils.ts";
import { IndexListContext } from "../../context/IndexListContext.ts";
import { IListPage } from "../../interfaces/listpage/IListPage.ts";
import { IProj } from "../../interfaces/proj/IProj.ts";
2024-03-28 19:35:54 +08:00
import NoData from "../../assets/no-data.png";
2024-04-29 17:22:26 +08:00
import gpsImg from '../../static/right/gps.png'
import { Link } from "react-router-dom";
import { Breadcrumb } from 'antd';
import backImg from '../../static/right/back.png'
const { Search } = Input;
2024-03-13 16:11:28 +08:00
export default function ListProj() {
2024-03-27 18:56:48 +08:00
const indexListContext = useContext(IndexListContext);
2024-03-13 16:11:28 +08:00
const listProjRef: MutableRefObject<HTMLDivElement | null> = useRef(null);
const listRef: MutableRefObject<HTMLDivElement | null> = useRef(null);
2024-03-20 18:30:39 +08:00
const [messageApi, contextHolder] = message.useMessage();
const [page, setPage] = useState(1);
const [total, setTotal] = useState(0);
2024-03-27 18:56:48 +08:00
const [projs, setProjs] = useState<IProj[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [keywords, setKeywords] = useState('');
2024-03-19 19:19:07 +08:00
2024-03-16 23:12:49 +08:00
const domHeight = window.innerHeight - 280;
2024-03-13 16:11:28 +08:00
2024-03-20 18:30:39 +08:00
const reqData = (currentPage: number) => {
2024-03-27 18:56:48 +08:00
get<IListPage<IProj>>({
2024-03-20 18:30:39 +08:00
messageApi: messageApi,
url: '/api/proj/listpage/self',
config: {
params: {
page: currentPage,
2024-03-27 18:56:48 +08:00
rows: 20,
keywords: keywords,
2024-04-01 20:39:22 +08:00
projCategoryId: indexListContext.category,
2024-03-27 18:56:48 +08:00
status: indexListContext.status ? indexListContext.status : ''
2024-03-20 18:30:39 +08:00
}
},
2024-03-27 18:56:48 +08:00
onBefore() {
setIsLoading(true);
},
2024-04-29 17:22:26 +08:00
onSuccess({ data }) {
2024-03-27 18:56:48 +08:00
setPage(data.page);
2024-03-20 18:30:39 +08:00
setTotal(data.total);
setProjs(data.rows);
2024-03-27 18:56:48 +08:00
},
onFinally() {
setIsLoading(false);
2024-03-19 19:19:07 +08:00
}
})
}
const renderList = () => {
2024-04-01 20:39:22 +08:00
if (projs.length == 0) {
2024-03-28 19:35:54 +08:00
return (
2024-04-01 20:39:22 +08:00
<div className="no-data" style={{
width: '100%',
height: '100%',
backgroundColor: 'var(--color-light)',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center'
}}>
2024-04-29 17:22:26 +08:00
<Image src={NoData} preview={false} />
2024-03-28 19:35:54 +08:00
<span></span>
</div>
)
}
2024-04-02 18:45:46 +08:00
return projs.map((item) => {
2024-04-29 17:22:26 +08:00
return <CardProj item={item} key={new Date().getTime() + ':' + item.projId} />;
2024-04-01 20:39:22 +08:00
});
}
const renderCategory = () => {
2024-03-19 19:19:07 +08:00
}
useEffect(() => {
2024-04-02 18:45:46 +08:00
if (indexListContext.categorys) {
reqData(page);
renderCategory();
}
}, [indexListContext.status, indexListContext.categoryChangeCount, indexListContext.category, keywords, page])
2024-03-19 19:19:07 +08:00
2024-04-29 17:22:26 +08:00
// const renderStatus = () => {
// if (indexListContext.status == 'ALL') {
// return <Tag color="blue">项目:全部项目</Tag>
// } else if (indexListContext.status == 'PROCESSING') {
// return <Tag color="blue">项目:进行中的</Tag>
// } else if (indexListContext.status == 'COMPLETE') {
// return <Tag color="blue">项目:已完成的</Tag>
// }
// return <></>
// }
2024-03-28 19:35:54 +08:00
2024-03-13 16:11:28 +08:00
return (
2024-03-20 18:30:39 +08:00
<>
{contextHolder}
<div className="list-proj" ref={listProjRef}>
<div className="top">
2024-04-29 17:22:26 +08:00
{/* 标签 */}
{/* {renderStatus()} */}
<div className='gps'>
<img src={gpsImg} alt="" />
<div>当前位置:首页</div>
</div>
<div className='line'></div>
<Search placeholder="输入项目名称" onSearch={(value) => {
2024-03-27 18:56:48 +08:00
setKeywords(value)
2024-04-29 17:22:26 +08:00
}} style={{
width: '253px',
height: '31px',
}} />
<div className='nowPosition'>
<img src={backImg} alt="" />
<div>
<Breadcrumb
separator="|"
items={[
{ title: <Link to={'/'}></Link> },
]}
/>
</div>
</div>
2024-03-13 16:11:28 +08:00
</div>
2024-03-20 18:30:39 +08:00
<div className="body">
2024-03-27 18:56:48 +08:00
<Spin tip="加载中..." spinning={isLoading}>
2024-04-29 17:22:26 +08:00
<div className="list" ref={listRef} style={{ height: `${domHeight}px` }}>
2024-03-27 18:56:48 +08:00
{renderList()}
</div>
<div className="page">
<Pagination defaultCurrent={page} total={total} onChange={(page) => {
setPage(page);
2024-04-29 17:22:26 +08:00
}} />
2024-03-27 18:56:48 +08:00
</div>
</Spin>
2024-03-13 16:11:28 +08:00
</div>
</div>
2024-03-20 18:30:39 +08:00
</>
2024-03-13 16:11:28 +08:00
)
}