index.ux 6.0 KB

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