forked from wangziqi/gongxue-base
fix: restore RoomPage component wrapper and fix action column
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState, useMemo } from 'react';
|
import React, { useEffect, useState, useMemo, useCallback } from 'react';
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
Button,
|
Button,
|
||||||
@@ -63,6 +63,8 @@ function parseRoomNumber(input: string) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const RoomsPage: React.FC = () => {
|
||||||
|
const [data, setData] = useState<any[]>([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [modalOpen, setModalOpen] = useState(false);
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
const [editing, setEditing] = useState<any>(null);
|
const [editing, setEditing] = useState<any>(null);
|
||||||
@@ -156,20 +158,19 @@ function parseRoomNumber(input: string) {
|
|||||||
setSaving(false);
|
setSaving(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const fetchBeds = useCallback(async (roomId: number) => {
|
||||||
const fetchBeds = async (roomId: number) => {
|
|
||||||
try {
|
try {
|
||||||
const res = await api.get(`/rooms/${roomId}/beds`);
|
const res = await api.get(`/rooms/${roomId}/beds`);
|
||||||
setBeds(res);
|
setBeds(res);
|
||||||
} catch (e) { console.error(e); }
|
} catch (e) { console.error(e); }
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
const fetchLockers = async (roomId: number) => {
|
const fetchLockers = useCallback(async (roomId: number) => {
|
||||||
try {
|
try {
|
||||||
const res = await api.get(`/rooms/${roomId}/lockers`);
|
const res = await api.get(`/rooms/${roomId}/lockers`);
|
||||||
setLockers(res);
|
setLockers(res);
|
||||||
} catch (e) { console.error(e); }
|
} catch (e) { console.error(e); }
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
const handleSaveBed = async () => {
|
const handleSaveBed = async () => {
|
||||||
const values = await bedForm.validateFields();
|
const values = await bedForm.validateFields();
|
||||||
@@ -325,54 +326,57 @@ function parseRoomNumber(input: string) {
|
|||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
width: 220,
|
width: 220,
|
||||||
render: (_: any, record: any) => (
|
render: (_: unknown, record: unknown) => {
|
||||||
<Space>
|
const r = record as { status?: string; id: number };
|
||||||
{record.status === 'archived' ? (
|
return (
|
||||||
<Popconfirm
|
<Space>
|
||||||
title="确定恢复此宿舍?恢复后将重新出现在宿舍总览中。"
|
{r.status === 'archived' ? (
|
||||||
onConfirm={() => handleRestore(record.id)}
|
|
||||||
okText="恢复"
|
|
||||||
cancelText="取消"
|
|
||||||
>
|
|
||||||
<PermissionButton permission="room:edit" size="small" icon={<UndoOutlined />} type="link">
|
|
||||||
恢复
|
|
||||||
</PermissionButton>
|
|
||||||
<PermissionButton
|
|
||||||
permission="room:view"
|
|
||||||
size="small"
|
|
||||||
type="link"
|
|
||||||
onClick={async () => {
|
|
||||||
setDrawerRoom(record);
|
|
||||||
setDrawerOpen(true);
|
|
||||||
await Promise.all([fetchBeds(record.id), fetchLockers(record.id)]);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
查看
|
|
||||||
</PermissionButton>
|
|
||||||
<PermissionButton
|
|
||||||
permission="room:edit"
|
|
||||||
size="small"
|
|
||||||
onClick={() => {
|
|
||||||
setEditing(record);
|
|
||||||
form.setFieldsValue(record);
|
|
||||||
setModalOpen(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
编辑
|
|
||||||
</PermissionButton>
|
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title="归档后不会删除数据,可随时恢复。有在住人员将无法归档。"
|
title="确定恢复此宿舍?"
|
||||||
onConfirm={() => handleArchive(record.id)}
|
onConfirm={() => handleRestore(r.id)}
|
||||||
okText="归档"
|
|
||||||
cancelText="取消"
|
|
||||||
>
|
>
|
||||||
<PermissionButton permission="room:delete" size="small" icon={<InboxOutlined />}>
|
<PermissionButton permission="room:edit" size="small" icon={<UndoOutlined />} type="link">
|
||||||
归档
|
恢复
|
||||||
</PermissionButton>
|
</PermissionButton>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</>
|
) : (
|
||||||
)}
|
<>
|
||||||
</Space>
|
<PermissionButton
|
||||||
|
permission="room:view"
|
||||||
|
size="small"
|
||||||
|
type="link"
|
||||||
|
onClick={async () => {
|
||||||
|
const rec = record as { id: number };
|
||||||
|
setDrawerRoom(record);
|
||||||
|
setDrawerOpen(true);
|
||||||
|
await Promise.all([fetchBeds(rec.id), fetchLockers(rec.id)]);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
查看
|
||||||
|
</PermissionButton>
|
||||||
|
<PermissionButton
|
||||||
|
permission="room:edit"
|
||||||
|
size="small"
|
||||||
|
onClick={() => {
|
||||||
|
const rec = record as { id: number };
|
||||||
|
setEditing(rec);
|
||||||
|
form.setFieldsValue(rec);
|
||||||
|
setModalOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</PermissionButton>
|
||||||
|
<Popconfirm title="确定归档?" onConfirm={() => handleArchive(r.id)}>
|
||||||
|
<PermissionButton permission="room:delete" size="small" icon={<InboxOutlined />}>
|
||||||
|
归档
|
||||||
|
</PermissionButton>
|
||||||
|
</Popconfirm>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
], [showArchived, buildings, handleBatchDelete, handleRestore, handleArchive, fetchBeds, fetchLockers]);
|
], [showArchived, buildings, handleBatchDelete, handleRestore, handleArchive, fetchBeds, fetchLockers]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user