2024-03-13 16:11:28 +08:00
|
|
|
import './list-proj.css'
|
|
|
|
import CardProj from "../card/CardProj.tsx";
|
2024-03-19 19:19:07 +08:00
|
|
|
import {useRef, MutableRefObject, useState, useEffect} from "react";
|
2024-03-20 18:30:39 +08:00
|
|
|
import {Input, Pagination, message} from 'antd';
|
2024-03-13 16:11:28 +08:00
|
|
|
import type {SearchProps} from 'antd/es/input/Search';
|
2024-03-20 18:30:39 +08:00
|
|
|
import {get} from "../../util/AjaxUtils.ts";
|
2024-03-13 16:11:28 +08:00
|
|
|
|
|
|
|
const {Search} = Input;
|
|
|
|
|
2024-03-13 19:01:21 +08:00
|
|
|
const onSearch: SearchProps['onSearch'] = (value, _e, info) => {
|
|
|
|
console.log(info?.source, value)
|
|
|
|
};
|
2024-03-13 16:11:28 +08:00
|
|
|
|
|
|
|
export default function ListProj() {
|
|
|
|
|
|
|
|
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);
|
|
|
|
const [projs, setProjs] = 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) => {
|
|
|
|
get({
|
|
|
|
messageApi: messageApi,
|
|
|
|
url: '/api/proj/listpage/self',
|
|
|
|
config: {
|
|
|
|
params: {
|
|
|
|
page: currentPage,
|
|
|
|
rows: 20
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onSuccess({data}) {
|
|
|
|
setProjs(data.page);
|
|
|
|
setTotal(data.total);
|
|
|
|
setProjs(data.rows);
|
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-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">
|
|
|
|
<Search placeholder="按项目名搜索" onSearch={onSearch} style={{width: 200}}/>
|
2024-03-13 16:11:28 +08:00
|
|
|
</div>
|
2024-03-20 18:30:39 +08:00
|
|
|
<div className="body">
|
|
|
|
<div className="list" ref={listRef} style={{height: `${domHeight}px`}}>
|
|
|
|
{renderList()}
|
|
|
|
</div>
|
|
|
|
<div className="page">
|
|
|
|
<Pagination defaultCurrent={page} total={total} onChange={(page) => {
|
|
|
|
setPage(page);
|
|
|
|
reqData(page);
|
|
|
|
}}/>
|
|
|
|
</div>
|
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
|
|
|
)
|
|
|
|
}
|