From 797bfd94fdc6f44da3eb28433682ea553ba82e25 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Mon, 30 Sep 2024 20:02:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(web):=20=E8=AF=95=E7=9C=8B=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E4=B9=A6=E7=B1=8D=E5=90=8E=E8=BF=94=E5=9B=9E=E4=B9=A6?= =?UTF-8?q?=E6=9E=B6=E6=97=B6=E6=8F=90=E7=A4=BA=E6=98=AF=E5=90=A6=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E4=B9=A6=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/web/src/store/bookStore.js | 1 + modules/web/src/views/BookChapter.vue | 28 ++++++++++++++++++++++++++- modules/web/src/views/BookShelf.vue | 8 +++++--- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/modules/web/src/store/bookStore.js b/modules/web/src/store/bookStore.js index a801cbd84..1f011d1f6 100644 --- a/modules/web/src/store/bookStore.js +++ b/modules/web/src/store/bookStore.js @@ -7,6 +7,7 @@ export const useBookStore = defineStore("book", { connectStatus: "正在连接后端服务器……", connectType: "", newConnect: true, + /**@type {Array<{respondTime:number}>} */ searchBooks: [], shelf: [], catalog: [], diff --git a/modules/web/src/views/BookChapter.vue b/modules/web/src/views/BookChapter.vue index 5cdd48f9c..31da23a85 100644 --- a/modules/web/src/views/BookChapter.vue +++ b/modules/web/src/views/BookChapter.vue @@ -492,7 +492,7 @@ onMounted(() => { bookAuthor: bookAuthor, bookUrl: bookUrl, index: chapterIndex, - chapterPos: chapterPos, + chapterPos: chapterPos }; localStorage.setItem(bookUrl, JSON.stringify(book)); } @@ -532,6 +532,7 @@ onMounted(() => { ); }); + onUnmounted(() => { window.removeEventListener("keyup", handleKeyPress); window.removeEventListener("keydown", ignoreKeyPress); @@ -541,6 +542,31 @@ onUnmounted(() => { readSettingsVisible.value = false; popCataVisible.value = false; scrollObserver?.disconnect(); + scrollObserver = null; +}); + +onBeforeRouteLeave(async ()=> { + let bookUrl = sessionStorage.getItem("bookUrl"); + let bookName = sessionStorage.getItem("bookName"); + let isSeachBook = sessionStorage.getItem("isSeachBook"); + var book = JSON.parse(localStorage.getItem(bookUrl)); + // 阅读的是搜索的书籍 并未在书架 + if (isSeachBook) { + await ElMessageBox.confirm( + `是否将《${bookName}》放入书架?`, + "放入书架", + { + confirmButtonText: "确认", + cancelButtonText: "否", + type: "info" + } + ).then(() => { + //选择是,无动作 + }).catch(()=>{ + //选择否,删除书籍 + API.deleteBook(book); + }) + } }); diff --git a/modules/web/src/views/BookShelf.vue b/modules/web/src/views/BookShelf.vue index 509a66a73..8b1751d61 100644 --- a/modules/web/src/views/BookShelf.vue +++ b/modules/web/src/views/BookShelf.vue @@ -211,18 +211,20 @@ const handleBookClick = async (book) => { durChapterPos = 0, } = book; // 判断是否为 searchBook - if (book.durChapterIndex === undefined) { + const isSeachBook = "respondTime" in book + if (isSeachBook) { await API.saveBook(book); } - toDetail(bookUrl, name, author, durChapterIndex, durChapterPos); + toDetail(bookUrl, name, author, durChapterIndex, durChapterPos, isSeachBook); }; -const toDetail = (bookUrl, bookName, bookAuthor, chapterIndex, chapterPos) => { +const toDetail = (bookUrl, bookName, bookAuthor, chapterIndex, chapterPos, isSeachBook) => { if (bookName === "尚无阅读记录") return; sessionStorage.setItem("bookUrl", bookUrl); sessionStorage.setItem("bookName", bookName); sessionStorage.setItem("bookAuthor", bookAuthor); sessionStorage.setItem("chapterIndex", chapterIndex); sessionStorage.setItem("chapterPos", chapterPos); + sessionStorage.setItem("isSeachBook", isSeachBook); readingRecent.value = { name: bookName, author: bookAuthor,