From abd0f42dab214845ba474e15bfcb75d73bec676b Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 26 Apr 2023 21:14:15 +0800 Subject: [PATCH] fix: loading state is not restored when Dialog's onConfirm method has exception (#3852) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area console /milestone 2.5.x #### What this PR does / why we need it: 修复在 Dialog 组件中,如果 onConfirm 方法出现异常,按钮加载状态没有复原的问题。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/3844 #### Does this PR introduce a user-facing change? ```release-note None ``` --- .../packages/components/src/components/dialog/Dialog.vue | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/console/packages/components/src/components/dialog/Dialog.vue b/console/packages/components/src/components/dialog/Dialog.vue index 7a273b1c3..493f7cf41 100644 --- a/console/packages/components/src/components/dialog/Dialog.vue +++ b/console/packages/components/src/components/dialog/Dialog.vue @@ -78,7 +78,14 @@ const handleCancel = () => { const handleConfirm = async () => { if (props.onConfirm) { loading.value = true; - await props.onConfirm(); + + try { + await props.onConfirm(); + } catch (error) { + console.error("Failed to execute onConfirm: ", error); + } finally { + loading.value = false; + } } handleClose(); };