feat: add status+tenant filter to Students page, status filter to Rooms page
This commit is contained in:
@@ -45,6 +45,7 @@ const RoomsPage: React.FC = () => {
|
||||
const [archivedCount, setArchivedCount] = useState(0);
|
||||
const [searchText, setSearchText] = useState('');
|
||||
const [filterBuilding, setFilterBuilding] = useState<string | undefined>(undefined);
|
||||
const [filterStatus, setFilterStatus] = useState<string | undefined>(undefined);
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<number[]>([]);
|
||||
const [form] = Form.useForm();
|
||||
|
||||
@@ -89,13 +90,12 @@ const RoomsPage: React.FC = () => {
|
||||
let result = data;
|
||||
if (searchText) {
|
||||
const keyword = searchText.toLowerCase();
|
||||
result = result.filter((r: any) => r.roomNumber?.toLowerCase().includes(keyword));
|
||||
}
|
||||
if (filterBuilding) {
|
||||
result = result.filter((r: any) => r.building === filterBuilding);
|
||||
result = result.filter((r: Record<string, unknown>) => typeof r.roomNumber === 'string' && r.roomNumber.toLowerCase().includes(keyword));
|
||||
}
|
||||
if (filterBuilding) result = result.filter((r: Record<string, unknown>) => r.building === filterBuilding);
|
||||
if (filterStatus) result = result.filter((r: Record<string, unknown>) => r.status === filterStatus);
|
||||
return result;
|
||||
}, [data, searchText, filterBuilding]);
|
||||
}, [data, searchText, filterBuilding, filterStatus]);
|
||||
|
||||
const handleSave = async () => {
|
||||
const values = await form.validateFields();
|
||||
@@ -314,6 +314,8 @@ const RoomsPage: React.FC = () => {
|
||||
onChange={(v) => setFilterBuilding(v)}
|
||||
options={buildings.map((b) => ({ value: b, label: b }))}
|
||||
/>
|
||||
<Select placeholder="状态" allowClear style={{ width: 110 }} value={filterStatus} onChange={setFilterStatus}
|
||||
options={[{value:'available',label:'可入住'},{value:'full',label:'已满'},{value:'maintenance',label:'维护中'}]} />
|
||||
<Button
|
||||
type={showArchived ? 'primary' : 'default'}
|
||||
onClick={() => setShowArchived(!showArchived)}
|
||||
|
||||
@@ -74,6 +74,8 @@ const StudentsPage: React.FC = () => {
|
||||
const [tenants, setTenants] = useState<any[]>([]);
|
||||
const [editing, setEditing] = useState<any>(null);
|
||||
const [searchName, setSearchName] = useState('');
|
||||
const [filterStatus, setFilterStatus] = useState<string | undefined>(undefined);
|
||||
const [filterTenantId, setFilterTenantId] = useState<number | undefined>(undefined);
|
||||
const [showArchived, setShowArchived] = useState(false);
|
||||
const [archivedCount, setArchivedCount] = useState(0);
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<number[]>([]);
|
||||
@@ -117,12 +119,14 @@ const StudentsPage: React.FC = () => {
|
||||
const fetchData = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const params: any = { name: searchName || undefined, includeArchived: 'true' };
|
||||
const res: any = await api.get('/students', { params });
|
||||
const archived = res.filter((r: any) => r.status === 'archived');
|
||||
const params: Record<string, unknown> = { name: searchName || undefined, includeArchived: 'true' };
|
||||
if (filterStatus) params.status = filterStatus;
|
||||
if (filterTenantId) params.tenantId = filterTenantId;
|
||||
const res = await api.get('/students', { params }) as Array<Record<string, unknown>>;
|
||||
const list = res as Array<Record<string, unknown>>;
|
||||
const archived = list.filter((r) => r.status === 'archived');
|
||||
setArchivedCount(archived.length);
|
||||
const filtered = showArchived ? res : res.filter((r: any) => r.status !== 'archived');
|
||||
setData(filtered);
|
||||
setData(showArchived ? list : list.filter((r) => r.status !== 'archived'));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
@@ -131,14 +135,13 @@ const StudentsPage: React.FC = () => {
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
}, [searchName, showArchived]);
|
||||
}, [searchName, showArchived, filterStatus, filterTenantId]);
|
||||
|
||||
useEffect(() => {
|
||||
api.get('/tenants', { params: { includeArchived: 'false' } }).then((res: unknown) => {
|
||||
setTenants(res as Array<{ id: number; name: string }>);
|
||||
}).catch(() => {});
|
||||
}, []);
|
||||
|
||||
const handleSave = async () => {
|
||||
const values = await form.validateFields();
|
||||
try {
|
||||
@@ -331,6 +334,12 @@ const StudentsPage: React.FC = () => {
|
||||
allowClear
|
||||
style={{ width: 250 }}
|
||||
/>
|
||||
<Select placeholder="状态筛选" allowClear style={{ width: 120 }} value={filterStatus} onChange={(v) => { setFilterStatus(v); }}>
|
||||
{Object.entries(statusMap).filter(([k]) => k !== 'archived').map(([k, v]) => <Select.Option key={k} value={k}>{v.text}</Select.Option>)}
|
||||
</Select>
|
||||
<Select placeholder="所属机构" allowClear style={{ width: 140 }} value={filterTenantId} onChange={(v) => { setFilterTenantId(v); }}>
|
||||
{tenants.map((t: { id: number; name: string }) => <Select.Option key={t.id} value={t.id}>{t.name}</Select.Option>)}
|
||||
</Select>
|
||||
<Button
|
||||
type={showArchived ? 'primary' : 'default'}
|
||||
onClick={() => setShowArchived(!showArchived)}
|
||||
|
||||
Reference in New Issue
Block a user