index.ux 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <import name="x-book" src="../../components/book/book.ux"></import>
  2. <template>
  3. <div class="home-wrap">
  4. <div class="home_title"><text>精选</text></div>
  5. <div class="type-wrap_content">
  6. <div class="type-wrap">
  7. <block for="type in typeList">
  8. <div class="type-item" @click="typeChange(type.index)">
  9. <text class="{{type.index === current ? 'cur' : ''}}">{{
  10. type.name
  11. }}</text>
  12. <text class="choose-bar" show="{{type.index === current}}"></text>
  13. </div>
  14. </block>
  15. <!-- <text class="feebar-text" @click="toPage('Free')">限时免费</text> -->
  16. </div>
  17. <div class="search-bar">
  18. <div class="search-bar__wrap">
  19. <text @click="toCategory">请输入书名或者作者名</text
  20. ><image
  21. src="https://yueduyun.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/img/search.png"
  22. ></image>
  23. </div>
  24. </div>
  25. </div>
  26. <!-- <div class="type-bar">
  27. <div class="search-bar__wrap">
  28. <text @click="toCategory">请输入书名或者作者名</text
  29. ><image
  30. src="https://yueduyun.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/img/search.png"
  31. ></image>
  32. </div>
  33. </div> -->
  34. <list class="list-content">
  35. <list-item type="swipe" class="swipe-bar">
  36. <swiper class="swipe-bar" autoplay="true" indicator="false">
  37. <block for="b in banner">
  38. <div class="swipe-item">
  39. <image
  40. class="cover"
  41. src="{{b.banner_url}}"
  42. @click="pageRouter(b)"
  43. ></image>
  44. </div>
  45. </block>
  46. </swiper>
  47. </list-item>
  48. <!-- <list-item type="entrance">
  49. <div class="entrance_block">
  50. <div>
  51. <image
  52. src="../../assets/imgs/to_search.png"
  53. @click="toPage('Search')"
  54. ></image>
  55. </div>
  56. <div>
  57. <image
  58. src="../../assets/imgs/to_task.png"
  59. @click="toPage('Task')"
  60. ></image>
  61. </div>
  62. <div>
  63. <image
  64. src="../../assets/imgs/to_rank.png"
  65. @click="toPage('Leaderboard')"
  66. ></image>
  67. </div>
  68. </div>
  69. </list-item> -->
  70. <block for="bookObj in list">
  71. <list-item type="simple" class="book-list__wrap" if="$idx % 3 === 0">
  72. <div class="book-list_content">
  73. <div class="book-list__title">
  74. <text class="border"></text>
  75. <text>{{ bookObj.lable }}</text>
  76. </div>
  77. <div class="book-list__multi">
  78. <block for="book in bookObj.books.slice(4)">
  79. <div class="book-item">
  80. <x-book multi="{{true}}" width="{{150}}" book="{{book}}">
  81. <div class="book-info__multi">
  82. <text class="name">{{ book.book_name }}</text>
  83. <text class="intro">{{ book.book_summary }}</text>
  84. </div>
  85. </x-book>
  86. </div>
  87. </block>
  88. </div>
  89. <div class="book-list__line">
  90. <block for="book in bookObj.books.slice(0, 4)">
  91. <x-book
  92. multi="{{false}}"
  93. width="{{150}}"
  94. lines="{{true}}"
  95. book="{{book}}"
  96. ></x-book>
  97. </block>
  98. </div>
  99. </div>
  100. </list-item>
  101. <list-item
  102. type="multi"
  103. class="book-list__wrap book-list__wrap--multi"
  104. else
  105. >
  106. <div class="book-list_content">
  107. <div class="book-list__title">
  108. <text>{{ bookObj.lable }}</text>
  109. </div>
  110. <div class="book-list">
  111. <block for="book in bookObj.books">
  112. <x-book multi="{{false}}" book="{{book}}"></x-book>
  113. </block>
  114. </div>
  115. </div>
  116. </list-item>
  117. </block>
  118. <list-item style="height:120px;"></list-item>
  119. </list>
  120. </div>
  121. </template>
  122. <script>
  123. import { getHomeList , getBannerData,checkAdvertisement} from '../../api'
  124. import storage from '@system.storage'
  125. import router from '@system.router'
  126. export default {
  127. props: {
  128. tabindex: {
  129. type: Number,
  130. default: 0
  131. }
  132. },
  133. data() {
  134. return {
  135. typeList: [
  136. {
  137. name: '男生',
  138. index: 0
  139. },
  140. {
  141. name: '女生',
  142. index: 1
  143. }
  144. ],
  145. banner: [],
  146. list: [],
  147. current: 1
  148. }
  149. },
  150. async onInit() {
  151. await this.getCityListByTabChange()
  152. this.$on('refreshData', this.broadevt)
  153. this.$watch('current', 'getCityListByTabChange')
  154. this.$watch('tabindex', 'watchPropsChange')
  155. },
  156. typeChange(index) {
  157. this.current = index
  158. },
  159. watchPropsChange(v) {
  160. if (v === 0) this.getCityListByTabChange(this.current)
  161. },
  162. async broadevt(evt) {
  163. if (evt.detail.current == 0) {
  164. await this.getCityListByTabChange(this.current)
  165. }
  166. },
  167. toCategory() {
  168. //this.$emit('change');
  169. router.push({
  170. uri: '/views/Search'
  171. })
  172. },
  173. pageRouter(page) {
  174. if(page.ids){
  175. try{
  176. let type = page.type ? "default" : "";
  177. checkAdvertisement(type,page.ids);
  178. // console.log('type',type);
  179. }catch(e){
  180. }
  181. }
  182. if (page.redirect_url && page.redirect_url != "#") {
  183. if (page.redirect_type == "book") {
  184. router.push({
  185. uri: page.redirect_url,
  186. params: {
  187. bid: page.bid,
  188. chapter_id: page.cid
  189. }
  190. })
  191. } else if (page.redirect_type == "activity") {
  192. router.push({
  193. uri: page.redirect_url,
  194. params:page.param
  195. })
  196. }
  197. }
  198. },
  199. toMyRead() {
  200. this.$emit('change')
  201. },
  202. jump(page) {
  203. router.push({
  204. uri: '/views/' + page
  205. })
  206. },toPage(page) {
  207. router.push({
  208. uri: '/views/' + page,
  209. params: {
  210. sex: this.current
  211. }
  212. })
  213. },toCategory() {
  214. router.push({
  215. uri: '/views/Search',
  216. })
  217. },
  218. async getCityListByTabChange(index = 1) {
  219. await storage.set({ key: 'sex', value: index || 0 })
  220. let sex = index ? 'female' : 'male'
  221. let ret = await getHomeList(sex)
  222. // this.banner = ret.slice(0, 1)[0]
  223. this.list = ret.slice(1)
  224. let banner = await getBannerData(sex == "female" ? 2 : 1);
  225. this.banner = banner;
  226. }
  227. }
  228. </script>
  229. <style lang="less">
  230. @import "../../assets/less/home.less";
  231. </style>