From 25725e520ef1fc168f61b6233f1d83f98e9ab1a2 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 26 Jul 2023 14:42:19 +0800 Subject: [PATCH] feat: add showCancel prop for dialog component (#4302) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /area console /kind improvement /milestone 2.8.x #### What this PR does / why we need it: 为 Dialog 组件添加 showCancel 属性用于控制是否显示取消按钮,某些场景下 Dialog 只是用于提示切必须点击确定。 此外,还对以下位置做了对应修改: 1. 进入文章编辑时检查编辑器是否存在的弹框,只允许点击确定并返回。 2. 备份恢复完成之后点击确定关闭 Halo。 #### Does this PR introduce a user-facing change? ```release-note Console 端的 Dialog 组件添加 showCancel 属性用于控制是否显示取消按钮。 ``` --- .../src/components/dialog/Dialog.vue | 6 +++++- .../src/components/dialog/interface.ts | 18 ++++++------------ .../contents/pages/SinglePageEditor.vue | 5 +---- .../src/modules/contents/posts/PostEditor.vue | 5 +---- .../src/modules/system/backup/tabs/Restore.vue | 5 +---- 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/console/packages/components/src/components/dialog/Dialog.vue b/console/packages/components/src/components/dialog/Dialog.vue index e1c5529e7..6494e15a2 100644 --- a/console/packages/components/src/components/dialog/Dialog.vue +++ b/console/packages/components/src/components/dialog/Dialog.vue @@ -19,6 +19,7 @@ const props = withDefaults( description?: string; confirmText?: string; confirmType?: ButtonType; + showCancel?: boolean; cancelText?: string; visible?: boolean; onConfirm?: () => void; @@ -30,6 +31,7 @@ const props = withDefaults( description: "", confirmText: "确定", confirmType: "primary", + showCancel: true, cancelText: "取消", visible: false, onConfirm: () => { @@ -126,7 +128,9 @@ const handleClose = () => { {{ confirmText }} - {{ cancelText }} + + {{ cancelText }} + diff --git a/console/packages/components/src/components/dialog/interface.ts b/console/packages/components/src/components/dialog/interface.ts index a322b11c3..9bfa31e05 100644 --- a/console/packages/components/src/components/dialog/interface.ts +++ b/console/packages/components/src/components/dialog/interface.ts @@ -2,28 +2,22 @@ export type Type = "success" | "info" | "warning" | "error"; export const DialogProviderProvideKey = "DIALOG_PROVIDER_PROVIDE_KEY"; import type { Type as ButtonType } from "../button/interface"; -export interface useDialogOptions { - type?: Type; - visible: boolean; - title: string; - description?: string; - confirmType?: ButtonType; - confirmText?: string; - cancelText?: string; - onConfirm?: () => void; - onCancel?: () => void; -} - export interface DialogProps { type?: Type; visible?: boolean; title?: string; description?: string; confirmType?: ButtonType; + showCancel?: boolean; confirmText?: string; cancelText?: string; onConfirm?: () => void; onCancel?: () => void; } +type useDialogOptions = Omit & { + visible: boolean; + title: string; +}; + export type useDialogUserOptions = Omit; diff --git a/console/src/modules/contents/pages/SinglePageEditor.vue b/console/src/modules/contents/pages/SinglePageEditor.vue index 6992e3688..db0bb581f 100644 --- a/console/src/modules/contents/pages/SinglePageEditor.vue +++ b/console/src/modules/contents/pages/SinglePageEditor.vue @@ -257,13 +257,10 @@ const handleFetchContent = async () => { raw_type: data.rawType, }), confirmText: t("core.common.buttons.confirm"), - cancelText: t("core.common.buttons.cancel"), + showCancel: false, onConfirm: () => { router.back(); }, - onCancel: () => { - router.back(); - }, }); } await nextTick(); diff --git a/console/src/modules/contents/posts/PostEditor.vue b/console/src/modules/contents/posts/PostEditor.vue index f72525a75..290d1365f 100644 --- a/console/src/modules/contents/posts/PostEditor.vue +++ b/console/src/modules/contents/posts/PostEditor.vue @@ -269,13 +269,10 @@ const handleFetchContent = async () => { raw_type: data.rawType, }), confirmText: t("core.common.buttons.confirm"), - cancelText: t("core.common.buttons.cancel"), + showCancel: false, onConfirm: () => { router.back(); }, - onCancel: () => { - router.back(); - }, }); } diff --git a/console/src/modules/system/backup/tabs/Restore.vue b/console/src/modules/system/backup/tabs/Restore.vue index 422362c02..8b38ddbfa 100644 --- a/console/src/modules/system/backup/tabs/Restore.vue +++ b/console/src/modules/system/backup/tabs/Restore.vue @@ -16,13 +16,10 @@ const onUploaded = () => { title: t("core.backup.operations.restore.title"), description: t("core.backup.operations.restore.description"), confirmText: t("core.common.buttons.confirm"), - cancelText: t("core.common.buttons.cancel"), + showCancel: false, async onConfirm() { await handleShutdown(); }, - async onCancel() { - await handleShutdown(); - }, }); };