MainView.ets 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import { BasicType } from "basic"
  2. import { tagItemComp } from "../components/BuilderIndex"
  3. import { DeerSearch } from "../components/DeerSearch"
  4. import { ytBuildComp } from "../components/ytBuildComp"
  5. import { CustomTextStyle } from "../style/CustomTextStyle"
  6. import { MainViModel } from "./viewModel/MainViewModel"
  7. @ComponentV2
  8. export struct MainView {
  9. vm: MainViModel = new MainViModel()
  10. build() {
  11. ytBuildComp(){
  12. Column() {
  13. Stack({alignContent: Alignment.Top}){
  14. List(){
  15. // logo
  16. ListItem(){
  17. Text('京东快递合作伙伴')
  18. .attributeModifier(new CustomTextStyle({size: 12, weight: 600}))
  19. .padding({top: this.vm.safeTop})
  20. }
  21. .padding({bottom: 13})
  22. // 搜索框
  23. ListItem(){
  24. this.customSearch()
  25. }
  26. ListItem(){
  27. Column(){
  28. // 轮播
  29. Swiper(){
  30. Row()
  31. .height(150)
  32. .width('100%')
  33. .backgroundColor(Color.Orange)
  34. }
  35. .height(150)
  36. .width("100%")
  37. .enabled(false)
  38. .indicator(false)
  39. .borderRadius(30)
  40. // 功能
  41. Row(){
  42. ForEach(this.vm.function1, (item: BasicType, index) => {
  43. Column({space: 5}){
  44. Image(item.src)
  45. .width(60)
  46. .aspectRatio(1)
  47. Text(item.text)
  48. .attributeModifier(new CustomTextStyle({size: 14, weight: 600}))
  49. }
  50. .onClick(item.click)
  51. })
  52. }
  53. .width("100%")
  54. .margin({top: 22})
  55. .justifyContent(FlexAlign.SpaceAround)
  56. // 榜单
  57. Row({space: 7}){
  58. ForEach(['畅销版单TOP', '月度推荐'], (item: string, index) => {
  59. Column({space: 5}){
  60. Text(item)
  61. .attributeModifier(new CustomTextStyle({size: 16, weight: 600, color: '#663815'}))
  62. Text('查看更多>>')
  63. .attributeModifier(new CustomTextStyle({size: 12, weight: 600, color: index == 0 ?'#B27500' : '#E45C0B'}))
  64. }
  65. .layoutWeight(1)
  66. .aspectRatio(1)
  67. .justifyContent(FlexAlign.Start)
  68. .alignItems(HorizontalAlign.Start)
  69. .padding({left: 15, top: 17, right: 15, bottom: 17})
  70. .backgroundImage( index == 0 ?
  71. $r('[basic].media.png_TopRecommend') :
  72. $r('[basic].media.png_MonthRecommend') )
  73. .backgroundImageSize({ width: '100%', height: '100%'})
  74. .onClick(() => {
  75. // todo 完成榜单的跳转
  76. })
  77. })
  78. }
  79. .width("100%")
  80. .margin({top: 18})
  81. // 新书上架
  82. Column({space: 18}){
  83. Row({space: 8}){
  84. Text('新书上架')
  85. .attributeModifier(new CustomTextStyle({size: 16, weight: 600}))
  86. Text('查看更多>>')
  87. .attributeModifier(new CustomTextStyle({size: 12, weight: 600, color: '#807A66'}))
  88. }
  89. .width("100%")
  90. .justifyContent(FlexAlign.Start)
  91. .alignItems(VerticalAlign.Bottom)
  92. Grid(){
  93. ForEach(new Array(4).fill(''), (item: string, index) => {
  94. GridItem(){
  95. Column(){
  96. Image('https://th.bing.com/th/id/R.8bbf769b39bb26eefb9b6de51c23851d?rik=crTnc5i8A%2b8p7A&riu=http%3a%2f%2fpicview.iituku.com%2fcontentm%2fzhuanji%2fimg%2f202207%2f09%2fe7196ac159f7cf2b.jpg%2fnu&ehk=DYPLVpoNAXLj5qzwgR5vHf9DladFh%2b34s4UcuP3Kn6E%3d&risl=&pid=ImgRaw&r=0')
  97. .width('100%')
  98. .aspectRatio(148/100)
  99. Column({space: 5}){
  100. Text('红楼梦幼儿美绘本 第四卷红楼梦幼儿美绘本 第四卷')
  101. .maxLines(2)
  102. .textOverflow({overflow: TextOverflow.Ellipsis})
  103. .attributeModifier(new CustomTextStyle({size: 14, weight: 400}))
  104. Row({space: 8}){
  105. tagItemComp('情绪价值', '#4EB1EF', '#EDF7FD')
  106. tagItemComp('3-8岁', '#FC9911', '#FFF5E7')
  107. }
  108. .width("100%")
  109. .justifyContent(FlexAlign.Start)
  110. }
  111. .width("100%")
  112. .padding({left: 8, right: 8, top: 8, bottom: 8})
  113. }
  114. .width('100%')
  115. .borderRadius(8)
  116. .aspectRatio(152/180)
  117. .backgroundColor(Color.White)
  118. .border({width: 2, color: '#000000'})
  119. }
  120. })
  121. }
  122. .rowsGap(16)
  123. .maxCount(2)
  124. .width("100%")
  125. .columnsGap(10)
  126. .layoutWeight(1)
  127. .columnsTemplate('repeat(2, 1fr)')
  128. }
  129. .height(500)
  130. .height(470)
  131. .width("100%")
  132. .margin({top: 25})
  133. .padding({left: 18, right: 18, top: 20})
  134. .backgroundImage($r('[basic].media.png_newBook'))
  135. .backgroundImageSize({width: '100%', height: '100%'})
  136. }
  137. .width("100%")
  138. }
  139. .margin({top: 13})
  140. ListItem(){}
  141. .padding({ bottom: 16 })
  142. }
  143. .width('100%')
  144. .height('100%')
  145. .scrollBar(BarState.Off)
  146. .padding({ left: 16, right: 16 })
  147. .onScrollIndex((index: number) => {
  148. this.vm.scrollIndex = index
  149. console.log(`index = ${JSON.stringify(index)}`)
  150. })
  151. if(this.vm.scrollIndex > 0){
  152. Row(){
  153. this.deerTitleComp()
  154. }
  155. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.TOP), TransitionEffect.move(TransitionEdge.TOP)).animation({ duration: 100 }))
  156. }
  157. }
  158. }
  159. .width('100%')
  160. .linearGradient({ colors: [['#F9EDAE', 0], ['#FFFFFF', 0.4]] })
  161. }
  162. }
  163. @Builder
  164. deerTitleComp(){
  165. Column({space: 10}){
  166. Row()
  167. .width(55)
  168. .height(30)
  169. this.customSearch()
  170. }
  171. .width('100%')
  172. .backgroundColor(Color.White)
  173. .alignItems(HorizontalAlign.Center)
  174. .shadow({ offsetY: 13, radius: 16, color: '#0A000000' })
  175. .padding({top: this.vm.safeTop, bottom: 10, left: 16, right: 16})
  176. }
  177. @Builder
  178. customSearch(){
  179. DeerSearch({ enable: false })
  180. }
  181. }