|
@@ -23,35 +23,64 @@
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
import { computed, onMounted, ref } from "vue";
|
|
import { computed, onMounted, ref } from "vue";
|
|
|
|
+import { useRoute } from "vue-router";
|
|
|
|
+import { storeToRefs } from "pinia";
|
|
|
|
+import { showLoadingToast } from "vant";
|
|
import NavBar from "@/components/NavBar.vue";
|
|
import NavBar from "@/components/NavBar.vue";
|
|
-import { useEpubStore } from "@/stores";
|
|
|
|
|
|
+import { useEpubStore, useBaseStore, useReaderStore } from "@/stores";
|
|
|
|
+import { getBookDetail2Api, getBookDetailApi, getLabelListApi } from "@/api";
|
|
|
|
+import { getBaseUrl } from "@/utils";
|
|
import { THEMES } from "./constants";
|
|
import { THEMES } from "./constants";
|
|
import ToolbarPopover from "./components/ToolbarPopover.vue";
|
|
import ToolbarPopover from "./components/ToolbarPopover.vue";
|
|
import ToolbarMenu from "./components/ToolbarMenu.vue";
|
|
import ToolbarMenu from "./components/ToolbarMenu.vue";
|
|
|
|
|
|
|
|
+const route = useRoute();
|
|
|
|
+const baseUrl = getBaseUrl();
|
|
const epubStore = useEpubStore();
|
|
const epubStore = useEpubStore();
|
|
|
|
+const baseStore = useBaseStore();
|
|
|
|
+const readerStore = useReaderStore();
|
|
|
|
+const { noteList } = storeToRefs(readerStore);
|
|
|
|
+const { isLogin } = storeToRefs(baseStore);
|
|
const selectedCfi = ref("");
|
|
const selectedCfi = ref("");
|
|
const selectMenuStyle = ref({});
|
|
const selectMenuStyle = ref({});
|
|
|
|
+const detail = ref(null);
|
|
const paneBgColor = computed(
|
|
const paneBgColor = computed(
|
|
() => THEMES.find((theme) => theme.key === epubStore.curTheme).background
|
|
() => THEMES.find((theme) => theme.key === epubStore.curTheme).background
|
|
);
|
|
);
|
|
|
|
|
|
-onMounted(() => {
|
|
|
|
|
|
+const getBookDetail = async () => {
|
|
|
|
+ const data = await (isLogin.value ? getBookDetail2Api : getBookDetailApi)(
|
|
|
|
+ route.params.id
|
|
|
|
+ );
|
|
|
|
+ detail.value = data;
|
|
|
|
+
|
|
|
|
+ initEpub();
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+const initEpub = () => {
|
|
|
|
+ const toast = showLoadingToast({
|
|
|
|
+ duration: 0,
|
|
|
|
+ message: "书本加载中...",
|
|
|
|
+ forbidClick: true,
|
|
|
|
+ });
|
|
|
|
+
|
|
epubStore.init({
|
|
epubStore.init({
|
|
- url: "./test2.epub",
|
|
|
|
|
|
+ url: baseUrl + detail.value.filePath,
|
|
themes: THEMES,
|
|
themes: THEMES,
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ const parentWidth = window.innerWidth;
|
|
epubStore.rendition.hooks.render.register((v) => {
|
|
epubStore.rendition.hooks.render.register((v) => {
|
|
- v.document.addEventListener("click", (e) => {
|
|
|
|
|
|
+ v.document.addEventListener("click", async (e) => {
|
|
// 如果显示冒泡,则不翻页
|
|
// 如果显示冒泡,则不翻页
|
|
if (selectMenuStyle.value.visibility === "visible") return;
|
|
if (selectMenuStyle.value.visibility === "visible") return;
|
|
|
|
|
|
- const offsetX = e.offsetX;
|
|
|
|
- const width = window.innerWidth;
|
|
|
|
|
|
+ const { page } = await epubStore.refreshLocation();
|
|
|
|
+ const clientX = e.clientX;
|
|
|
|
+ const screenX = clientX - page * parentWidth;
|
|
|
|
|
|
- if (offsetX > 0 && offsetX < width * 0.3) epubStore.prePage();
|
|
|
|
- else if (offsetX > 0 && offsetX > width * 0.7) epubStore.nextPage();
|
|
|
|
|
|
+ if (screenX < parentWidth * 0.5) epubStore.prePage();
|
|
|
|
+ else if (screenX > parentWidth * 0.5) epubStore.nextPage();
|
|
});
|
|
});
|
|
|
|
|
|
v.document.body.addEventListener("touchend", (e) => {
|
|
v.document.body.addEventListener("touchend", (e) => {
|
|
@@ -67,7 +96,13 @@ onMounted(() => {
|
|
epubStore.rendition.on("selected", (v) => {
|
|
epubStore.rendition.on("selected", (v) => {
|
|
selectedCfi.value = v;
|
|
selectedCfi.value = v;
|
|
});
|
|
});
|
|
-});
|
|
|
|
|
|
+
|
|
|
|
+ epubStore.rendition.on("rendered", () => {
|
|
|
|
+ toast.close();
|
|
|
|
+
|
|
|
|
+ isLogin.value && getLabelList();
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
|
|
const selected = (e, v) => {
|
|
const selected = (e, v) => {
|
|
const sty = {
|
|
const sty = {
|
|
@@ -100,6 +135,27 @@ const selected = (e, v) => {
|
|
const hideSelectMenu = () => {
|
|
const hideSelectMenu = () => {
|
|
selectMenuStyle.value = { visibility: "hidden" };
|
|
selectMenuStyle.value = { visibility: "hidden" };
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+// 获取笔记列表
|
|
|
|
+const getLabelList = async () => {
|
|
|
|
+ await readerStore.getLabelList(detail.value.id);
|
|
|
|
+
|
|
|
|
+ noteList.value.forEach((item) => {
|
|
|
|
+ epubStore.rendition?.annotations.highlight(
|
|
|
|
+ item.content.cfi,
|
|
|
|
+ {},
|
|
|
|
+ () => {},
|
|
|
|
+ "",
|
|
|
|
+ {
|
|
|
|
+ fill: item.content.color,
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+onMounted(() => {
|
|
|
|
+ getBookDetail();
|
|
|
|
+});
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|