HarmonyOS 组件.bindPopup属性使用问题

@Component  
export struct PatientFollowUpPage {  
  onDestinationBack: () => boolean = () => false;  
  @Consume('appPathStack') appPathStack: NavPathStack;  
  @Prop patientItem:HisPatientListVosDTO = new HisPatientListVosDTO()  
  @State showPopup: boolean = false;  
  private menus: Menu[] = [{  
    content: "新增计划",  
    imageSource:$r('app.media.followPlanIcon')  
  }, {  
    content: "新增随访",  
    imageSource:$r('app.media.addFollowUpIcon')  
  }  
  ]  
  build() {  
    NavDestination(){  
      Column(){  
        CommonToolBar({  
          toolBarTitle:$r('app.string.patient_followUp'),  
          onBackClick:() => this.onDestinationBack(),  
  
          rightCustomView:() =>{  
            this.navBarRightComponent(this.showPopup)  
          }  
  
        })  
      }  
      .width(CommonConstants.FULL_PARENT)  
      .height(CommonConstants.FULL_PARENT)  
      .justifyContent(FlexAlign.Start)  
    }  
    .backgroundColor($r('app.color.global_pageBack_F1F2F5'))  
    .hideTitleBar(true)  
  }  
  // 导航右侧自定义区  
  @Builder  
  navBarRightComponent($$:boolean){  
    Row(){  
      Image($r('app.media.base_filter'))  
        .width(28).height(28)  
        .margin({ right:16 })  
        .onClick( ()=> {})  
        .id('filter_data_image')  
      Image($r('app.media.patientAdd'))  
        .width(28).height(28)  
        .id('add_data_image')  
        .bindPopup($$,{  
          builder: shortImageCutsPopupBuilder<Menu>(this.menus,128, (data, position) => {  
            $$ = false  
          }),  
          placement: Placement.TopRight,  
          enableArrow: true,  
          radius: 8,  
          popupColor: $r('app.color.global_black_FF333333'),  
          backgroundBlurStyle: BlurStyle.NONE,  
          onStateChange: (e) => {  
            if (!e.isVisible) {  
              $$ = false;  
            }  
          }  
        })  
        .onClick(() =>{  
          $$ = !$$  
        })  
    }  
    .alignRules({  
      right:{anchor:AppConstants.RELATIVE_CONTAINER_ID,align:HorizontalAlign.End},  
      center:{anchor:AppConstants.RELATIVE_CONTAINER_ID,align:VerticalAlign.Center}  
    })  
    .margin({right:16})  
    .alignItems(VerticalAlign.Center)  
    .height('100%')  
    .backgroundColor(Color.Red)  
    .id('navBarRight')  
  }  
}
HarmonyOS
2024-10-12 11:07:47
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple

bindPopup是可以写在@Builder自定义组件中的。请参考以下demo:

// xxx.ets  
@Entry  
@Component  
struct PopupExample {  
  @State handlePopup: boolean = false  
  @State customPopup: boolean = false  
  // popup构造器定义气泡内容  
  @Builder popupBuilder() {  
    Row() {  
      Text('Custom Popup Message').fontSize(10)  
      Button('PopupOptions')  
        .onClick(() => {  
          this.handlePopup = !this.handlePopup  
        })  
        .bindPopup(this.handlePopup, {  // PopupOptions类型气泡的内容  
          message: 'This is a popup with PopupOptions',  
          messageOptions: { // 气泡的文本样式  
            textColor: Color.Red,  
            font: {  
              size: '14vp',  
              style: FontStyle.Italic,  
              weight: FontWeight.Bolder  
            }  
          },  
          placement: Placement.Bottom,  
          enableArrow: false,  
          targetSpace: '15vp',  
          onStateChange: (e) => {  
            console.info(JSON.stringify(e.isVisible))  
            if (!e.isVisible) {  
              this.handlePopup = false  
            }  
          }  
        })  
    }.height(50).padding(5)  
  }  
  build() {  
    Column({space: 100}) {  
      Button('CustomPopupOptions')  
        .onClick(() => {  
          this.customPopup = !this.customPopup  
        })  
        .bindPopup(this.customPopup, {  // CustomPopupOptions类型气泡的内容  
          builder: this.popupBuilder,  
          targetSpace: '15vp',  
          enableArrow: false,   
          onStateChange: (e) => {  
            if (!e.isVisible) {  
              this.customPopup = false  
            }  
          }  
        })  
    }.margin(20)  
  }  
}
分享
微博
QQ
微信
回复
2024-10-12 16:56:01
相关问题
bindPopup样式问题有哪些啊?
406浏览 • 1回复 待解决
customKeyboard属性使用问题
735浏览 • 1回复 待解决
HarmonyOS bindPopup设置color无效
715浏览 • 0回复 待解决
span组件使用margin属性失效
1980浏览 • 1回复 待解决
使用linearGradient属性色值渐变问题
241浏览 • 1回复 待解决
HarmonyOS bindPopup如何设置箭头颜色
253浏览 • 1回复 待解决
HarmonyOS Scroll组件使用问题
359浏览 • 1回复 待解决
HarmonyOS RichText属性使用
381浏览 • 1回复 待解决
HarmonyOS swiper组件使用问题
285浏览 • 1回复 待解决
组件属性width是否支持使用变量定义
427浏览 • 1回复 待解决
HarmonyOS 组件设置属性无效果
336浏览 • 1回复 待解决
HarmonyOS 类中属性默认值问题
203浏览 • 1回复 待解决