index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <page-pane
  3. v-loading.fullscreen.lock="loading"
  4. class="detail"
  5. :container-color="paneBgColor"
  6. :simple="isPhotocopy"
  7. >
  8. <component v-if="detail" :is="comp" :is-login="isLogin" :detail="detail" />
  9. </page-pane>
  10. <toolbar v-if="route.params.type === 'reader'" />
  11. <introduction-dialog v-model:visible="introductionVisible" :detail="detail" />
  12. </template>
  13. <script setup>
  14. import { computed, ref, watch, onUnmounted } from "vue";
  15. import { useRoute, useRouter } from "vue-router";
  16. import { THEMES } from "@lsq/base";
  17. import { getBookDetailApi, getBookDetail2Api } from "@/api";
  18. import { storeToRefs } from "pinia";
  19. import { useEpubStore, useDetailStore, useBaseStore } from "@/stores";
  20. import Toolbar from "./components/Toolbar/index.vue";
  21. import Reader from "./components/Reader/index.vue";
  22. import Photocopy from "./components/Photocopy/index.vue";
  23. import DetailVideo from "./components/Video/index.vue";
  24. import IntroductionDialog from "./components/IntroductionDialog.vue";
  25. const route = useRoute();
  26. const router = useRouter();
  27. const baseStore = useBaseStore();
  28. const epubStore = useEpubStore(window.pinia);
  29. const detailStore = useDetailStore();
  30. const { isLogin } = storeToRefs(baseStore);
  31. const { introductionVisible, detail } = storeToRefs(detailStore);
  32. const loading = ref(false);
  33. const paneBgColor = computed(
  34. () => THEMES.find((theme) => theme.key === epubStore.curTheme).color
  35. );
  36. const isPhotocopy = computed(() => route.params.type === "photocopy");
  37. const comp = computed(() => {
  38. switch (route.params.type) {
  39. case "photocopy":
  40. return Photocopy;
  41. case "video":
  42. return DetailVideo;
  43. default:
  44. return Reader;
  45. }
  46. });
  47. const getBookDetail = async () => {
  48. try {
  49. loading.value = true;
  50. const data = await (isLogin.value ? getBookDetail2Api : getBookDetailApi)(
  51. route.params.id
  52. );
  53. if (!data) {
  54. ElMessage.warning("图书丢失了");
  55. router.replace({ name: "home" });
  56. return;
  57. }
  58. detail.value = data;
  59. } finally {
  60. loading.value = false;
  61. }
  62. };
  63. watch(
  64. isLogin,
  65. () => {
  66. getBookDetail();
  67. },
  68. {
  69. immediate: true,
  70. }
  71. );
  72. onUnmounted(() => {
  73. detailStore.clear();
  74. });
  75. </script>
  76. <style lang="scss" scoped>
  77. @import "./index.scss";
  78. </style>