index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <div v-loading="loading" class="photocopy">
  3. <template v-if="!noData">
  4. <div class="photocopy-left">
  5. <el-image :src="baseUrl + list[curIndex]?.thumb" fit="contain" />
  6. <div class="photocopy-left__prev" @click="handlePrev" />
  7. <div class="photocopy-left__next" @click="handleNext" />
  8. <div class="photocopy-left__magnify" @click="viewerVisible = true" />
  9. <div class="photocopy-left__pagination">
  10. {{ curIndex + 1 }}/{{ total }}
  11. </div>
  12. </div>
  13. <el-scrollbar class="photocopy-right">
  14. <div
  15. v-if="list[curIndex]?.description"
  16. v-html="list[curIndex].description"
  17. />
  18. <div v-else id="reader" />
  19. </el-scrollbar>
  20. </template>
  21. <el-empty v-else description="暂无数据" style="width: 100%" />
  22. </div>
  23. <el-image-viewer
  24. v-if="viewerVisible"
  25. :url-list="list.map((i) => `${baseUrl}${i.thumb}`)"
  26. :initial-index="curIndex"
  27. @close="viewerVisible = false"
  28. />
  29. </template>
  30. <script setup>
  31. import { watch, ref, nextTick, onUnmounted } from "vue";
  32. import { usePagination } from "@lsq/base";
  33. import { useEpubStore } from "@/stores";
  34. import { getMediaListApi } from "@/api";
  35. import { getBaseUrl } from "@/utils";
  36. const props = defineProps(["detail", "isLogin"]);
  37. const curIndex = ref(0);
  38. const viewerVisible = ref(false);
  39. const baseUrl = getBaseUrl();
  40. const epubStore = useEpubStore(window.pinia);
  41. const { total, loading, list, noData, getList } = usePagination(
  42. async (params) => {
  43. return getMediaListApi({
  44. ...params,
  45. pageSize: 999,
  46. bookId: props.detail.id,
  47. type: "img",
  48. });
  49. }
  50. );
  51. const handlePrev = () => {
  52. curIndex.value = Math.max(curIndex.value - 1, 0);
  53. epubStore.prePage();
  54. };
  55. const handleNext = () => {
  56. curIndex.value = Math.min(curIndex.value + 1, list.value.length - 1);
  57. epubStore.nextPage();
  58. };
  59. const handleInit = async () => {
  60. await getList();
  61. nextTick(() => {
  62. epubStore.init({
  63. ghost: true,
  64. url: baseUrl + props.detail.filePath,
  65. });
  66. });
  67. };
  68. watch(
  69. () => props.detail,
  70. () => {
  71. props.detail && handleInit();
  72. },
  73. {
  74. immediate: true,
  75. }
  76. );
  77. onUnmounted(() => {
  78. epubStore.clear();
  79. });
  80. </script>
  81. <style lang="scss" scoped>
  82. @import "./index.scss";
  83. </style>