MyCustomDialog.ets 2.59 KB
@CustomDialog
export struct MyCustomDialog {
  @State title: string = "标题"
  @State titleShow: boolean = true
  @State tipValue: string ="提示文字"
  @State tipShow: boolean = true
  @State cancelIsLeft :boolean = true//取消是否在左边
  @State leftText: string = "取消"
  @State rightText: string = "确认"
  @State leftTextColor: Resource = $r('app.color.color_333333')
  @State rightTextColor: Resource = $r('app.color.color_648DF2')


  controller: CustomDialogController
  cancel: () => void = () => {
  }
  confirm: () => void = () => {
  }

  build() {
    Column() {
      Column(){
        if(this.titleShow){
          Text(this.title)
            .fontSize("32lpx")
            .fontColor($r('app.color.color_333333'))
            .lineHeight('50lpx')
            .fontWeight(600)
        }

        if(this.tipShow){
          Text(this.tipValue)
            .margin({ top:this.titleShow?"10lpx":"0lpx" })
            .fontSize("27lpx")
            .fontWeight(400)
            .lineHeight('38lpx')
            .fontColor($r('app.color.color_999999'))
        }
      }.padding({top:"48lpx",bottom:"48lpx"})
      .alignItems(HorizontalAlign.Center)

      Divider()
        .width("100%")
        .strokeWidth('1lpx')
        .height('1lpx')
        .color($r('app.color.color_EEEEEE'))

      Row(){
        Text(this.leftText)
          .fontSize('35lpx')
          .fontWeight(400)
          .fontColor(this.leftTextColor)
          .onClick(() => {
            if (this.controller != undefined){
              if(this.cancelIsLeft){
                this.controller.close()
                this.cancel()
              }else{
                this.controller.close()
                this.confirm()
              }
            }
          }).layoutWeight(1)
          .textAlign(TextAlign.Center)

        Divider()
          .width("1lpx")
          .strokeWidth('1lpx')
          .vertical(true)
          .height('92lpx')
          .color($r('app.color.color_EEEEEE'))

        Text(this.rightText)
          .fontSize('35lpx')
          .textAlign(TextAlign.Center)
          .fontWeight(400)
          .fontColor(this.rightTextColor)
          .onClick(() => {
            if (this.controller != undefined) {
              if(this.cancelIsLeft){
                this.controller.close()
                this.confirm()
              }else{
                this.controller.close()
                this.cancel()
              }
            }
          }).layoutWeight(1)
      }
      .alignItems(VerticalAlign.Center)
      .height('96lpx')
    }.borderRadius(10)
    .width("518lpx")
    .backgroundColor("#FFF")
  }
}