BookSearchPage.ets 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { YTAvoid, YTHeader } from 'basic'
  2. import { DeerSearch } from '../components/DeerSearch'
  3. import { CustomTextStyle } from '../style/CustomTextStyle'
  4. import { LengthMetrics, PersistenceV2 } from '@kit.ArkUI'
  5. import { HistoryStorage } from '../model/Storage'
  6. // 书籍搜索页面
  7. @ComponentV2
  8. struct BookSearchPage {
  9. @Local safeBottom: number = AppStorage.get(YTAvoid.SAFE_BOTTOM_KEY) as number
  10. searHistory: HistoryStorage = PersistenceV2.connect(HistoryStorage, () => new HistoryStorage())!
  11. // 清空历史记录
  12. clearHistory() {
  13. this.searHistory.history = []
  14. }
  15. // 开始搜索
  16. onSearch(text: string) {
  17. let key = text
  18. console.log('开始搜索searchKey: ' + key)
  19. }
  20. build() {
  21. NavDestination() {
  22. Column() {
  23. YTHeader({ defaultStyle: { title: '搜索' } })
  24. Column(){
  25. List(){
  26. ListItem(){
  27. DeerSearch({
  28. onSearch: this.onSearch,
  29. })
  30. }
  31. .margin({top: 14})
  32. ListItem(){
  33. Row(){
  34. Text('搜索历史')
  35. .attributeModifier(new CustomTextStyle({ size: 12, weight: 600 }))
  36. Image($r('[basic].media.icon_trashCan'))
  37. .width(24)
  38. .aspectRatio(1)
  39. .onClick(() => { this.clearHistory() })
  40. }
  41. .width("100%")
  42. .alignItems(VerticalAlign.Center)
  43. .justifyContent(FlexAlign.SpaceBetween)
  44. }
  45. .margin({top: 16})
  46. ListItem(){
  47. Flex({wrap: FlexWrap.Wrap, space: { cross: new LengthMetrics(9), main: new LengthMetrics(6)}}) {
  48. ForEach(this.searHistory.history, (item: string, index) => {
  49. Text(item)
  50. .borderRadius(13)
  51. .backgroundColor('rgba(0, 0, 0, 0.04)')
  52. .padding({left: 11, top: 6, right: 11, bottom: 6})
  53. .attributeModifier(new CustomTextStyle({ size: 12, weight: 400, color: 'rgba(0, 0, 0, 0.5)' }))
  54. .onClick(() => { this.onSearch(item) })
  55. })
  56. }
  57. .width("100%")
  58. }
  59. .margin({top: 4})
  60. ListItem(){
  61. Scroll(){
  62. Row({space: 15}){
  63. ForEach(['热门搜索', '主体分类'], (item: string, index) => {
  64. Column(){
  65. Row({space: 8}){
  66. Image(index == 0 ?
  67. $r('[basic].media.icon_SearchHot') :
  68. $r('[basic].media.icon_SearchClassify')
  69. )
  70. .width(24)
  71. .aspectRatio(1)
  72. Text(item)
  73. }
  74. Divider()
  75. .height(2)
  76. .backgroundColor('#f1f1f1')
  77. .width('90%')
  78. .margin({left: 15, top: 13, bottom: 13})
  79. ForEach(new Array(20).fill(''), (item: string, index) => {
  80. Row({space: 5}){
  81. Text(`${index<9?' ':''}${index+1}`)
  82. .attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: index < 3 ? '#FFFC3636' : '#FF000000'}))
  83. Text('西游记')
  84. .attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: index < 3 ? '#FF000000' : '#80000000'}))
  85. }
  86. .width('100%')
  87. .margin({top: 12})
  88. .justifyContent(FlexAlign.Start)
  89. .onClick(() => { this.onSearch('西游记') })
  90. })
  91. }
  92. .width(230)
  93. .borderRadius(8)
  94. .alignItems(HorizontalAlign.Start)
  95. .border({width: 2, color: '#000000'})
  96. .padding({left: 10, right: 10, top: 13, bottom: 13})
  97. })
  98. }
  99. }
  100. .scrollBar(BarState.Off)
  101. .scrollable(ScrollDirection.Horizontal)
  102. }
  103. .margin({top: 20})
  104. ListItem()
  105. .height(this.safeBottom)
  106. }
  107. .width('100%')
  108. .height('100%')
  109. .scrollBar(BarState.Off)
  110. }
  111. .width('100%')
  112. .layoutWeight(1)
  113. .padding({ left: 16, right: 16 })
  114. }
  115. .width('100%')
  116. .height('100%')
  117. .backgroundColor('#F7F8FA')
  118. .justifyContent(FlexAlign.Start)
  119. .alignItems(HorizontalAlign.Start)
  120. }
  121. .hideTitleBar(true)
  122. }
  123. }
  124. @Builder
  125. function BookSearchBuilder() {
  126. BookSearchPage()
  127. }