2024-03-13 16:11:28 +08:00
|
|
|
import './list-proj.css'
|
|
|
|
import CardProj from "../card/CardProj.tsx";
|
2024-03-27 18:56:48 +08:00
|
|
|
import {useRef, MutableRefObject, useState, useEffect, useContext} from "react";
|
|
|
|
import {Input, Pagination, message, Spin} from 'antd';
|
2024-03-20 18:30:39 +08:00
|
|
|
import {get} from "../../util/AjaxUtils.ts";
|
2024-03-27 18:56:48 +08:00
|
|
|
import {IndexListContext} from "../../context/IndexListContext.ts";
|
|
|
|
import {IListPage} from "../../interfaces/listpage/IListPage.ts";
|
|
|
|
import {IProj} from "../../interfaces/proj/IProj.ts";
|
2024-03-13 16:11:28 +08:00
|
|
|
|
|
|
|
const {Search} = Input;
|
|
|
|
|
|
|
|
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,
|
|
|
|
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-03-20 18:30:39 +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 = () => {
|
|
|
|
return projs.map((item, index) => <CardProj item={item} key={`proj${index}`}/>);
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
2024-03-20 18:30:39 +08:00
|
|
|
reqData(page);
|
2024-03-27 18:56:48 +08:00
|
|
|
}, [indexListContext.status, keywords, page])
|
2024-03-19 19:19:07 +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-03-27 18:56:48 +08:00
|
|
|
<Search placeholder="按项目名搜索" onSearch={(value) => {
|
|
|
|
setKeywords(value)
|
|
|
|
}} style={{width: 200}}/>
|
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}>
|
|
|
|
<div className="list" ref={listRef} style={{height: `${domHeight}px`}}>
|
|
|
|
{renderList()}
|
|
|
|
</div>
|
|
|
|
<div className="page">
|
|
|
|
<Pagination defaultCurrent={page} total={total} onChange={(page) => {
|
|
|
|
setPage(page);
|
|
|
|
}}/>
|
|
|
|
</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
|
|
|
)
|
|
|
|
}
|