目前暂不支持声明全局的CustomDialogController,CustomDialogController仅在作为@CustomDialog和@Component struct的成员变量,且在@Component struct内部定义时赋值才有效。建议使用:promptAction.openCustomDialog,相关文档https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...对话框customDialogId要保持一致,建议使用全局变量,参考demo如下://index.ets import { promptAction } from '@kit.ArkUI' import { customDialogBuilder } from './components' AppStorage.setOrCreate('customDialogId', 0); @Entry @Component struct Index { @State message: string = 'Hello World' @StorageLink('customDialogId') customDialogId: number = 1; build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) .onClick(() => { promptAction.openCustomDialog({ builder: customDialogBuilder.bind(this) }).then((dialogId: number) => { this.customDialogId = dialogId }) }) } .width('100%') } .height('100%') } } //custom.ets import promptAction from '@ohos.promptAction' @Builder export function customDialogBuilder() { Column() { Text('Custom dialog Message').fontSize(10) Row() { Button("确认").onClick(() => { promptAction.closeCustomDialog(AppStorage.get<number>('customDialogId')) }) Blank().width(50) Button("取消").onClick(() => { promptAction.closeCustomDialog(AppStorage.get<number>('customDialogId')) }) } }.height(200).padding(5) }
目前暂不支持声明全局的CustomDialogController,CustomDialogController仅在作为@CustomDialog和@Component struct的成员变量,且在@Component struct内部定义时赋值才有效。
建议使用:promptAction.openCustomDialog,相关文档https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...
对话框customDialogId要保持一致,建议使用全局变量,参考demo如下: