From fbdcfe6de06ee9f4b5f805aeae9cefc50982babb Mon Sep 17 00:00:00 2001 From: chengqian Date: Thu, 14 May 2026 12:33:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ui):=E4=BD=BF=E7=94=A8=E6=A8=A1?= =?UTF-8?q?=E6=80=81=E6=A1=86=E4=BB=A3=E6=9B=BF=E7=B3=BB=E7=BB=9F=E8=87=AA?= =?UTF-8?q?=E5=B8=A6=E6=8F=90=E7=A4=BA=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/common/ConfirmDialog.vue | 27 ++++++++++++++ web/tenant/src/composables/useConfirm.ts | 37 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 web/tenant/src/components/common/ConfirmDialog.vue create mode 100644 web/tenant/src/composables/useConfirm.ts diff --git a/web/tenant/src/components/common/ConfirmDialog.vue b/web/tenant/src/components/common/ConfirmDialog.vue new file mode 100644 index 0000000..bb52860 --- /dev/null +++ b/web/tenant/src/components/common/ConfirmDialog.vue @@ -0,0 +1,27 @@ + + + diff --git a/web/tenant/src/composables/useConfirm.ts b/web/tenant/src/composables/useConfirm.ts new file mode 100644 index 0000000..9a843fa --- /dev/null +++ b/web/tenant/src/composables/useConfirm.ts @@ -0,0 +1,37 @@ +import { ref } from 'vue' + +interface ConfirmOptions { + title?: string + message: string + confirmText?: string + cancelText?: string + danger?: boolean +} + +const visible = ref(false) +const options = ref({ message: '' }) +let resolvePromise: ((value: boolean) => void) | null = null + +export function useConfirm() { + function confirm(opts: ConfirmOptions | string): Promise { + options.value = typeof opts === 'string' ? { message: opts } : opts + visible.value = true + return new Promise((resolve) => { + resolvePromise = resolve + }) + } + + function handleConfirm() { + visible.value = false + resolvePromise?.(true) + resolvePromise = null + } + + function handleCancel() { + visible.value = false + resolvePromise?.(false) + resolvePromise = null + } + + return { visible, options, confirm, handleConfirm, handleCancel } +}