SecondView.ets 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. import { DeerSearch } from '../components/DeerSearch'
  2. import { SecondViewModel } from './viewModel/SecondViewModel'
  3. import { CustomTextStyle } from '../style/CustomTextStyle'
  4. import { bookItemComp, bookItemCompCover } from '../components/BuilderIndex'
  5. import { BookListTypeList } from '../model/BookModelIndex'
  6. import { cert } from '@kit.DeviceCertificateKit'
  7. import { BookItem } from 'basic'
  8. @ComponentV2
  9. export struct SecondView {
  10. vm: SecondViewModel = new SecondViewModel()
  11. build() {
  12. Column(){
  13. Row({space: 12}){
  14. Row({space: 6}){
  15. Text(this.vm.ageRange || '年龄选择')
  16. .attributeModifier(new CustomTextStyle({size: 14, weight: 600}))
  17. Image($r('[basic].media.icon_expension'))
  18. .width(10)
  19. .height(8)
  20. .rotate({ angle: this.vm.openAgeDialog ? 180 : 0 })
  21. .animation({duration: 200, curve: Curve.Smooth})
  22. }
  23. .width(120)
  24. .borderRadius(18)
  25. .padding({top: 8, bottom: 8})
  26. .backgroundColor('#FFFECF2F')
  27. .justifyContent(FlexAlign.Center)
  28. .border({width: 2, color: '#FF000000'})
  29. .bindMenu(this.ageSelect())
  30. .onClick(() => { if(!this.vm.openAgeDialog) this.vm.openAgeDialog = true })
  31. DeerSearch({showSearchButton: false, enable: false})
  32. .layoutWeight(1)
  33. }
  34. .width("100%")
  35. .padding({left: 16, right: 16, top: this.vm.safeTop, bottom: 20})
  36. .linearGradient( this.vm.openTypeDialog ? {colors: [['#FFF2C0', 0], ['#FFF3C6', 1]]} : undefined)
  37. Column(){
  38. RelativeContainer(){
  39. Column(){
  40. // 页面的 Title
  41. Column(){
  42. Row(){
  43. Row(){
  44. List({space: 22, scroller: this.vm.categoryControl}){
  45. ForEach(this.vm.categoryList.list, (item: BookListTypeList, index) => {
  46. ListItem(){
  47. Column(){
  48. Text(item.bookListTypeName)
  49. .zIndex(99)
  50. .onClick(() => { this.vm.changeCategory(index) })
  51. .attributeModifier(new CustomTextStyle({size: 16, weight: 600, color: this.vm.categoryIndex == index ? '#FF111111' : '#FF777777'}))
  52. if(this.vm.categoryIndex == index){
  53. Image($r('[basic].media.icon_SelectBg'))
  54. .width(45)
  55. .height(16)
  56. .margin({top:-10})
  57. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.TOP), TransitionEffect.move(TransitionEdge.TOP)).animation({ duration: 100, curve: Curve.Smooth }))
  58. }
  59. }
  60. .alignItems(HorizontalAlign.Center)
  61. }
  62. })
  63. }
  64. .height(40)
  65. .width("100%")
  66. .scrollBar(BarState.Off)
  67. .listDirection(Axis.Horizontal)
  68. }.layoutWeight(1)
  69. Row(){
  70. Image($r('[basic].media.icon_expension'))
  71. .width(10)
  72. .height(8)
  73. .rotate({ angle: this.vm.openTypeDialog ? 180 : 0 })
  74. .animation({duration: 200, curve: Curve.Smooth})
  75. }
  76. .padding({left: 16, top: 2})
  77. .onClick(() => { this.vm.openCategoryDialog() })
  78. }.alignItems(VerticalAlign.Top)
  79. Row(){
  80. Row(){
  81. ForEach(['最新', '最热'], (item: string, index: number) => {
  82. Text(item)
  83. .borderRadius(15)
  84. .padding({left: 12, top: 5, right: 12, bottom: 5})
  85. .attributeModifier(new CustomTextStyle({size: 14, weight: 600}))
  86. .border({width: 2, color: this.vm.query?.sort == index ? '#FF000000' : Color.Transparent})
  87. .backgroundColor(this.vm.query?.sort == index ? '#FFFECF2F' : Color.Transparent)
  88. .onClick(() => { this.vm.changeSortType(index) })
  89. })
  90. }
  91. Row({space: 16}){
  92. Row({space: 6}){
  93. Blank()
  94. .width(14)
  95. .aspectRatio(1)
  96. .borderRadius(2)
  97. .border({width: 2, color: '#FF000000'})
  98. .backgroundColor(this.vm.isRead ? '#FFFECF2F' : Color.White)
  99. Text('未读')
  100. .attributeModifier(new CustomTextStyle({size: 14, weight: 400}))
  101. }.onClick(() => { this.vm.changeIsRead() })
  102. Text(this.vm.showMode ? '封面模式' : '列表模式')
  103. .onClick(() => { this.vm.changeShowMode() })
  104. .attributeModifier(new CustomTextStyle({size: 14, weight: 400}))
  105. }
  106. }
  107. .width("100%")
  108. .margin({top: 10})
  109. .justifyContent(FlexAlign.SpaceBetween)
  110. }
  111. .width("100%")
  112. .backgroundColor(Color.White)
  113. .borderRadius({bottomLeft: 20, bottomRight: 20})
  114. .padding({left: 16, right: 16, bottom: 18})
  115. // 书籍列表项
  116. Column(){
  117. List({space: 12}){
  118. ListItem()
  119. Repeat(this.vm.bookList)
  120. .each((item: RepeatItem<BookItem>) => {
  121. if(this.vm.showMode) {
  122. // 列表模式
  123. bookItemComp(
  124. item,
  125. () => { this.vm.goBookDetail(item.item) },
  126. () => { this.vm.addToBook(item.item) })
  127. } else {
  128. // 封面模式
  129. bookItemCompCover(item, () => {})
  130. }
  131. })
  132. }
  133. .width("100%")
  134. .height("100%")
  135. .scrollBar(BarState.Off)
  136. }
  137. .id('list')
  138. .width("100%")
  139. .layoutWeight(1)
  140. .padding({left: 16, right: 16})
  141. .backgroundColor(Color.Transparent)
  142. }.width("100%").height("100%")
  143. .alignRules({
  144. left: { anchor: '__container__', align: HorizontalAlign.Start },
  145. top: { anchor: '__container__', align: VerticalAlign.Top }
  146. })
  147. // 分类弹窗
  148. if(this.vm.openTypeDialog){
  149. Column(){
  150. Column(){
  151. Row(){
  152. Column(){
  153. Text('选择分类')
  154. .zIndex(99)
  155. .attributeModifier(new CustomTextStyle({size: 16, weight: 600}))
  156. Image($r('[basic].media.icon_SelectBg'))
  157. .width(45)
  158. .height(16)
  159. .margin({top:-10})
  160. }
  161. Column(){
  162. Image($r('[basic].media.icon_expension'))
  163. .width(10)
  164. .height(8)
  165. .rotate({ angle: this.vm.openTypeDialog ? 180 : 0 })
  166. .animation({duration: 200, curve: Curve.Smooth})
  167. }
  168. .width(50)
  169. .height(24)
  170. .alignItems(HorizontalAlign.End)
  171. .justifyContent(FlexAlign.Center)
  172. .onClick(() => { this.vm.openCategoryDialog() })
  173. }
  174. .width("100%")
  175. .justifyContent(FlexAlign.SpaceBetween)
  176. Grid(){
  177. ForEach(this.vm.categoryList.list, (item: BookListTypeList, index: number) => {
  178. GridItem(){
  179. Text(item.bookListTypeName)
  180. .width('100%')
  181. .borderRadius(18)
  182. .textAlign(TextAlign.Center)
  183. .padding({top: 6, bottom: 6})
  184. .backgroundColor(this.vm.categoryIndex == index ? '#FFFECF2F' : '#FFFFFF')
  185. .border({width: 2, color: this.vm.categoryIndex == index ? '#FF000000' : '#FFFFFF'})
  186. .attributeModifier(new CustomTextStyle({size: 16, weight: 400}))
  187. .onClick(() => {
  188. this.vm.changeCategory(index, true)
  189. this.vm.openCategoryDialog()
  190. })
  191. }
  192. })
  193. }
  194. .rowsGap(14)
  195. .columnsGap(23)
  196. .margin({top: 13})
  197. .maxCount(Math.abs(this.vm.categoryList?.list?.length/3))
  198. .columnsTemplate('repeat(3, 1fr)')
  199. }
  200. .width("100%")
  201. .onClick(() => {})
  202. .padding({left: 17, right: 17, bottom: 13})
  203. .borderRadius({bottomLeft: 16, bottomRight: 16})
  204. .linearGradient({colors: [['#FFF3C6', 0], ['#FFF9E4', 1]]})
  205. .transition(TransitionEffect.translate({ y: -20 })
  206. .animation({ duration: 200, curve: Curve.Friction}))
  207. }
  208. .width("100%")
  209. .height("100%")
  210. .backgroundColor('rgba(0, 0, 0, 0.5)')
  211. .onClick(() => { this.vm.openCategoryDialog() })
  212. .alignRules({
  213. left: { anchor: '__container__', align: HorizontalAlign.Start },
  214. top: { anchor: '__container__', align: VerticalAlign.Top }
  215. })
  216. }
  217. }
  218. .width('100%')
  219. .height('100%')
  220. .backgroundColor('#F7F9FA')
  221. }
  222. .width('100%')
  223. .layoutWeight(1)
  224. }
  225. .width('100%')
  226. .height('100%')
  227. }
  228. @Builder
  229. ageSelect(){
  230. Column({space: 17}){
  231. ForEach(this.vm.ageList, (item: string, index: number) => {
  232. Text(item)
  233. .attributeModifier(new CustomTextStyle({size: 14, weight: 600}))
  234. .onClick(() => {
  235. this.vm.changeAgeRange(index)
  236. })
  237. })
  238. }
  239. .margin(-4)
  240. .borderRadius(20)
  241. .border({width: 2, color: '#FF000000'})
  242. .padding({left: 32, right: 32, top: 19, bottom: 19})
  243. .onDisAppear(() => { this.vm.openAgeDialog = false })
  244. }
  245. }