DiaLogSheetComp.ets 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { BasicType, NavDiaLogModel } from "../../../../../Index"
  2. import { DiaLogSheetControl } from "./DiaLogControl"
  3. @ComponentV2
  4. export struct DiaLogSheetComp {
  5. @Param controller?: DiaLogSheetControl = undefined
  6. @Param params: Array<BasicType> = []
  7. @BuilderParam container: (_: () => void) => void = this.containerComp
  8. control: DiaLogSheetControl = new DiaLogSheetControl(this.getUIContext())
  9. aboutToAppear(): void {
  10. if(this.controller) {
  11. this.control = this.controller
  12. }
  13. }
  14. build() {
  15. NavDestination() {
  16. Column() {
  17. Column().layoutWeight(1).width('100%')
  18. .gesture(
  19. TapGesture()
  20. .onAction(() => {
  21. this.control._onBackPress()
  22. })
  23. )
  24. Column() {
  25. Column(){
  26. this.containerComp()
  27. }
  28. .onAreaChange((o, n) => {
  29. this.control.containerH = n.height as number
  30. })
  31. Blank()
  32. .height(this.control.h_)
  33. .backgroundColor(Color.White)
  34. }
  35. .onTouch((event: TouchEvent) => {
  36. this.control.edgeEffect(event)
  37. event.stopPropagation();
  38. })
  39. .offset({ y: this.control.h_ < 0 ? Math.abs(this.control.h_ as number) : 0 })
  40. }
  41. .width('100%')
  42. .height('200%')
  43. .opacity(this.control.opacity_)
  44. .backgroundColor(this.control.bgc)
  45. .offset({ y: this.control.offsetY_ })
  46. .justifyContent(FlexAlign.End)
  47. .onAppear(() => { this.control.appear() })
  48. .alignItems(HorizontalAlign.Center)
  49. }
  50. .hideTitleBar(true)
  51. .mode(NavDestinationMode.DIALOG)
  52. .onBackPressed(() => { return this.control._onBackPress() })
  53. .systemTransition(NavigationSystemTransitionType.NONE)
  54. }
  55. @Builder
  56. containerComp(){
  57. Column(){
  58. ForEach(this.params, (item: BasicType, index) => {
  59. Row(){
  60. Text(item.text)
  61. .fontSize(16)
  62. .textAlign(TextAlign.Center)
  63. }
  64. .width("100%")
  65. .onClick(() => {
  66. this.control._onBackPress(item.text)
  67. })
  68. .alignItems(VerticalAlign.Center)
  69. .justifyContent(FlexAlign.Center)
  70. .padding({ top: 24, bottom: 24 })
  71. Divider().width("80%").height(1).backgroundColor('#000000F2')
  72. })
  73. Row(){
  74. Text(`取消`)
  75. .fontSize(16)
  76. .textAlign(TextAlign.Center)
  77. }
  78. .width("100%")
  79. .alignItems(VerticalAlign.Center)
  80. .justifyContent(FlexAlign.Center)
  81. .padding({ top: 24, bottom: 24 })
  82. .onClick(() => { this.control._onBackPress() })
  83. }
  84. .width("100%")
  85. .padding({ bottom: 30 })
  86. .backgroundColor(Color.White)
  87. .justifyContent(FlexAlign.Center)
  88. .alignItems(HorizontalAlign.Center)
  89. .borderRadius({ topLeft: 8, topRight: 8 })
  90. }
  91. }
  92. @Builder
  93. export function DiaLogSheetCompBuilder(_: string, params: NavDiaLogModel){
  94. DiaLogSheetComp({ params: params.params, controller: params?.control as DiaLogSheetControl })
  95. }