中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
微信扫码分享
// CustomDialog_Globally.ets import { BusinessError } from '@ohos.base'; // CustomDialog_Globally_other01.ets import { ComponentContent } from '@kit.ArkUI'; import { buildText, Params } from './CustomDialog_Globally'; export class Params { text: string = "" callback: (volumeType: string, value: number) => void = () => { }; constructor(text: string, callback: (volumeType: string, value: number) => void) { this.text = text; this.callback = callback; } } @Builder export function buildText(params: Params) { // 弹窗内容 Column() { Text(params.text) .fontSize(50) .fontWeight(FontWeight.Bold) .margin({ bottom: 36 }) Button("登录") .onClick(() => { params.text = 'button 点击登录了' // 登录结果回调 params.callback('1', 2) }) }.backgroundColor(Color.Yellow) } @Entry @Component struct CustomDialog_Globally { @State message: string = "hello" build() { Row() { Column() { Button("click me") .onClick(() => { let uiContext = this.getUIContext(); let promptAction = uiContext.getPromptAction(); // let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message)); 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%') } } @Entry @Component struct CustomDialog_Globally_other01 { @State message: string = 'Hello World'; build() { Column() { Text(this.message) .id('HelloWorld') .fontSize(50) .fontWeight(FontWeight.Bold) .onClick(() => { let uiContext = this.getUIContext(); let promptAction = uiContext.getPromptAction(); let callback = (volumeType: string, value: number) => { //处理返回值的逻辑 console.log(`OpenCustomDialog args error code is ${volumeType}, message is ${value}`); this.message = volumeType; } let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message, callback)); 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}`); } ; }) } .height('100%') .width('100%') } }