|
|
@@ -25,6 +25,7 @@ const Files: React.FC = () => {
|
|
|
pageSize: 10,
|
|
|
total: 0,
|
|
|
});
|
|
|
+
|
|
|
const queryClient = useQueryClient();
|
|
|
|
|
|
|
|
|
@@ -40,20 +41,13 @@ const Files: React.FC = () => {
|
|
|
queryFn: () => fetchFiles({ page: pagination.current, pageSize: pagination.pageSize }),
|
|
|
});
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- if (data) {
|
|
|
- setPagination(prev => ({
|
|
|
- ...prev,
|
|
|
- total: data.pagination.total,
|
|
|
- }));
|
|
|
- }
|
|
|
- }, [data]);
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- if (filesError) {
|
|
|
- message.error(`获取文件列表失败: ${filesError instanceof Error ? filesError.message : '未知错误'}`);
|
|
|
- }
|
|
|
- }, [filesError]);
|
|
|
+ // 错误处理
|
|
|
+ if (filesError) {
|
|
|
+ message.error(`获取文件列表失败: ${filesError instanceof Error ? filesError.message : '未知错误'}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 从API响应获取分页数据
|
|
|
+ const tablePagination = data?.pagination || pagination;
|
|
|
|
|
|
// 搜索
|
|
|
const handleSearch = () => {
|
|
|
@@ -116,7 +110,7 @@ const Files: React.FC = () => {
|
|
|
setModalVisible(false);
|
|
|
},
|
|
|
onError: (error: Error) => {
|
|
|
- message.error(`操作失败: ${error.message}`);
|
|
|
+ message.error(`操作失败: ${error instanceof Error ? error.message : '未知错误'}`);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -128,7 +122,7 @@ const Files: React.FC = () => {
|
|
|
queryClient.invalidateQueries({ queryKey: ['files'] });
|
|
|
},
|
|
|
onError: (error: Error) => {
|
|
|
- message.error(`删除失败: ${error.message}`);
|
|
|
+ message.error(`删除失败: ${error instanceof Error ? error.message : '未知错误'}`);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -254,7 +248,7 @@ const Files: React.FC = () => {
|
|
|
dataSource={data?.data || []}
|
|
|
rowKey="id"
|
|
|
loading={loading}
|
|
|
- pagination={pagination}
|
|
|
+ pagination={tablePagination}
|
|
|
onChange={handleTableChange}
|
|
|
bordered
|
|
|
/>
|