HarmonyOS openCustomDialog返回的对话框id是undefined?

HarmonyOS openCustomDialog返回的对话框id是undefined?

HarmonyOS
2024-10-15 12:46:26
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple

请参考下如下写法:

import { BusinessError } from '@ohos.base';  
import { ComponentContent } from "@ohos.arkui.node";  
import { PromptAction } from '@kit.ArkUI';  
class Params {  
  ApplicationSharings: string[] = [];  
  Sharings: string[] = [];  
  promptAction: PromptAction;  
  numss: number = 0  
  constructor(ApplicationSharings: string[], Sharings: string[] = [], promptAction: PromptAction, numss: number) {  
    this.ApplicationSharings = ApplicationSharings;  
    this.Sharings = Sharings;  
    this.promptAction = promptAction;  
    this.numss = numss;  
  }  
}  
@Builder  
function buildText($$: Params) {  
  Column() {  
    Text('xxxx')  
      .fontSize(10)  
    Grid() {  
      ForEach($$.ApplicationSharings, (item: string, index) => {  
        GridItem() {  
          Column() {  
            Image($r('app.media.app_icon'))  
              .height(50).width(50)  
            Text(item)  
              .fontSize(10)  
          }  
        }  
      })  
    }  
    .height(100)  
    .rowsGap(20)  
    .columnsGap(20)  
    .scrollBar(BarState.Off)  
    .rowsTemplate('1fr')  
    Grid() {  
      ForEach($$.Sharings, (item: string, index) => {  
        GridItem() {  
          Column() {  
            Image($r('app.media.app_icon'))  
              .height(50).width(50)  
            Text(item)  
              .fontSize(10)  
          }  
        }  
      })  
    }  
    .height(100)  
    .rowsGap(20)  
    .columnsGap(20)  
    .scrollBar(BarState.Off)  
    .rowsTemplate('1fr')  
    Button('取消')  
      .width('100%')  
      .fontColor(Color.Black)  
      .backgroundColor(Color.White)  
      .onClick(() => {  
        let link1: SubscribedAbstractProperty<number> = storage.link('PropA');  
        let numsss = link1.get()  
        console.log(':::numsss', link1.get())  
        link1.set(++numsss)  
      })  
  }  
  .backgroundColor('#FFF0F0F0')  
  .width('90%')  
  .height('30%')  
  .borderRadius(10)  
}  
let para: Record<string, number> = { 'PropA': 1 };  
let storage: LocalStorage = new LocalStorage(para); // 创建新实例并使用给定对象初始化  
@Entry(storage)  
@Component  
struct CustomDialogDemo {  
  @State message: string = "hello"  
  @State ApplicationSharings: string[] =  
    ['转发', '群发给客户', '群发到客户群', '分享到同事吧', '收藏', '群发到客户群', '分享到同事吧', '收藏', '刷新',  
      '翻译', '复制链接', '调整字体', '刷新', '翻译']  
  @State Sharings: string[] = ['最小化', '复制链接', '调整字体', '刷新', '翻译', '复制链接', '调整字体', '刷新', '翻译']  
  @LocalStorageLink('PropA') @Watch('onchang') nums: number = 0;  
  @LocalStorageLink('uiContext') aaa: UIContext = this.getUIContext();  
  @LocalStorageLink('PropAA') shjsh: ComponentContent<Params> | null = null   
  aboutToAppear(): void {  
  }  
  onchang() {  
    console.log('::: onchang')  
    try {  
      this.aaa.getPromptAction().closeCustomDialog(this.shjsh);  
    } catch (error) {  
      let message = (error as BusinessError).message;  
      let code = (error as BusinessError).code;  
      console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);  
    }    
  }  
  build() {  
    Row() {  
      Column() {  
        TextInput()  
          .id('aaa')  
          .visibility(Visibility.None)  
        Button("click me")  
          .onClick(() => {  
            let uiContext = this.getUIContext();  
            let promptAction = uiContext.getPromptAction();  
            let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText),  
              new Params(this.ApplicationSharings, this.Sharings, promptAction, this.nums));  
            this.shjsh = contentNode  
            try {  
              promptAction.openCustomDialog(contentNode);  
            } catch (error) {  
              let message = (error as BusinessError).message;  
              let code = (error as BusinessError).code;  
              console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);  
            }  
            ;  
          })  
      }  
      .width('100%')  
      .height('100%')  
    }  
    .height('100%')  
  }  
}
分享
微博
QQ
微信
回复
2024-10-15 18:04:27
相关问题
如何封装一个自定义Dialog对话框
2120浏览 • 1回复 待解决
HarmonyOS创建前置广角相机返回undefined
318浏览 • 1回复 待解决
promptAction.openCustomDialog 全局弹窗
286浏览 • 1回复 待解决