feat(basic): 增强 Alert 和 Confirm 弹窗功能- 为 AlertBean 类添加 autoCancel 属性,用于自定义弹窗关闭行为
- 为 showAlertDialog 和 showConfirmDialog 方法增加 builder 参数,支持自定义布局 - 在方法内部使用 builder ?? wrapBuilder(alertDialogBuilder) ,实现默认布局和自定义布局的切换 - 修改 openCustomDialog 方法调用,支持自定义 autoCancel 设置
这个提交包含在:
父节点
699de803ec
当前提交
1e44b97a73
@ -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<T> {
|
||||
@ -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(() => {
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户