Index.ets 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { Main } from '../views/Main'
  2. import { DueTime } from '../views/DueTime'
  3. import { Note } from '../views/Note';
  4. import { Time } from '../views/Time';
  5. import { About } from '../views/About';
  6. import { YTAvoid } from '../utils/YTAvoid';
  7. @Entry
  8. @Component
  9. struct Index {
  10. @State currentIndex: number = 0
  11. @StorageProp(YTAvoid.SAFE_TOP_KEY)
  12. top:number=0
  13. @StorageProp(YTAvoid.SAFE_BOTTOM_KEY)
  14. bottom:number=0
  15. private controller: TabsController = new TabsController();
  16. @Builder TabBuilder(title: string, targetIndex: number, selectedImg: Resource, normalImg: Resource) {
  17. Column() {
  18. Image(this.currentIndex === targetIndex ? selectedImg : normalImg)
  19. .size({ width: 25, height: 25 })
  20. Text(title)
  21. .fontColor(this.currentIndex === targetIndex ? '#756860' : '#A2A4B1')
  22. .fontSize(12)
  23. }
  24. .width('100%')
  25. .height(50)
  26. .backgroundColor(Color.White)
  27. .justifyContent(FlexAlign.Center)
  28. .onClick(() => {
  29. this.currentIndex = targetIndex
  30. this.controller.changeIndex(targetIndex)
  31. })
  32. }
  33. build() {
  34. Column() {
  35. Tabs({ barPosition: BarPosition.End, controller: this.controller }) {
  36. TabContent() {
  37. if(this.currentIndex==0) {
  38. Main()
  39. }
  40. }.tabBar(this.TabBuilder("清单", 0, $r('app.media.c_book'), $r('app.media.book')))
  41. TabContent() {
  42. if(this.currentIndex==1) {
  43. DueTime()
  44. }
  45. }.tabBar(this.TabBuilder("截止时间", 1, $r('app.media.timeselect'), $r('app.media.timeunselect')))
  46. TabContent() {
  47. if(this.currentIndex==2) {
  48. Note()
  49. }
  50. }.tabBar(this.TabBuilder("笔记", 2, $r('app.media.notesel'), $r('app.media.note')))
  51. TabContent() {
  52. if(this.currentIndex==3) {
  53. Time()
  54. }
  55. }.tabBar(this.TabBuilder("时间轴", 3, $r('app.media.timeselect'), $r('app.media.timeunselect')))
  56. TabContent() {
  57. if(this.currentIndex==4) {
  58. About()
  59. }
  60. }.tabBar(this.TabBuilder("关于", 4, $r('app.media.c_my'), $r('app.media.my')))
  61. }.onChange((index: number) => {
  62. this.currentIndex = index
  63. })
  64. .scrollable(false)
  65. }.width('100%')
  66. .height('100%')
  67. .backgroundImage($r('app.media.backimg'))
  68. .backgroundImageSize({width:'100%',height:'100%'})
  69. .backgroundColor('#fff')
  70. .padding({bottom: this.bottom,top:this.top})
  71. }
  72. }