From cec5b73b3b6f1bd1c93b8d3803d7f8490d48dc08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=9A=E8=BE=B0=E5=85=88=E7=94=9F?= Date: Tue, 3 Dec 2024 00:29:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=89=E6=96=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/hooks/useTableData.ts | 8 ++--- frontend/src/pages/System/External/index.tsx | 35 ++++++++++++++++---- frontend/src/pages/System/External/types.ts | 1 + 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/frontend/src/hooks/useTableData.ts b/frontend/src/hooks/useTableData.ts index f7f59725..c42deab2 100644 --- a/frontend/src/hooks/useTableData.ts +++ b/frontend/src/hooks/useTableData.ts @@ -132,7 +132,7 @@ export function useTableData< loadData(); return true; } catch (error) { - return false; + throw error; } }; @@ -145,14 +145,14 @@ export function useTableData< loadData(); return true; } catch (error) { - return false; + throw error; } }; // 删除 const handleDelete = async (id: number) => { if (!service.delete) return false; - return new Promise((resolve) => { + return new Promise((resolve, reject) => { Modal.confirm({ title: '确认删除', content: '确定要删除该记录吗?', @@ -166,7 +166,7 @@ export function useTableData< loadData(); resolve(true); } catch (error) { - resolve(false); + reject(error); } }, onCancel: () => resolve(false) diff --git a/frontend/src/pages/System/External/index.tsx b/frontend/src/pages/System/External/index.tsx index ac66c0ab..cf8c3dd1 100644 --- a/frontend/src/pages/System/External/index.tsx +++ b/frontend/src/pages/System/External/index.tsx @@ -78,14 +78,27 @@ const ExternalPage: React.FC = () => { const handleSubmit = async () => { try { const values = await form.validateFields(); + let success = false; + if (editingSystem) { - await handleUpdate(editingSystem.id, values); + success = await handleUpdate(editingSystem.id, values); } else { - await handleCreate(values); + success = await handleCreate(values); + } + + if (success) { + setModalVisible(false); + } + } catch (error: any) { + // 如果是表单验证错误,不显示错误消息 + if (!error.errorFields) { + // 如果是后端返回的错误,显示后端的错误消息 + if (error.response?.data) { + message.error(error.response.data.message || '操作失败'); + } else { + message.error(error.message || '操作失败'); + } } - setModalVisible(false); - } catch (error) { - console.error('操作失败:', error); } }; @@ -152,6 +165,12 @@ const ExternalPage: React.FC = () => { ); } }, + { + title: '最后连接时间', + dataIndex: 'lastConnectTime', + width: 150, + render: (time: string) => time || '-' + }, { title: '状态', dataIndex: 'enabled', @@ -160,6 +179,8 @@ const ExternalPage: React.FC = () => { handleStatusChange(record.id, checked)} + checkedChildren="否" + unCheckedChildren="是" /> ) }, @@ -330,10 +351,10 @@ const ExternalPage: React.FC = () => { - + diff --git a/frontend/src/pages/System/External/types.ts b/frontend/src/pages/System/External/types.ts index 0220e6ce..26685f35 100644 --- a/frontend/src/pages/System/External/types.ts +++ b/frontend/src/pages/System/External/types.ts @@ -43,6 +43,7 @@ export interface ExternalSystemResponse extends BaseResponse { token?: string; syncStatus: SyncStatus; lastSyncTime?: string; + lastConnectTime?: string; config?: string; }