index.ux 4.5 KB

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