DiaLogComp.ets 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { BasicType, NavDiaLogModel } from '../../../../../Index'
  2. import { DiaLogCompControl } from './DiaLogControl'
  3. @ComponentV2
  4. export struct DiaLogComp {
  5. @Param controller?: DiaLogCompControl = undefined
  6. @Param param: BasicType = {}
  7. @BuilderParam container: () => void
  8. control: DiaLogCompControl = new DiaLogCompControl(this.getUIContext())
  9. aboutToAppear(): void {
  10. if (this.controller) {
  11. this.control = this.controller
  12. }
  13. }
  14. build() {
  15. NavDestination(){
  16. Column(){
  17. Column(){
  18. if(this.container) {
  19. this.container()
  20. } else {
  21. this.containerComp()
  22. }
  23. }
  24. // 屏蔽外部容器的点击事件
  25. .onClick(() => {})
  26. .scale({ x: this.control.opacity_, y: this.control.opacity_ })
  27. }
  28. .width("100%")
  29. .height("100%")
  30. .opacity(this.control.opacity_)
  31. .backgroundColor(this.control.bgc)
  32. .justifyContent(FlexAlign.Center)
  33. .alignItems(HorizontalAlign.Center)
  34. .onClick(() => { this.control._onBackPress()})
  35. .onAppear(() => { this.control.appear() })
  36. }
  37. .hideTitleBar(true)
  38. .mode(NavDestinationMode.DIALOG)
  39. .onBackPressed(() => { return this.control._onBackPress() })
  40. .systemTransition(NavigationSystemTransitionType.NONE)
  41. }
  42. @Builder
  43. containerComp(){
  44. Column() {
  45. Text(this.param.text ?? '一个弹窗')
  46. .fontColor(Color.Black)
  47. .lineHeight(18)
  48. .fontSize(18)
  49. .textAlign(TextAlign.Center)
  50. .margin({ bottom: 18 })
  51. if(this.param.message) {
  52. Text(this.param.message)
  53. .fontSize(15)
  54. .lineHeight(18)
  55. .fontColor('#C1C1C1')
  56. .margin({ bottom: 18 })
  57. .textAlign(TextAlign.Center)
  58. }
  59. Row({space: 20}) {
  60. Text('取消')
  61. .fontSize(16)
  62. .fontWeight(400)
  63. .borderRadius(36)
  64. .layoutWeight(1)
  65. .border({width: 1})
  66. .fontColor(Color.Black)
  67. .backgroundColor('#F5F5F7')
  68. .textAlign(TextAlign.Center)
  69. .padding({ top: 10, bottom: 10})
  70. .onClick(() => {
  71. this.control._onBackPress(0)
  72. })
  73. Text(this.param.date ?? '确定')
  74. .fontSize(16)
  75. .fontWeight(400)
  76. .layoutWeight(1)
  77. .borderRadius(36)
  78. .fontColor(Color.Black)
  79. .textAlign(TextAlign.Center)
  80. .padding({ top: 10, bottom: 10})
  81. .backgroundColor(this.param.color ?? '#FFFECF2F')
  82. .onClick(() => {
  83. this.control._onBackPress(1)
  84. })
  85. }
  86. .justifyContent(FlexAlign.SpaceBetween)
  87. .width('100%')
  88. }
  89. .width(315)
  90. .borderRadius(8)
  91. .backgroundColor(Color.White)
  92. .padding({ top: 28, left: 32, right: 32, bottom: 20 })
  93. }
  94. }
  95. @Builder
  96. export function DiaLogCompBuilder(_: string, param: NavDiaLogModel){
  97. DiaLogComp({ param: param.param, controller: param.control, container: param.builder })
  98. }