From 1e44b97a7367b8cbdb91040873c289b6700007fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Tue, 29 Apr 2025 18:14:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(basic):=20=E5=A2=9E=E5=BC=BA=20Alert=20?= =?UTF-8?q?=E5=92=8C=20Confirm=20=E5=BC=B9=E7=AA=97=E5=8A=9F=E8=83=BD-=20?= =?UTF-8?q?=E4=B8=BA=20AlertBean=20=E7=B1=BB=E6=B7=BB=E5=8A=A0=20autoCance?= =?UTF-8?q?l=20=E5=B1=9E=E6=80=A7=EF=BC=8C=E7=94=A8=E4=BA=8E=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=BC=B9=E7=AA=97=E5=85=B3=E9=97=AD=E8=A1=8C?= =?UTF-8?q?=E4=B8=BA=20-=20=E4=B8=BA=20showAlertDialog=20=E5=92=8C=20showC?= =?UTF-8?q?onfirmDialog=20=E6=96=B9=E6=B3=95=E5=A2=9E=E5=8A=A0=20builder?= =?UTF-8?q?=20=E5=8F=82=E6=95=B0=EF=BC=8C=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=B8=83=E5=B1=80=20-=20=E5=9C=A8=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=86=85=E9=83=A8=E4=BD=BF=E7=94=A8=20builder=20=3F?= =?UTF-8?q?=3F=20wrapBuilder(alertDialogBuilder)=20=EF=BC=8C=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E9=BB=98=E8=AE=A4=E5=B8=83=E5=B1=80=E5=92=8C=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=B8=83=E5=B1=80=E7=9A=84=E5=88=87=E6=8D=A2?= =?UTF-8?q?=20-=20=E4=BF=AE=E6=94=B9=20openCustomDialog=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E8=B0=83=E7=94=A8=EF=BC=8C=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=20autoCancel=20=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/ets/utils/ToolsHelper.ets | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/ets/utils/ToolsHelper.ets b/src/main/ets/utils/ToolsHelper.ets index e3f85ef..c8c1586 100644 --- a/src/main/ets/utils/ToolsHelper.ets +++ b/src/main/ets/utils/ToolsHelper.ets @@ -7,7 +7,7 @@ import { md5_hex } from '../util/md5'; import { GlobalContext, LogHelper } from '../../../../Index'; import { ComponentContent } from '@kit.ArkUI'; -class AlertBean { +export class AlertBean { options: ConfirmOptions dialogTag: string @@ -35,6 +35,7 @@ export interface ConfirmOptions { msg?: string confirm?: Btn cancel?: Btn + autoCancel?: boolean } export interface ListOptions { @@ -304,13 +305,18 @@ export class ToolsHelper { /** * 弹出Alert弹窗 + * 第二个参数可以自定义布局,自定义布局接收的参数为AlertBean + * @Builder + * function alertDialogBuilder(options: AlertBean) {} + * * @param options + * @param builder wrapBuilder(alertDialogBuilder) */ - static showAlertDialog(options: AlertOptions) { + static showAlertDialog(options: AlertOptions, builder?: WrappedBuilder<[Object]>) { const dialogTag = ToolsHelper.getUuid() const ui = GlobalContext.getUiContext() if (ui) { - const c = new ComponentContent(ui, wrapBuilder(alertDialogBuilder), + const c = new ComponentContent(ui, builder ?? wrapBuilder(alertDialogBuilder), new AlertBean({ title: options.title, msg: options.msg, confirm: options.action }, dialogTag)) ui.getPromptAction().openCustomDialog(c, { autoCancel: false @@ -352,14 +358,19 @@ export class ToolsHelper { /** * 弹出Confirm弹窗 + * 第二个参数可以自定义布局,自定义布局接收的参数为AlertBean + * @Builder + * function alertDialogBuilder(options: AlertBean) {} + * * @param options + * @param builder wrapBuilder(alertDialogBuilder) */ - static showConfirmDialog(options: ConfirmOptions) { + static showConfirmDialog(options: ConfirmOptions, builder?: WrappedBuilder<[Object]>) { const dialogTag = ToolsHelper.getUuid() const ui = GlobalContext.getUiContext() if (ui) { - const c = new ComponentContent(ui, wrapBuilder(alertDialogBuilder), + const c = new ComponentContent(ui, builder ?? wrapBuilder(alertDialogBuilder), new AlertBean({ title: options.title, msg: options.msg, @@ -367,7 +378,7 @@ export class ToolsHelper { confirm: options.confirm }, dialogTag)) ui.getPromptAction().openCustomDialog(c, { - autoCancel: false + autoCancel: options.autoCancel }).then(() => { ToolsHelper.mapAlertDialog.set(dialogTag, c) }).catch(() => {