feat(web): 试看搜索书籍后返回书架时提示是否加入书架
This commit is contained in:
@@ -7,6 +7,7 @@ export const useBookStore = defineStore("book", {
|
|||||||
connectStatus: "正在连接后端服务器……",
|
connectStatus: "正在连接后端服务器……",
|
||||||
connectType: "",
|
connectType: "",
|
||||||
newConnect: true,
|
newConnect: true,
|
||||||
|
/**@type {Array<{respondTime:number}>} */
|
||||||
searchBooks: [],
|
searchBooks: [],
|
||||||
shelf: [],
|
shelf: [],
|
||||||
catalog: [],
|
catalog: [],
|
||||||
|
|||||||
@@ -492,7 +492,7 @@ onMounted(() => {
|
|||||||
bookAuthor: bookAuthor,
|
bookAuthor: bookAuthor,
|
||||||
bookUrl: bookUrl,
|
bookUrl: bookUrl,
|
||||||
index: chapterIndex,
|
index: chapterIndex,
|
||||||
chapterPos: chapterPos,
|
chapterPos: chapterPos
|
||||||
};
|
};
|
||||||
localStorage.setItem(bookUrl, JSON.stringify(book));
|
localStorage.setItem(bookUrl, JSON.stringify(book));
|
||||||
}
|
}
|
||||||
@@ -532,6 +532,7 @@ onMounted(() => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
window.removeEventListener("keyup", handleKeyPress);
|
window.removeEventListener("keyup", handleKeyPress);
|
||||||
window.removeEventListener("keydown", ignoreKeyPress);
|
window.removeEventListener("keydown", ignoreKeyPress);
|
||||||
@@ -541,6 +542,31 @@ onUnmounted(() => {
|
|||||||
readSettingsVisible.value = false;
|
readSettingsVisible.value = false;
|
||||||
popCataVisible.value = false;
|
popCataVisible.value = false;
|
||||||
scrollObserver?.disconnect();
|
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);
|
||||||
|
})
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -211,18 +211,20 @@ const handleBookClick = async (book) => {
|
|||||||
durChapterPos = 0,
|
durChapterPos = 0,
|
||||||
} = book;
|
} = book;
|
||||||
// 判断是否为 searchBook
|
// 判断是否为 searchBook
|
||||||
if (book.durChapterIndex === undefined) {
|
const isSeachBook = "respondTime" in book
|
||||||
|
if (isSeachBook) {
|
||||||
await API.saveBook(book);
|
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;
|
if (bookName === "尚无阅读记录") return;
|
||||||
sessionStorage.setItem("bookUrl", bookUrl);
|
sessionStorage.setItem("bookUrl", bookUrl);
|
||||||
sessionStorage.setItem("bookName", bookName);
|
sessionStorage.setItem("bookName", bookName);
|
||||||
sessionStorage.setItem("bookAuthor", bookAuthor);
|
sessionStorage.setItem("bookAuthor", bookAuthor);
|
||||||
sessionStorage.setItem("chapterIndex", chapterIndex);
|
sessionStorage.setItem("chapterIndex", chapterIndex);
|
||||||
sessionStorage.setItem("chapterPos", chapterPos);
|
sessionStorage.setItem("chapterPos", chapterPos);
|
||||||
|
sessionStorage.setItem("isSeachBook", isSeachBook);
|
||||||
readingRecent.value = {
|
readingRecent.value = {
|
||||||
name: bookName,
|
name: bookName,
|
||||||
author: bookAuthor,
|
author: bookAuthor,
|
||||||
|
|||||||
Reference in New Issue
Block a user