index.ux 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <list id="catalog" class="catalog-wrap" @scrollbottom="loadCatalog" @scrolltop="loadPrev" v-if="list.length>0">
  3. <block for="list">
  4. <list-item type="catalog-item" class="catalog-item {{$idx == chapter_sequence_index ? 'checked' : ''}}" @click='jumpReader($item)'>
  5. <text class="catalog-name {{$idx == chapter_sequence_index ? 'catalog-name__check' : ''}}">{{$item.chapter_name}}</text>
  6. <image show='{{$item.chapter_is_vip}}' src="../../assets/imgs/book-vip.png"></image>
  7. </list-item>
  8. </block>
  9. <list-item type="loading-text" class="loading-wrap" if="!end">
  10. <progress type="circular"></progress>
  11. <text>加载中...</text>
  12. </list-item>
  13. <list-item type="loading-text" class="loading-wrap" else>
  14. <text>已经到底了</text>
  15. </list-item>
  16. </list>
  17. </template>
  18. <script>
  19. import { getCatalog } from "../../api";
  20. import router from '@system.router';
  21. import prompt from '@system.prompt';
  22. const PER_PAGE_NUM = 50;
  23. export default {
  24. protected: {
  25. bid: "",
  26. chapter_sequence: "",
  27. },
  28. private: {
  29. list: [],
  30. meta: {},
  31. chapter_sequence_index: 0,
  32. startpage: 1,
  33. loading: false,
  34. end: false,
  35. },
  36. onInit() {
  37. // let page = 1
  38. // var chapter_sequence_index = 0
  39. // if (this.chapter_sequence) {
  40. // var chapter_sequence = this.chapter_sequence
  41. // chapter_sequence_index = chapter_sequence % PER_PAGE_NUM - 1
  42. // this.chapter_sequence_index = chapter_sequence_index
  43. // page = Math.ceil(chapter_sequence / PER_PAGE_NUM)
  44. // }
  45. // this.startpage = page;
  46. // getCatalog({ bid: this.bid, page: page, page_size: PER_PAGE_NUM }).then(r => {
  47. // this.list = r.list
  48. // this.meta = r.meta
  49. // setTimeout(() => {
  50. // this.$element('catalog').scrollTo({ index: chapter_sequence_index })
  51. // }, 500)
  52. // })
  53. },
  54. onShow() {
  55. let page = 1
  56. var chapter_sequence_index = 0
  57. if (this.chapter_sequence) {
  58. var chapter_sequence = this.chapter_sequence
  59. chapter_sequence_index = chapter_sequence % PER_PAGE_NUM - 1
  60. this.chapter_sequence_index = chapter_sequence_index
  61. page = Math.ceil(chapter_sequence / PER_PAGE_NUM)
  62. }
  63. this.startpage = page;
  64. getCatalog({ bid: this.bid, page: page, page_size: PER_PAGE_NUM }).then(r => {
  65. this.list = r.list
  66. this.meta = r.meta
  67. setTimeout(() => {
  68. this.$element('catalog').scrollTo({ index: chapter_sequence_index })
  69. }, 500)
  70. })
  71. },
  72. jumpReader(info) {
  73. if (info.is_need_charge == 1) {
  74. this.chapter_sequence = info.chapter_sequence
  75. router.push({
  76. uri: "/views/Pay",
  77. params: {
  78. bid: info.bid,
  79. }
  80. })
  81. return
  82. }
  83. router.push({
  84. uri: "/views/Reader",
  85. params: {
  86. bid: info.bid,
  87. chapter_id: info.chapter_id
  88. }
  89. })
  90. },
  91. loadCatalog() {
  92. if (this.meta.last_page < (this.meta.current_page + 1)) {
  93. prompt.showToast({ message: '已经到底啦' });
  94. this.end = true;
  95. return;
  96. }
  97. let params = {
  98. bid: this.bid,
  99. page: this.meta.current_page + 1,
  100. page_size: PER_PAGE_NUM
  101. }
  102. this.initCatalog(params);
  103. // getCatalog({ bid: '5pNo6A7wqQmB1WgQygDjkOM9VZn2vXeY', page: this.meta.current_page + 1, page_size: PER_PAGE_NUM }).then(r => {
  104. // console.log(...r.list)
  105. // this.list.push(...r.list)
  106. // this.meta = r.meta
  107. // })
  108. },
  109. loadPrev() {
  110. console.log("get prev catalog");
  111. if ((this.startpage - 1) < 1) return prompt.showToast({ message: '已经到顶啦' });
  112. let params = {
  113. bid: this.bid,
  114. page: this.startpage - 1,
  115. page_size: PER_PAGE_NUM
  116. }
  117. this.initCatalog(params, true);
  118. // getCatalog({ bid: '5pNo6A7wqQmB1WgQygDjkOM9VZn2vXeY', page: this.startpage - 1, page_size: PER_PAGE_NUM }).then(r => {
  119. // console.log(...r.list)
  120. // this.list.unshift(...r.list)
  121. // this.startpage = r.meta.current_page
  122. // })
  123. },
  124. initCatalog(params, isLoadPrev = false) {
  125. this.end = false;
  126. getCatalog(params).then(r => {
  127. if (isLoadPrev) {
  128. this.list.unshift(...r.list)
  129. this.startpage = r.meta.current_page
  130. } else {
  131. this.list.push(...r.list)
  132. this.meta = r.meta;
  133. }
  134. })
  135. }
  136. }
  137. </script>
  138. <style lang="less">
  139. @import "../../assets/less/catalog.less";
  140. </style>