bookshelf.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <view class="bookshelf-content">
  3. <view class="bookshelf-content__top" :style="{height:top_height+'px'}">
  4. <view class="bookshelf-content__top__bg">
  5. <image class="image" src="../../static/imgs/public/img_top_bg_1.png"></image>
  6. </view>
  7. <view :style="{marginTop: safeArea_top+'px'}">
  8. <z-tabs
  9. ref="tabs"
  10. :tabs-style="{height:tab_height + 'px'}"
  11. bg-color="transparent"
  12. bar-height="0"
  13. active-color="#FF8EBB"
  14. :active-style="{'font-size': '60rpx', 'font-weight': '500'}"
  15. inactive-color="#3D3D3D"
  16. :inactive-style="{'font-size': '30rpx', 'font-weight': '500'}"
  17. scroll-count="1"
  18. :bottomLineIsShow="false"
  19. :list="tab_list"
  20. :current="tab_current"
  21. @change="tabsChange" />
  22. </view>
  23. </view>
  24. <view :style="{marginTop: top_height + 'px'}">
  25. <bookList :class="tab_current==0?'style_show':'style_hide'"
  26. :book_list='data_book_list'
  27. @clickBook='gotoReadBook'
  28. @clickEdit='clickEdit'
  29. @clickButtonStatus='bookListClickButtonStatus'
  30. @clickDeleteBook='bookListClickDeleteBook'></bookList>
  31. <readHistory :class="tab_current==1?'style_show':'style_hide'"
  32. :book_list='data_read_history_list'
  33. @clickBook='gotoReadBook'
  34. @clickEdit='clickEdit'
  35. @clickButtonStatus='readHistoryClickButtonStatus'
  36. @clickDeleteBook='readHistoryClickDeleteBook'></readHistory>
  37. </view>
  38. </view>
  39. </template>
  40. <script setup lang="ts">
  41. import { config } from '../../config/config';
  42. import { book_item_data } from '../../data/data';
  43. import { ref } from 'vue';
  44. import { tools } from '../../framework/tools';
  45. import bookList from '../bookshelf/bookshelf-bookList.vue'
  46. import readHistory from '../bookshelf/bookshelf-readHistory.vue'
  47. import { ReadRecord } from '../../stores/readRecordManager';
  48. import { util } from '../../framework/util';
  49. let tab_height = ref(50)
  50. let tab_list = ref(['书架','阅读历史'])
  51. let tab_current = ref(0) //0:书架 1:阅读历史
  52. let safeArea_top = ref(0)
  53. let top_height = ref(0)
  54. if(tools.platform == config.Platform.WEIXIN) {
  55. safeArea_top.value = uni.getSystemInfoSync().safeArea.top
  56. }
  57. top_height.value = safeArea_top.value + tab_height.value
  58. let data_book_list = ref<Array<book_item_data>>([])
  59. let data_read_history_list = ref<Array<book_item_data>>([])
  60. let booksheflf_type_status = ref(config.book_action_status.QUAN_BU)
  61. let read_history_type_status = ref(config.book_action_status.QUAN_BU)
  62. let is_edit_status = ref(false)
  63. initData()
  64. initEvent()
  65. function initData() {
  66. uni.setNavigationBarTitle({
  67. title:config.app_name
  68. })
  69. data_book_list.value = tools.getLocalBookshelfList()
  70. data_read_history_list.value = tools.getLocalReadHistoryList()
  71. }
  72. function requestBookshelfData() {
  73. let local_book_list = []
  74. let request_book_shelf_list = []
  75. for (let i = 0; i < tools.getLocalBookshelfList().length; i++) {
  76. let element = tools.getLocalBookshelfList()[i]
  77. // let read_record_data = ReadRecord().getReadRecordData(element.book_id)
  78. // if(read_record_data) {
  79. // element.start_read_chapter_id = read_record_data.chapter_id
  80. // } else {
  81. // element.start_read_chapter_id = 1
  82. // }
  83. local_book_list.push(element)
  84. let book_opt = tools.getRequestBookshelfParameter(element)
  85. request_book_shelf_list.push(book_opt)
  86. }
  87. tools.requestBookShelf(request_book_shelf_list,1,(data:book_item_data[])=>{
  88. // console.log('请求书架data=',data)
  89. data_book_list.value = []
  90. for (let i = 0; i < data.length; i++) {
  91. let element = data[i]
  92. data_book_list.value.push(element)
  93. }
  94. tools.resetSortBookshelf(data_book_list.value)
  95. },()=>{
  96. data_book_list.value = local_book_list
  97. })
  98. }
  99. function initEvent() {
  100. uni.$on(config.EVENT_TYPE.USER_LOGIN_SUCCESS, ()=>{
  101. requestBookshelfData()
  102. })
  103. uni.$on(config.EVENT_TYPE.UPDATE_BOOKSHELF,()=>{
  104. // 安卓不支持....
  105. // data_book_list.value = []
  106. // setTimeout(()=>{ data_book_list.value = tools.getLocalBookshelfList()},500)
  107. data_book_list.value = []
  108. for (let i = 0; i < tools.getLocalBookshelfList().length; i++) {
  109. let element = tools.getLocalBookshelfList()[i]
  110. if(booksheflf_type_status.value==config.book_action_status.QUAN_BU) {
  111. data_book_list.value.push(element)
  112. } else {
  113. if(booksheflf_type_status.value==element.book_is_action) {
  114. data_book_list.value.push(element)
  115. }
  116. }
  117. }
  118. })
  119. uni.$on(config.EVENT_TYPE.UPDATE_READHISTORY,()=>{
  120. // console.log('tools.getLocalReadHistoryList()=',tools.getLocalReadHistoryList())
  121. // 安卓不支持....
  122. // data_read_history_list.value = []
  123. // setTimeout(()=>{ data_read_history_list.value = tools.getLocalReadHistoryList()},50)
  124. data_read_history_list.value = []
  125. for (let i = 0; i < tools.getLocalReadHistoryList().length; i++) {
  126. let element = tools.getLocalReadHistoryList()[i]
  127. // data_read_history_list.value.push(element)
  128. if(read_history_type_status.value==config.book_action_status.QUAN_BU) {
  129. data_read_history_list.value.push(element)
  130. } else {
  131. if(read_history_type_status.value==element.book_is_action) {
  132. data_read_history_list.value.push(element)
  133. }
  134. }
  135. }
  136. })
  137. uni.$on(config.EVENT_TYPE.UPDATE_BOOKSHELF_CURRENT_READ_CHAPTER,(book_data:book_item_data)=>{
  138. for (let i = 0; i < data_book_list.value.length; i++) {
  139. let element = data_book_list.value[i]
  140. if(element.book_id==book_data.book_id) {
  141. if(element.start_read_chapter_id!=book_data.start_read_chapter_id) {
  142. element.start_read_chapter_id = book_data.start_read_chapter_id
  143. }
  144. break
  145. }
  146. }
  147. for (let i = 0; i < data_read_history_list.value.length; i++) {
  148. let element = data_read_history_list.value[i]
  149. if(element.book_id==book_data.book_id) {
  150. if(element.start_read_chapter_id!=book_data.start_read_chapter_id) {
  151. element.start_read_chapter_id = book_data.start_read_chapter_id
  152. }
  153. break
  154. }
  155. }
  156. })
  157. }
  158. function tabsChange(index:number) {
  159. tab_current.value = index
  160. }
  161. function clickEdit(is_edit:boolean) {
  162. is_edit_status.value = is_edit
  163. }
  164. function changeButtonStatusTips(status:number) {
  165. // console.log('button status=',status)
  166. let status_string = ''
  167. switch (status){
  168. case config.book_action_status.QUAN_BU:
  169. status_string = '全部'
  170. break;
  171. case config.book_action_status.LIAN_ZAI:
  172. status_string = '连载'
  173. break;
  174. case config.book_action_status.WAN_JIE:
  175. status_string = '完结'
  176. break;
  177. default:
  178. break;
  179. }
  180. if(status_string.length>0) {
  181. util.showInfoToast(status_string)
  182. }
  183. }
  184. function bookListClickButtonStatus(status:number) {
  185. booksheflf_type_status.value = status
  186. changeButtonStatusTips(status)
  187. data_book_list.value = []
  188. if(status==config.book_action_status.QUAN_BU) {
  189. data_book_list.value = tools.getLocalBookshelfList()
  190. return
  191. }
  192. let temp_list:book_item_data[] = []
  193. for (let i = 0; i < tools.getLocalBookshelfList().length; i++) {
  194. let element = tools.getLocalBookshelfList()[i]
  195. if(element.book_is_action == status) {
  196. temp_list.push(element)
  197. }
  198. }
  199. if(temp_list.length>0) {
  200. data_book_list.value = temp_list
  201. }
  202. }
  203. function bookListClickDeleteBook() {
  204. data_book_list.value = tools.getLocalBookshelfList()
  205. }
  206. function readHistoryClickButtonStatus(status:number) {
  207. read_history_type_status.value = status
  208. changeButtonStatusTips(status)
  209. data_read_history_list.value = []
  210. if(status==config.book_action_status.QUAN_BU) {
  211. data_read_history_list.value = tools.getLocalReadHistoryList()
  212. return
  213. }
  214. let temp_list:book_item_data[] = []
  215. for (let i = 0; i < tools.getLocalReadHistoryList().length; i++) {
  216. let element = tools.getLocalReadHistoryList()[i]
  217. if(element.book_is_action == status) {
  218. temp_list.push(element)
  219. }
  220. }
  221. if(temp_list.length>0) {
  222. data_read_history_list.value = temp_list
  223. }
  224. }
  225. function readHistoryClickDeleteBook() {
  226. data_read_history_list.value = tools.getLocalReadHistoryList()
  227. }
  228. function gotoReadBook(book_data:book_item_data, index:number) {
  229. // console.log('book_data=',book_data,'index=',index)
  230. return tools.gotoBookdetails(book_data.book_id,book_data.wx_book_id)
  231. // tools.gotoRead(book_data)
  232. // if(tab_current.value==0) {
  233. // // 书架
  234. // if(index>0) {
  235. // data_book_list.value.splice(index,1)
  236. // data_book_list.value.unshift(book_data)
  237. // tools.resetSortBookshelf(data_book_list.value)
  238. // uni.pageScrollTo({ scrollTop:0 })
  239. // }
  240. // } else {
  241. // //阅读历史
  242. // if(index>0) {
  243. // data_read_history_list.value.splice(index,1)
  244. // data_read_history_list.value.unshift(book_data)
  245. // uni.pageScrollTo({ scrollTop:0 })
  246. // }
  247. // }
  248. tools.gotoRead(book_data)
  249. if(tab_current.value==0) {
  250. // 书架
  251. if(index>0) {
  252. data_book_list.value.splice(index,1)
  253. data_book_list.value.unshift(book_data)
  254. tools.resetSortBookshelf(data_book_list.value)
  255. uni.pageScrollTo({ scrollTop:0 })
  256. }
  257. } else {
  258. //阅读历史
  259. if(index>0) {
  260. uni.pageScrollTo({ scrollTop:0 })
  261. }
  262. }
  263. }
  264. </script>
  265. <style lang="scss">
  266. .bookshelf-content{
  267. display: flex;
  268. flex-direction: column;
  269. &__top{
  270. position: fixed;
  271. z-index: 9;
  272. top: 0;
  273. width: 100%;
  274. &__bg{
  275. position: absolute;
  276. flex-shrink: 0;
  277. width:100%;
  278. height: 100%;
  279. .image{
  280. width: 100%;
  281. height: 100%;
  282. }
  283. }
  284. }
  285. }
  286. .style_show{
  287. display: flex;
  288. }
  289. .style_hide{
  290. display: none;
  291. }
  292. </style>