From 391ea29f1a635159c35eb7f5981c9b64329b35ae Mon Sep 17 00:00:00 2001 From: kae Date: Thu, 18 Jun 2026 18:24:51 +0900 Subject: [PATCH] fix: repair supplier modal submit flow destroyOnClose unmounts the Form on close, disconnecting the useForm instance so validateFields throws on reopen. Replaced with afterOpenChange to reset fields without unmounting. Also moved setModalOpen(false) and reload() before message.success so that antd v5's static message API throwing outside an context no longer prevents the modal from closing after a successful create or update. --- src/pages/Purchase/Suppliers/index.tsx | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/pages/Purchase/Suppliers/index.tsx b/src/pages/Purchase/Suppliers/index.tsx index 26aea6c..8df0146 100644 --- a/src/pages/Purchase/Suppliers/index.tsx +++ b/src/pages/Purchase/Suppliers/index.tsx @@ -30,15 +30,24 @@ const SuppliersPage: React.FC = () => { const handleSubmit = async () => { const values = await form.validateFields(); - if (editing) { - await updateSupplier(editing.supplierId, values); - message.success('更新成功'); - } else { - await createSupplier(values); - message.success('创建成功'); + let successMsg = ''; + try { + if (editing) { + const res = await updateSupplier(editing.supplierId, values); + if (res?.code !== 0) { message.error(res?.msg || '更新失败'); return; } + successMsg = '更新成功'; + } else { + const res = await createSupplier(values); + if (res?.code !== 0) { message.error(res?.msg || '创建失败'); return; } + successMsg = '创建成功'; + } + } catch { + message.error('操作失败'); + return; } setModalOpen(false); actionRef.current?.reload(); + message.success(successMsg); }; const handleDelete = async (id: string) => { @@ -103,7 +112,7 @@ const SuppliersPage: React.FC = () => { open={modalOpen} onOk={handleSubmit} onCancel={() => setModalOpen(false)} - destroyOnClose + afterOpenChange={(open) => { if (!open) form.resetFields(); }} >