index.ux 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <import name="x-book" src="../../components/book/book.ux"></import>
  2. <template>
  3. <div class="home-wrap">
  4. <div class="type-bar">
  5. <block for="type in typeList">
  6. <div class="type-item" @click="typeChange(type.index)">
  7. <text class="{{type.index === current ? 'cur' : ''}}">{{type.name}}</text>
  8. <text class="choose-bar" show="{{type.index === current}}"></text>
  9. </div>
  10. </block>
  11. </div>
  12. <list class="list-content">
  13. <list-item type="search" class="search-bar">
  14. <div class="search-bar__wrap">
  15. <image src="https://yueduyun.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/img/search.png"></image>
  16. <text @click="toCategory">书名</text>
  17. </div>
  18. </list-item>
  19. <list-item type="swipe">
  20. <swiper class="swipe-bar" autoplay="true" indicator="false">
  21. <block for="b in banner.books">
  22. <div class="swipe-item">
  23. <image class="cover" src="{{b.banner_url}}" @click="pageRouter(b)"></image>
  24. </div>
  25. </block>
  26. </swiper>
  27. </list-item>
  28. <list-item type="entrance">
  29. <div class="entrance_block">
  30. <div><image src="../../assets/imgs/home_fl.png" @click="jump('Category')"></image><text>分类</text></div>
  31. <div><image src="../../assets/imgs/home_rank.png" @click="jump('Leaderboard')"></image><text>排行榜</text></div>
  32. <div><image src="../../assets/imgs/home_free.png" @click="jump('Free')"></image><text>限时免费</text></div>
  33. <div><image src="../../assets/imgs/home_pre.png" @click="toMyRead"></image><text>最近阅读</text></div>
  34. </div>
  35. </list-item>
  36. <block for="bookObj in list">
  37. <list-item type="simple" class="book-list__wrap" if="$idx % 2 === 0">
  38. <div class="book-list__title">
  39. <text>{{bookObj.lable}}</text>
  40. </div>
  41. <div class="book-list">
  42. <block for="book in bookObj.books">
  43. <x-book multi="{{false}}" book="{{book}}"></x-book>
  44. </block>
  45. </div>
  46. </list-item>
  47. <list-item type="multi" class="book-list__wrap book-list__wrap--multi" else>
  48. <div class="book-list__title">
  49. <text class="border"></text>
  50. <text>{{bookObj.lable}}</text>
  51. </div>
  52. <div class="book-list__line">
  53. <block for="book in bookObj.books.slice(0, 4)">
  54. <x-book multi="{{false}}" width="{{150}}" lines="{{true}}" book="{{book}}"></x-book>
  55. </block>
  56. </div>
  57. <div class="book-list__multi">
  58. <block for="book in bookObj.books.slice(4)">
  59. <div class="book-item">
  60. <x-book multi="{{true}}" width="{{150}}" book="{{book}}" >
  61. <div class="book-info__multi">
  62. <text class="name">{{book.book_name}}</text>
  63. <text class="intro">{{book.book_summary}}</text>
  64. </div>
  65. </x-book>
  66. </div>
  67. </block>
  68. </div>
  69. </list-item>
  70. </block>
  71. </list>
  72. </div>
  73. </template>
  74. <script>
  75. import { getHomeList } from "../../api";
  76. import storage from '@system.storage';
  77. import router from '@system.router';
  78. export default {
  79. props: {
  80. tabindex: {
  81. type: Number,
  82. default: 0
  83. }
  84. },
  85. data() {
  86. return {
  87. typeList: [
  88. {
  89. name: "男生",
  90. index: 0
  91. },
  92. {
  93. name: "女生",
  94. index: 1
  95. }
  96. ],
  97. banner: [],
  98. list: [],
  99. current: 1
  100. }
  101. },
  102. async onInit() {
  103. await this.getCityListByTabChange();
  104. this.$on('refreshData',this.broadevt);
  105. this.$watch('current', 'getCityListByTabChange');
  106. this.$watch('tabindex', 'watchPropsChange');
  107. },
  108. typeChange(index) {
  109. this.current = index;
  110. },
  111. watchPropsChange(v){
  112. if (v === 0) this.getCityListByTabChange(this.current);
  113. },
  114. async broadevt(evt){
  115. if(evt.detail.current==0){
  116. await this.getCityListByTabChange(this.current);
  117. }
  118. },
  119. toCategory() {
  120. //this.$emit('change');
  121. router.push({
  122. uri: '/views/Search',
  123. })
  124. },
  125. pageRouter(page) {
  126. router.push({
  127. uri: page.redirect_url,
  128. params: {
  129. bid: page.bid,
  130. chapter_id: page.cid
  131. }
  132. })
  133. },
  134. toMyRead(){
  135. this.$emit('change');
  136. },
  137. jump(page) {
  138. router.push({
  139. uri: '/views/' + page,
  140. })
  141. },
  142. async getCityListByTabChange(index = 1) {
  143. await storage.set({ key: "sex", value: index || 0 });
  144. let sex = index ? "female" : "male";
  145. let ret = await getHomeList(sex);
  146. this.banner = ret.slice(0, 1)[0];
  147. this.list = ret.slice(1);
  148. }
  149. }
  150. </script>
  151. <style lang="less">
  152. /* @import "../../assets/less/home.less"; */
  153. .home-wrap {
  154. background-color: #fff;
  155. flex-direction: column;
  156. padding-top: 20px;
  157. .entrance_block {
  158. width: 100%;
  159. padding: 30px;
  160. display: flex;
  161. justify-content: space-around;
  162. div{
  163. flex-direction: column;
  164. text{
  165. margin-top: 10px;
  166. text-align: center;
  167. }
  168. }
  169. image {
  170. width:80px;
  171. height:80px;
  172. margin:0 auto;
  173. }
  174. }
  175. .type-bar {
  176. background-color: #fff;
  177. .type-item {
  178. flex: 1;
  179. justify-content: center;
  180. align-items: center;
  181. flex-direction: column;
  182. position: relative;
  183. text {
  184. font-size: 30px;
  185. color: #999;
  186. // padding: 34px 0;
  187. }
  188. .cur {
  189. color: #ef5952;
  190. font-size: 36px;
  191. font-weight: bold;
  192. }
  193. .choose-bar {
  194. width: 38px;
  195. height: 4px;
  196. background-color: #ef5952;
  197. border-radius: 2px;
  198. margin-top: 10px;
  199. }
  200. }
  201. }
  202. .search-bar {
  203. padding: 24px;
  204. .search-bar__wrap {
  205. flex: 1;
  206. background-color: #f7f7f7;
  207. height: 62px;
  208. padding: 0 14px;
  209. border-radius: 30px;
  210. align-items: center;
  211. image {
  212. margin-right: 20px;
  213. width: 36px;
  214. height: 36px;
  215. }
  216. text {
  217. flex: 1;
  218. font-size: 24px;
  219. color: #999;
  220. }
  221. }
  222. }
  223. .swipe-bar {
  224. height: 260px;
  225. // background-color: #fff;
  226. .swipe-item {
  227. padding: 0px 24px;
  228. .swipe-item__info {
  229. flex: 1;
  230. flex-direction: column;
  231. padding-right: 32px;
  232. .name {
  233. font-size: 32px;
  234. color: #333;
  235. }
  236. .intro {
  237. font-size: 26px;
  238. color: #666;
  239. margin-top: 36px;
  240. lines: 4;
  241. text-overflow: ellipsis;
  242. }
  243. .category {
  244. font-size: 24px;
  245. color: #32a1ff;
  246. margin-top: 10px;
  247. }
  248. }
  249. .cover {
  250. width: 100%;
  251. height: 260px;
  252. // flex-basis: 180px;
  253. // flex-shrink: 0;
  254. // height: 240px;
  255. border-radius: 6px;
  256. }
  257. }
  258. }
  259. .book-list__wrap {
  260. background-color: #fff;
  261. // margin-top: 24px;
  262. padding: 0 24px;
  263. flex-direction: column;
  264. .book-list__title {
  265. padding: 30px 0;
  266. align-items: center;
  267. text {
  268. color: #333;
  269. font-size: 32px;
  270. }
  271. }
  272. }
  273. .book-list {
  274. flex: 1;
  275. flex-direction: row;
  276. flex-wrap: wrap;
  277. justify-content: space-between;
  278. }
  279. .book-list__multi {
  280. margin-top: 30px;
  281. flex-direction: column;
  282. .book-item {
  283. margin-bottom: 30px;
  284. }
  285. .book-info__multi {
  286. flex: 1;
  287. flex-direction: column;
  288. justify-content: flex-start;
  289. align-items: flex-start;
  290. margin-left: 38px;
  291. // margin-bottom: 40px;
  292. .name {
  293. font-size: 32px;
  294. color: #333;
  295. lines: 1;
  296. text-overflow: ellipsis;
  297. }
  298. .intro {
  299. font-size: 24px;
  300. color: #666;
  301. lines: 3;
  302. text-overflow: ellipsis;
  303. margin-top: 36px;
  304. line-height: 36px;
  305. }
  306. }
  307. }
  308. .book-list__line {
  309. justify-content: space-between;
  310. align-items: flex-start;
  311. border-bottom: 2px solid #f7f7f7;
  312. }
  313. }
  314. </style>