index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <page-pane>
  3. <div class="stack">
  4. <div class="stack-left">
  5. <sidebar @select="handleSelect" />
  6. </div>
  7. <div class="stack-main">
  8. <el-breadcrumb
  9. class="stack-breadcrumb"
  10. :separator-icon="ArrowRight"
  11. style="width: 100%"
  12. >
  13. <el-breadcrumb-item v-for="item in breadcrumb" :key="item.id">{{
  14. item.name
  15. }}</el-breadcrumb-item>
  16. </el-breadcrumb>
  17. <el-scrollbar
  18. v-loading="loading"
  19. style="flex: 1; width: 100%; height: 0; margin: 18px 0"
  20. >
  21. <ul class="stack-list">
  22. <li v-for="item in list" :key="item.id">
  23. <book-card type="row" size="large" :item="item" />
  24. </li>
  25. </ul>
  26. <el-empty v-if="noData" description="暂无数据" />
  27. </el-scrollbar>
  28. <el-pagination
  29. hide-on-single-page
  30. background
  31. layout="prev, pager, next"
  32. :total="total"
  33. @change="handlePage"
  34. />
  35. </div>
  36. </div>
  37. </page-pane>
  38. </template>
  39. <script setup>
  40. import { ref, watch } from "vue";
  41. import { useRouteQuery } from "@vueuse/router";
  42. import { ArrowRight } from "@element-plus/icons-vue";
  43. import { usePagination } from "@lsq/base";
  44. import { getBookListApi } from "@/api";
  45. import Sidebar from "./components/Sidebar/index.vue";
  46. import BookCard from "@/components/BookCard/index.vue";
  47. const breadcrumb = ref([]);
  48. const activeTab = useRouteQuery("active");
  49. const searchKey = useRouteQuery("keyword");
  50. const { pageNum, total, loading, list, noData, getList } = usePagination(
  51. async (params) => {
  52. const p = {
  53. ...params,
  54. searchKey: searchKey.value,
  55. };
  56. const id = breadcrumb.value[breadcrumb.value.length - 1].id;
  57. if (activeTab.value === "collection" && id > -1) {
  58. p.exhibitTypeId = id;
  59. } else if (id > -1) {
  60. p.storageId = id;
  61. }
  62. return getBookListApi(p);
  63. }
  64. );
  65. const handlePage = (page) => {
  66. pageNum.value = page;
  67. getList();
  68. };
  69. const resetSearch = () => {
  70. pageNum.value = 1;
  71. getList();
  72. };
  73. const handleSelect = (type, data) => {
  74. if (type === "classify") {
  75. // 切换分类
  76. breadcrumb.value = data;
  77. }
  78. resetSearch();
  79. };
  80. watch(breadcrumb, (v) => {
  81. pageNum.value = 1;
  82. v.length && getList();
  83. });
  84. </script>
  85. <style lang="scss" scoped>
  86. @import "./index.scss";
  87. </style>