This commit is contained in:
make
2025-04-17 17:28:17 +08:00
parent 3212819051
commit 76010ff43b
29 changed files with 673 additions and 953 deletions

View File

@@ -150,6 +150,8 @@ function incShouCangFun(intId) {
}
}
const strBookshelfKey = window.location.hostname + 'strBookshelfKey';
// 加入书架 addShuJiaFun
function addBookshelfFun(NovelInfo) {
@@ -157,8 +159,8 @@ function addBookshelfFun(NovelInfo) {
NovelInfo = arrNovel
}
let arrBookshelf = JSON.parse(localStorage.getItem('strBookshelfKey')) || [];
console.log(arrBookshelf)
let arrBookshelf = JSON.parse(localStorage.getItem(strBookshelfKey)) || [];
// 检查书籍是否已存在
const index = arrBookshelf.findIndex(item => item.n_id === NovelInfo.n_id);
@@ -173,15 +175,14 @@ function addBookshelfFun(NovelInfo) {
}
// 更新本地存储
localStorage.setItem('strBookshelfKey', JSON.stringify(arrBookshelf));
localStorage.setItem(strBookshelfKey, JSON.stringify(arrBookshelf));
}
// 删除书架
function delBookshelfFun(intNId) {
// 获取书架数据
const arrHistory = JSON.parse(localStorage.getItem('strBookshelfKey')) || [];
console.log(arrHistory)
const arrHistory = JSON.parse(localStorage.getItem(strBookshelfKey)) || [];
// 检查 arrHistory 是否为数组且不为空
if (Array.isArray(arrHistory) && arrHistory.length > 0) {
@@ -208,7 +209,7 @@ function delBookshelfFun(intNId) {
function displayBookshelf() {
// 获取书架数据
const arrBookshelf = JSON.parse(localStorage.getItem('strBookshelfKey')) || [];
const arrBookshelf = JSON.parse(localStorage.getItem(strBookshelfKey)) || [];
if (arrBookshelf.length === 0) {
console.log('书架为空');