index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <svg-icon
  3. class="stack__search"
  4. name="icon_search"
  5. width="24px"
  6. height="24px"
  7. color="var(--van-primary-color)"
  8. @click="$router.push({ name: 'search' })"
  9. />
  10. <van-tabs v-model:active="activeTab" swipeable shrink class="stack">
  11. <template #nav-bottom>
  12. <classify-scroll
  13. :active-tab="activeTab"
  14. :storage-init-val="storageId"
  15. :exhibit-init-val="exhibitId"
  16. @storageId="handleStorage"
  17. @exhibitId="handleExhibit"
  18. @tab-change="handleChange"
  19. />
  20. </template>
  21. <van-tab title="按书籍分类">
  22. <RecycleScroller
  23. class="stack-scroller"
  24. :items="bookList"
  25. :item-size="167 + 24"
  26. @scroll-end="handleBookEnd"
  27. >
  28. <template v-slot="{ item }">
  29. <BookCard2 :item="item" />
  30. </template>
  31. <template v-if="bookNoData" #empty>
  32. <van-empty description="暂无数据" />
  33. </template>
  34. <template v-if="bookLoading" #after>
  35. <van-loading style="text-align: center" />
  36. </template>
  37. </RecycleScroller>
  38. </van-tab>
  39. <van-tab title="按藏品分类">
  40. <RecycleScroller
  41. class="stack-scroller"
  42. :items="exhibitList"
  43. :item-size="167 + 24"
  44. @scroll-end="handleExhibitEnd"
  45. >
  46. <template v-slot="{ item }">
  47. <BookCard2 :item="item" />
  48. </template>
  49. <template v-if="exhibitNoData" #empty>
  50. <van-empty description="暂无数据" />
  51. </template>
  52. <template v-if="exhibitLoading" #after>
  53. <van-loading style="text-align: center" />
  54. </template>
  55. </RecycleScroller>
  56. </van-tab>
  57. </van-tabs>
  58. </template>
  59. <script setup>
  60. import { usePagination, PaginationType } from "@lsq/base";
  61. import { useRouteQuery } from "@vueuse/router";
  62. import { getBookListApi, getStorageSonListApi } from "@/api";
  63. import { RecycleScroller } from "vue-virtual-scroller";
  64. import BookCard2 from "@/components/BookCard2.vue";
  65. import ClassifyScroll from "./components/ClassifyScroll.vue";
  66. const activeTab = useRouteQuery("active", 0, { transform: Number });
  67. const storageId = useRouteQuery("storage", 0, { transform: Number });
  68. const exhibitId = useRouteQuery("exhibit", 0, { transform: Number });
  69. const {
  70. loading: bookLoading,
  71. list: bookList,
  72. noData: bookNoData,
  73. noMore: bookNoMore,
  74. pageNum: bookPage,
  75. getList: getBookList,
  76. resetParams: resetBookParams,
  77. } = usePagination(async (params) => {
  78. // 查找书籍分类指定分类
  79. if (storageId.value) {
  80. const data = await getStorageSonListApi(storageId.value);
  81. // 模拟分页
  82. return {
  83. pages: 1,
  84. total: data.length,
  85. records: data.slice(
  86. (params.pageNum - 1) * params.pageSize,
  87. params.pageNum * params.pageSize
  88. ),
  89. };
  90. }
  91. return getBookListApi({
  92. ...params,
  93. storageId: storageId.value || null,
  94. });
  95. }, PaginationType.CONCAT);
  96. const {
  97. loading: exhibitLoading,
  98. list: exhibitList,
  99. noData: exhibitNoData,
  100. noMore: exhibitNoMore,
  101. pageNum: exhibitPage,
  102. getList: getExhibitList,
  103. resetParams: resetExhibitParams,
  104. } = usePagination(async (params) => {
  105. return getBookListApi({
  106. ...params,
  107. exhibitTypeId: exhibitId.value || null,
  108. });
  109. }, PaginationType.CONCAT);
  110. const handleStorage = (id) => {
  111. if (id === storageId.value) return;
  112. storageId.value = id;
  113. resetBookParams();
  114. getBookList();
  115. };
  116. const handleBookEnd = () => {
  117. if (!bookNoMore.value && !bookLoading.value) {
  118. bookPage.value++;
  119. getBookList();
  120. }
  121. };
  122. const handleExhibit = (id) => {
  123. if (id === exhibitId.value) return;
  124. exhibitId.value = id;
  125. resetExhibitParams();
  126. getExhibitList();
  127. };
  128. const handleExhibitEnd = () => {
  129. if (!exhibitNoMore.value && !exhibitLoading.value) {
  130. exhibitPage.value++;
  131. getExhibitList();
  132. }
  133. };
  134. const handleChange = () => {
  135. if (activeTab.value === 0) {
  136. // 按书籍分类
  137. !bookList.value.length && getBookList();
  138. } else {
  139. // 按藏品分类
  140. !exhibitList.value.length && getExhibitList();
  141. }
  142. };
  143. </script>
  144. <style lang="scss">
  145. @import "./index.scss";
  146. </style>