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

65 lines
1.9 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-03-19 19:19:07 +08:00
import {useRef, MutableRefObject, useState, useEffect} from "react";
2024-03-13 16:11:28 +08:00
import {Input, Pagination} from 'antd';
import type {SearchProps} from 'antd/es/input/Search';
2024-03-19 19:19:07 +08:00
import {Axios} from "../../util/AjaxUtils.ts";
2024-03-13 16:11:28 +08:00
2024-03-16 23:12:49 +08:00
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-19 19:19:07 +08:00
const [page, _setPage] = useState(1);
const [total, _setTotal] = useState(0);
const [projs, _setProjs] = useState([]);
2024-03-16 23:12:49 +08:00
const domHeight = window.innerHeight - 280;
2024-03-13 16:11:28 +08:00
2024-03-19 19:19:07 +08:00
const renderData = () => {
Axios.get('/api/proj/listpage/self', {
params: {
page: page,
rows: 20
}
}).then(res => {
const data = res.data;
_setProjs(data.page);
_setTotal(data.total);
_setProjs(data.rows);
}).catch(res => {
console.log(res);
})
}
const renderList = () => {
return projs.map((item, index) => <CardProj item={item} key={`proj${index}`}/>);
}
useEffect(() => {
renderData();
}, [])
2024-03-13 16:11:28 +08:00
return (
<div className="list-proj" ref={listProjRef}>
<div className="top">
<Search placeholder="按项目名搜索" onSearch={onSearch} style={{width: 200}}/>
</div>
<div className="body">
<div className="list" ref={listRef} style={{height: `${domHeight}px`}}>
2024-03-19 19:19:07 +08:00
{renderList()}
2024-03-13 16:11:28 +08:00
</div>
<div className="page">
2024-03-19 19:19:07 +08:00
<Pagination defaultCurrent={page} total={total}/>
2024-03-13 16:11:28 +08:00
</div>
</div>
</div>
)
}