index.ux 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <import name="x-book" src="../../components/book/book.ux"></import>
  2. <template>
  3. <div class="detail-wrap">
  4. <div class="book-wrap">
  5. <x-book
  6. multi="{{true}}"
  7. width="{{180}}"
  8. book="{{book}}"
  9. prevent="{{true}}"
  10. >
  11. <div class="book-info">
  12. <text class="name">{{ book.book_name }}</text>
  13. <div class="category">
  14. <text>{{ book.book_category }}</text>
  15. <text class="status">{{
  16. book.book_end_status ? "完结" : "连载"
  17. }}</text>
  18. </div>
  19. <text class="words"
  20. >字数:{{ bookWordsFormat(book.book_word_count) }}</text
  21. >
  22. <div class="user-operator">
  23. <!-- <text class="add" @click="addShelf">{{book.is_on_user_shelf ? '已加入' : '加入书架'}}</text> -->
  24. <text
  25. class="read"
  26. @click="
  27. toRead(
  28. book.record_chapter_id
  29. ? book.record_chapter_id
  30. : book.first_cid
  31. )
  32. "
  33. >立即阅读</text
  34. >
  35. </div>
  36. </div>
  37. </x-book>
  38. <stack class="book-intro">
  39. <text class="short-info__text">{{ substrInfoText() }}</text>
  40. <div class="intro-div">
  41. <text class="toggle" @click="toggleTextStatus">{{
  42. showLongText ? "收起" : "展开"
  43. }}</text>
  44. </div>
  45. </stack>
  46. </div>
  47. <text
  48. class="lastest-chapter"
  49. @click="toRead(book.last_cid, book.is_need_charge)"
  50. >最新章节:{{ book.last_chapter }}</text
  51. >
  52. <div class="box-wrap short-chapter__list">
  53. <div class="small-title">
  54. <div class="wrap-left">
  55. <!-- <text class="border-left"></text> -->
  56. <text class="title">目录</text>
  57. <text class="total">共{{ book.book_chapter_total }}章</text>
  58. </div>
  59. <text class="wrap-right">{{ book.update_time }}</text>
  60. </div>
  61. <div class="chapter-list">
  62. <block for="chapters">
  63. <text
  64. class="chapter-item"
  65. @click="toRead($item.chapter_id, $item.is_need_charge)"
  66. >{{ $item.chapter_name }}</text
  67. >
  68. </block>
  69. </div>
  70. <text class="more-chapters" @click="toBookCatalog">更多目录 &gt;</text>
  71. </div>
  72. <div class="box-wrap similar-list__wrap">
  73. <div class="small-title">
  74. <div class="wrap-left">
  75. <!-- <text class="border-left"></text> -->
  76. <text class="title">同款推荐</text>
  77. </div>
  78. </div>
  79. <div class="similar-wrap">
  80. <block for="similar">
  81. <x-book similar="{{true}}" book="{{$item}}"></x-book>
  82. </block>
  83. </div>
  84. </div>
  85. </div>
  86. </template>
  87. <script>
  88. import { getBooksInfo, getShortCatalog, getSimilarBooks, postUserShelfBooks } from "../../api";
  89. import router from '@system.router';
  90. import prompt from '@system.prompt';
  91. import storage from "@system.storage";
  92. export default {
  93. public: {
  94. push_id: '',
  95. bid: " "
  96. },
  97. private: {
  98. showLongText: false,
  99. book: {},
  100. chapters: [],
  101. similar: []
  102. },
  103. substrInfoText() {
  104. if (this.book.book_summary) {
  105. return this.showLongText ? this.book.book_summary : this.book.book_summary.slice(0, 110);
  106. } else return "";
  107. },
  108. toggleTextStatus() {
  109. this.showLongText = !this.showLongText;
  110. this.substrInfoText();
  111. },
  112. async addShelf() {
  113. if (!this.book.is_on_user_shelf) {
  114. let ret = await postUserShelfBooks({ bid: this.bid });
  115. if (ret) this.book.is_on_user_shelf = 1, prompt.showToast({ message: "添加成功" });
  116. }
  117. },
  118. toRead(cid = "", needCharge = 0) {
  119. console.log(cid)
  120. if (needCharge == 1) {
  121. this.chapter_sequence = needCharge
  122. router.push({
  123. uri: "/views/Pay",
  124. params: {
  125. bid: this.book.book_id,
  126. }
  127. })
  128. return false;
  129. }
  130. let chapter_id = cid;
  131. router.push({
  132. uri: "/views/Reader",
  133. params: {
  134. bid: this.book.book_id,
  135. chapter_id: chapter_id,
  136. }
  137. })
  138. },
  139. toBookCatalog() {
  140. router.push({
  141. uri: "/views/Catalog",
  142. params: {
  143. bid: this.book.book_id
  144. }
  145. })
  146. },
  147. bookWordsFormat(words) {
  148. if (words > 10000) return (words / 10000).toFixed(2) + "万字";
  149. else return words + "字";
  150. },
  151. async getBooksInfo(bid) {
  152. this.book = await getBooksInfo(bid);
  153. this.chapters = await getShortCatalog(bid);
  154. this.similar = await getSimilarBooks(this.book.book_category_id, bid);
  155. },
  156. onShow() {
  157. console.log("book bid", this.bid);
  158. this.getBooksInfo(this.bid);
  159. },
  160. async onInit() {
  161. console.log("book bid", this.bid);
  162. // this.getBooksInfo(this.bid);
  163. if (this.push_id) {
  164. await storage.set({ key: "push_id", value: this.push_id });
  165. }
  166. },
  167. }
  168. </script>
  169. <style lang="less">
  170. @import "../../assets/less/detail.less";
  171. </style>