HarmonyOS鸿蒙Next中全局log弹窗openCustomDialog
HarmonyOS鸿蒙Next中全局log弹窗openCustomDialog
import { ComponentContent } from '@kit.ArkUI';
@Builder
export function buildText(close: () => void) {
Column() {
LoadingProgress()
.width(48)
.height(48)
.color(Color.White)
Text("加载中")
.fontSize(14)
.fontColor(Color.White)
}
.borderRadius(16)
.justifyContent(FlexAlign.Center)
.width(120)
.height(120)
.backgroundColor('rgba(0,0,0,0.6)')
.onClick(() => close())
}
class DialogManage {
private uiContext: UIContext | undefined = undefined
private contentNode: ComponentContent<object> | undefined = undefined
init(uiContext: UIContext) {
this.uiContext = uiContext
this.contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), this.close);
}
open(quit: boolean = true) {
if (this.uiContext && this.contentNode) {
this.uiContext.getPromptAction().openCustomDialog(this.contentNode, {
onWillDismiss: (closeData) => {
console.log("关闭原因: ", closeData.reason) // 屏蔽点击遮障层关闭弹窗
quit && closeData.reason !== DismissReason.TOUCH_OUTSIDE && this.close()
}
})
return
}
console.error("uiContext 或者 contentNode 不存在 open 失败")
}
close = () => {
if (this.uiContext && this.contentNode) {
this.uiContext.getPromptAction().closeCustomDialog(this.contentNode)
return
}
console.error("uiContext 或者 contentNode 不存在 close 失败")
}
}
export const dialogManage = new DialogManage()
更多关于HarmonyOS鸿蒙Next中全局log弹窗openCustomDialog的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
在HarmonyOS Next中,openCustomDialog用于创建全局自定义log弹窗。通过CustomDialogController类控制弹窗生命周期,包括定义布局、绑定组件及事件。使用@CustomDialog装饰器声明自定义弹窗组件,在aboutToAppear中初始化数据。通过controller.open()和controller.close()控制显示与关闭。弹窗支持模态交互,可自定义样式、位置和动画效果。
更多关于HarmonyOS鸿蒙Next中全局log弹窗openCustomDialog的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


