YTHeader.ets 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { yTRouter } from '../utils/YTRouter'
  2. @Component
  3. export struct YTHeader {
  4. @BuilderParam leftComp?: () => void
  5. @BuilderParam RightComp?: () => void
  6. @BuilderParam CenterComp?: () => void
  7. backArrow: boolean = true
  8. title: string = ''
  9. click = () => {
  10. yTRouter.routerBack()
  11. }
  12. build() {
  13. Stack() {
  14. Row() {
  15. if (this.backArrow && !this.leftComp) {
  16. Image($r('app.media.ic_back'))
  17. .width(24)
  18. .margin({ left: 16 })
  19. .onClick(this.click)
  20. }
  21. if (this.leftComp) {
  22. this.leftComp()
  23. }
  24. if (this.RightComp) {
  25. this.RightComp()
  26. }
  27. }
  28. .width('100%')
  29. .justifyContent(this.RightComp ? FlexAlign.SpaceBetween : FlexAlign.Start)
  30. if (this.CenterComp || this.title)
  31. Row() {
  32. if (this.CenterComp) {
  33. this.CenterComp()
  34. }
  35. if (this.title && !this.CenterComp) {
  36. Text(this.title)
  37. .fontSize(18)
  38. .fontWeight(700)
  39. }
  40. }
  41. .width('100%')
  42. .justifyContent(FlexAlign.Center)
  43. .hitTestBehavior(HitTestMode.None)
  44. }
  45. .height(44)
  46. .backgroundColor(Color.White)
  47. }
  48. }