bookshelf.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="bookshelf-content">
  3. <view style="position: fixed; z-index: 10; width: 100%; ">
  4. <z-tabs ref="tabs"
  5. :tabs-style="{height:tab_height + 'rpx'}"
  6. bg-color="#F8F8F8"
  7. bar-height="0"
  8. :active-color="config.theme_color"
  9. :active-style="{'font-size': '80rpx', 'font-weight': '500'}"
  10. inactive-color="#3D3D3D"
  11. :inactive-style="{'font-size': '40rpx', 'font-weight': '400'}"
  12. scroll-count="1"
  13. :bottomLineIsShow="false"
  14. :list="tab_list"
  15. :current="tab_current"
  16. @change="tabsChange" />
  17. </view>
  18. <view :style="{marginTop: tab_height + 'rpx'}">
  19. <bookList :class="tab_current==0?'style_show':'style_hide'" :book_list='data_book_list' @clickBook='gotoReadBook'></bookList>
  20. <readHistory :class="tab_current==1?'style_show':'style_hide'" :book_list='data_read_history_list' @clickBook='gotoReadBook' @clickDeleteBook='readHistoryClickDeleteBook'></readHistory>
  21. </view>
  22. </view>
  23. </template>
  24. <script setup lang="ts">
  25. import { config } from '../../config/config';
  26. import { book_item_data } from '../../data/data';
  27. import { ref } from 'vue';
  28. import { tools } from '../../framework/tools';
  29. import bookList from '../bookshelf/bookshelf-bookList.vue'
  30. import readHistory from '../bookshelf/bookshelf-readHistory.vue'
  31. import { ReadRecord } from '../../stores/readRecordManager';
  32. let tab_height = ref(100)
  33. let tab_list = ref(['书架','阅读历史'])
  34. let tab_current = ref(0) //0:书架 1:阅读历史
  35. let data_book_list = ref<Array<book_item_data>>([])
  36. let data_read_history_list = ref<Array<book_item_data>>([])
  37. initData()
  38. initEvent()
  39. function initData() {
  40. uni.setNavigationBarTitle({
  41. title:config.app_name
  42. })
  43. data_book_list.value = tools.getLocalBookshelfList()
  44. data_read_history_list.value = tools.getLocalReadHistoryList()
  45. }
  46. function requestBookshelfData() {
  47. let local_book_list = []
  48. let request_book_shelf_list = []
  49. for (let i = 0; i < tools.getLocalBookshelfList().length; i++) {
  50. let element = tools.getLocalBookshelfList()[i]
  51. let read_record_data = ReadRecord().getReadRecordData(element.book_id)
  52. if(read_record_data) {
  53. element.start_read_chapter_id = read_record_data.chapter_id
  54. } else {
  55. element.start_read_chapter_id = 1
  56. }
  57. local_book_list.push(element)
  58. let book_opt = tools.getRequestBookshelfParameter(element)
  59. request_book_shelf_list.push(book_opt)
  60. }
  61. data_book_list.value = local_book_list
  62. tools.requestBookShelf(request_book_shelf_list,1,(data:book_item_data[])=>{
  63. // console.log('请求书架data=',data)
  64. data_book_list.value = []
  65. for (let i = 0; i < data.length; i++) {
  66. let element = data[i]
  67. data_book_list.value.push(element)
  68. }
  69. tools.saveLocalBookshelfList()
  70. },()=>{
  71. data_book_list.value = local_book_list
  72. })
  73. }
  74. function initEvent() {
  75. uni.$on(config.EVENT_TYPE.USER_LOGIN_SUCCESS, ()=>{
  76. requestBookshelfData()
  77. })
  78. uni.$on(config.EVENT_TYPE.UPDATE_BOOKSHELF,()=>{
  79. data_book_list.value = []
  80. setTimeout(()=>{
  81. data_book_list.value = tools.getLocalBookshelfList()
  82. },50)
  83. })
  84. uni.$on(config.EVENT_TYPE.UPDATE_READHISTORY,()=>{
  85. // console.log('tools.getLocalReadHistoryList()=',tools.getLocalReadHistoryList())
  86. data_read_history_list.value = []
  87. setTimeout(()=>{
  88. data_read_history_list.value = tools.getLocalReadHistoryList()
  89. },50)
  90. })
  91. }
  92. function tabsChange(index:number) {
  93. tab_current.value = index
  94. }
  95. function readHistoryClickDeleteBook() {
  96. data_read_history_list.value = []
  97. tools.resetSortReadHistory(data_read_history_list.value)
  98. }
  99. function gotoReadBook(book_data:book_item_data, index:number) {
  100. // console.log('book_data=',book_data,'index=',index)
  101. tools.gotoRead(book_data)
  102. if(tab_current.value==0) {
  103. // 书架
  104. if(index>0) {
  105. data_book_list.value.splice(index,1)
  106. data_book_list.value.unshift(book_data)
  107. tools.resetSortBookshelf(data_book_list.value)
  108. uni.pageScrollTo({ scrollTop:0 })
  109. }
  110. } else {
  111. //阅读历史
  112. if(index>0) {
  113. data_read_history_list.value.splice(index,1)
  114. data_read_history_list.value.unshift(book_data)
  115. uni.pageScrollTo({ scrollTop:0 })
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="scss">
  121. .bookshelf-content{
  122. display: flex;
  123. flex-direction: column;
  124. }
  125. .style_show{
  126. display: flex;
  127. }
  128. .style_hide{
  129. display: none;
  130. }
  131. </style>