index.ux 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <import name="x-book" src="../../components/book/book.ux"></import>
  2. <template>
  3. <div class="shelfs">
  4. <div class="shelf_title">
  5. <text>书架</text>
  6. </div>
  7. <div v-if="isNull" if="{{Object.keys(firstBook).length > 0}}" @click="toReader(firstBook)" class="book_detail">
  8. <div class="image-recommend">
  9. <image src="../../assets/imgs/recommend-book.png"></image>
  10. </div>
  11. <div class="shelf-first__content">
  12. <image src="{{firstBook.cover_url}}"></image>
  13. <div class="book-info__multi">
  14. <text class="name">{{ firstBook.book_name }}</text>
  15. <text class="intro">{{ firstBook.intro }}</text>
  16. <text> {{firstBook.subtext}} </text>
  17. </div>
  18. </div>
  19. </div>
  20. <stack class="shelf">
  21. <div class="shelf-wrap">>
  22. <!-- <div class="type-bar">
  23. <div class="search-bar__wrap">
  24. <text @click="toSearch">请输入书名或者作者名</text
  25. ><image
  26. src="https://yueduyun.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/img/search.png"
  27. ></image>
  28. </div>
  29. </div> -->
  30. <div
  31. class="shelf-total {{current === 1 ? 'shelf-total__inRecent' : ''}}"
  32. if="{{mockList.length>0}}"
  33. >
  34. <text>共{{ booksize }}本</text>
  35. <div if="modeText" @click="changeMode">
  36. <text>
  37. <image
  38. src="../../assets/imgs/manage.png"
  39. class="modeimage"
  40. ></image>
  41. </text>
  42. <text class="administration-btn">{{ modeText }}</text>
  43. </div>
  44. <div if="!modeText" @click="changeMode">
  45. <text class="complete-btn">完成</text>
  46. </div>
  47. </div>
  48. <div if="{{mockList.length<=0 && isinit}}" class="blank_img">
  49. <image
  50. src="../../assets/imgs/white_shelf.png"
  51. ></image>
  52. <text>书架空空如也</text>
  53. <div class="add_book" @click="toCategory">
  54. <text>去添加</text>
  55. </div>
  56. </div>
  57. <block if="current === 0">
  58. <div class="shelf-books__wrap">
  59. <block for="mockList">
  60. <div class="book-item__wrap {{(($idx + 1)%4 === 0) ? 'm0' : ''}}">
  61. <stack>
  62. <x-book book="{{$item}}" read="{{true}}"></x-book>
  63. <div
  64. class="book-del__wrap"
  65. show="{{isDelMode}}"
  66. @click="deleteBook($item)"
  67. >
  68. <image
  69. src="https://yueduyun.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/img/delete.png"
  70. ></image>
  71. <text>删除</text>
  72. </div>
  73. </stack>
  74. </div>
  75. </block>
  76. <div class="book-item__wrap book-item__add m0" @click="toCategory">
  77. <image
  78. class="add-cover"
  79. src="https://yueduyun.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/img/bookstory.png"
  80. ></image>
  81. <text>添加书籍</text>
  82. </div>
  83. </div>
  84. </block>
  85. <block else>
  86. <list class="recent-list" if="{{mockList.length>0 && isinit}}">
  87. <list-item type="recent-item" class="recent-item">
  88. <div class="shelf-books__wrap">
  89. <block for="mockList">
  90. <div
  91. class="book-item__wrap {{(($idx + 1)%3 === 0) ? 'm0' : ''}}"
  92. >
  93. <stack>
  94. <x-book
  95. book="{{$item}}"
  96. read="{{true}}"
  97. isshowtext="{{false}}"
  98. >
  99. <div class="item_wrap">
  100. <text class="name">{{ $item.book_name }}</text>
  101. <text class="last-read"
  102. >读到 {{ $item.chapter_name }}</text
  103. >
  104. </div>
  105. </x-book>
  106. <div
  107. class="book-del__wrap"
  108. show="{{isDelMode}}"
  109. @click="deleteBook($item)"
  110. >
  111. <image
  112. src="../../assets/imgs/delete_recent.png"
  113. ></image>
  114. <text>删除</text>
  115. </div>
  116. </stack>
  117. </div>
  118. </block>
  119. <div
  120. class="book-item__wrap book-item__add m0"
  121. @click="toCategory"
  122. >
  123. <image
  124. class="add-cover"
  125. src="https://yueduyun.oss-cn-hangzhou.aliyuncs.com/xiaochengxu/img/bookstory.png"
  126. ></image>
  127. <text>添加书籍</text>
  128. </div>
  129. </div>
  130. </list-item>
  131. <list-item style="height:120px;"></list-item>
  132. </list>
  133. </block>
  134. </div>
  135. </stack>
  136. </div>
  137. </template>
  138. <script>
  139. import { getUserShelfBooks, deleteShelfBook, getReadrecord } from '../../api'
  140. import router from '@system.router'
  141. export default {
  142. props: {
  143. tabindex: {
  144. type: Number,
  145. default: 0
  146. }
  147. },
  148. data() {
  149. return {
  150. isInit: false,
  151. current: 1,
  152. isinit: false,
  153. isDelMode: false,
  154. modeText: '管理',
  155. mockList: [],
  156. booksize: 0,
  157. typeList: [
  158. {
  159. name: '我的书架',
  160. index: 0
  161. },
  162. {
  163. name: '最近阅读',
  164. index: 1
  165. }
  166. ],
  167. firstBook:{},
  168. isNull: false
  169. }
  170. },
  171. onInit() {
  172. this.getUserShelfBooks();
  173. this.$watch('isDelMode', 'listenMode')
  174. this.$watch('tabindex', 'watchPropsChange')
  175. this.$on('refreshData', this.broadevt);
  176. console.log("this.isInit:",this.isInit);
  177. console.log("this.mocKList:",this.mockList);
  178. },
  179. watchPropsChange(newV, oldV) {
  180. if (newV == 0) {
  181. this.getUserShelfBooks()
  182. }
  183. },
  184. broadevt(evt) {
  185. if (evt.detail.current == 1) {
  186. this.getUserShelfBooks()
  187. }
  188. },
  189. getUserShelfBooks(isDel = false) {
  190. getReadrecord().then(r => {
  191. if (!isDel) {
  192. this.isDelMode = false
  193. }
  194. r.map(m => {
  195. m.cover_url = m.cover
  196. m.recent_cid = m.cid
  197. delete m.cover
  198. delete m.cid
  199. })
  200. this.booksize = r.length
  201. if(this.booksize > 0){
  202. this.firstBook = r[0];
  203. this.firstBook.subtext = this.firstBook.author+"·"+(this.firstBook.status ==0 ? "连载·":"完结·")+(this.firstBook.size < 10000 ? this.firstBook.size : (this.firstBook.size/10000).toFixed(2)+"万");
  204. }else{
  205. this.firstBook = {};
  206. }
  207. this.mockList = r
  208. this.isinit = true
  209. })
  210. },
  211. deleteBook(book) {
  212. deleteShelfBook({ bid: book.book_id }).then(r => {
  213. this.getUserShelfBooks(true);
  214. Object.keys(this.firstBook) === 0 ? this.isNull = true : this.isNull = false;
  215. });
  216. },
  217. changeMode() {
  218. this.isDelMode = !this.isDelMode;
  219. this.getUserShelfBooks(true)
  220. },
  221. listenMode(v) {
  222. this.modeText = v ? '' : '管理'
  223. },
  224. toCategory() {
  225. this.$emit('change')
  226. },
  227. toSearch() {
  228. router.push({
  229. uri: '/views/Search'
  230. })
  231. },
  232. typeChange(index) {
  233. this.current = index
  234. },
  235. toReader(book){
  236. router.push({
  237. uri: '/views/Reader',
  238. params: {
  239. bid: book.book_id,
  240. chapter_id: book.recent_cid
  241. }
  242. })
  243. }
  244. }
  245. </script>
  246. <style lang="less">
  247. @import '../../assets/less/shelf.less';
  248. </style>