Index.ets 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { HomeTab } from './tabs/HomeTab';
  2. import { StatisticsTab } from './tabs/StatisticsTab';
  3. import { MoodLogTab } from './tabs/MoodLogTab';
  4. import { MineTab } from './tabs/MineTab';
  5. import { BasicType } from '../models';
  6. import { YTAvoid } from '../utils/YTAvoid';
  7. import { yTBindSheet } from '../utils/YTBindSheet';
  8. import { ContextHelper } from '../utils/ContextHelper';
  9. @Entry
  10. @Component
  11. struct Index {
  12. @State currentIndex: number = 0;
  13. private controller: TabsController = new TabsController();
  14. contentList: BasicType[] = [
  15. {
  16. text: '首页',
  17. src: $r('app.media.icon_home_unselect'),
  18. acSrc: $r('app.media.icon_home_select'),
  19. index: 0
  20. },
  21. {
  22. text: '统计',
  23. src: $r('app.media.statistics'),
  24. acSrc: $r('app.media.statistics_check'),
  25. index: 1
  26. }, {
  27. text: '心情日志',
  28. src: $r('app.media.mood_log'),
  29. acSrc: $r('app.media.mood_log_check'),
  30. index: 2
  31. },
  32. {
  33. text: '个人中心',
  34. src: $r('app.media.my'),
  35. acSrc: $r('app.media.my_check'),
  36. index: 3
  37. }
  38. ]
  39. aboutToAppear(): void {
  40. ContextHelper.init(this.getUIContext(), getContext())
  41. yTBindSheet.init({
  42. context: this.getUIContext(),
  43. options: {
  44. maskColor: '#63000000',
  45. showClose: false
  46. }
  47. })
  48. }
  49. build() {
  50. Column() {
  51. Tabs({ barPosition: BarPosition.End, controller: this.controller }) {
  52. TabContent() {
  53. HomeTab()
  54. }
  55. TabContent() {
  56. StatisticsTab()
  57. }
  58. TabContent() {
  59. MoodLogTab()
  60. }
  61. TabContent() {
  62. MineTab()
  63. }
  64. }
  65. .vertical(false)
  66. .barMode(BarMode.Fixed)
  67. .barHeight(0)
  68. .animationDuration(0)
  69. .onChange((index: number) => {
  70. this.currentIndex = index;
  71. })
  72. .layoutWeight(1)
  73. Row({ space: 6 }) {
  74. Row() {
  75. ForEach(this.contentList, (item: BasicType) => {
  76. this.barBuilder(item)
  77. })
  78. }
  79. .width('100%')
  80. .height(62)
  81. .borderRadius(31)
  82. .backgroundColor('#f2ffffff')
  83. .justifyContent(FlexAlign.SpaceAround)
  84. .shadow({
  85. color: '#33000000',
  86. radius: this.getUIContext().vp2px(30)
  87. })
  88. .clip(true)
  89. }
  90. .padding({ left: 16, right: 16 })
  91. .width('100%')
  92. .justifyContent(FlexAlign.Center)
  93. .position({
  94. left: '0%',
  95. bottom: YTAvoid.getBottom()
  96. })
  97. }
  98. }
  99. @Builder
  100. barBuilder(item: BasicType) {
  101. Column({ space: 4 }) {
  102. Image(this.currentIndex == item.index ? item.acSrc : item.src)
  103. .width(24)
  104. Text(item.text)
  105. .fontSize(10)
  106. .lineHeight(12)
  107. .fontWeight(500)
  108. .fontColor(this.currentIndex === item.index ? '#FF6A3D' : '#9BA1A6')
  109. }
  110. .layoutWeight(1)
  111. .onClick(() => {
  112. this.currentIndex = item.index!
  113. this.controller.changeIndex(this.currentIndex)
  114. })
  115. }
  116. }