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

141 lines
5.0 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";
2024-05-12 07:45:51 +08:00
import { Pagination, message, Spin, Image } from 'antd';
2024-04-29 17:22:26 +08:00
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-05-07 17:00:32 +08:00
import { useLocation } from 'react-router-dom';
// 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-05-12 07:45:51 +08:00
const { state } = useLocation()
2024-05-07 17:00:32 +08:00
// console.log('传递过来的参数',state.keyword);
// if(state){
// console.log('传递过来的参数',state.keyword);
// // setKeywords(state.keyword)
// }
2024-05-12 07:45:51 +08:00
const keywords = state ? state.keyword : ''
2024-05-07 17:00:32 +08:00
// console.log(keywords);
2024-05-12 07:45:51 +08:00
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);
2024-05-07 17:00:32 +08:00
// const [keywords, setKeywords] = useState('');
2024-03-16 23:12:49 +08:00
const domHeight = window.innerHeight - 280;
2024-05-12 07:45:51 +08:00
// const navigate = useNavigate()
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,
2024-05-12 07:45:51 +08:00
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-05-12 07:45:51 +08:00
console.log('看看结果', 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-05-12 07:45:51 +08:00
return (
<div className='projListBox' key={new Date().getTime() + ':' + item.projId}>
<CardProj item={item} />
</div>
)
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) {
2024-05-12 07:45:51 +08:00
2024-04-02 18:45:46 +08:00
reqData(page);
renderCategory();
}
}, [indexListContext.status, indexListContext.categoryChangeCount, indexListContext.category, keywords, page])
2024-05-12 07:45:51 +08:00
useEffect(() => {
}, [indexListContext.status])
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}>
2024-05-07 17:00:32 +08:00
2024-03-20 18:30:39 +08:00
<div className="body">
2024-03-27 18:56:48 +08:00
<Spin tip="加载中..." spinning={isLoading}>
2024-05-12 07:45:51 +08:00
<div className="list" ref={listRef} style={{ height: `${domHeight}px` }}>
2024-03-27 18:56:48 +08:00
{renderList()}
</div>
2024-05-07 17:00:32 +08:00
<div className="page" >
2024-05-12 07:45:51 +08:00
<Pagination defaultCurrent={page} total={total} defaultPageSize={20} onChange={(page) => {
reqData(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
)
}