This commit is contained in:
make
2025-04-22 21:28:08 +08:00
parent cd0cfdeec5
commit c87a377282
10 changed files with 446 additions and 381 deletions

View File

@@ -56,31 +56,38 @@ function incShouCangFun(intId){
}
}
const strBookshelfKey = window.location.hostname + 'strBookshelfKey';
const strHistoryKey = window.location.hostname + 'strHistoryKey';
// 加入书架
function addShujiaFun(NovelInfo){
if (!NovelInfo) {
NovelInfo = arrNovel
}
let arrBookshelf = JSON.parse(localStorage.getItem(strBookshelfKey)) || [];
// 获取当前书架数据
let arrShujia = JSON.parse(localStorage.getItem('shujiakey')) || [];
console.log(arrShujia)
// 检查书籍是否已存在
const exists = arrShujia.some(item => item.xsxq_id === NovelInfo.xsxq_id);
if (exists) {
layerPopup('该书已在书架中!',3)
return;
const index = arrBookshelf.findIndex(item => item.n_id === NovelInfo.n_id);
if (index !== -1) {
// 如果存在,更新该书籍的信息
arrBookshelf[index] = { ...arrBookshelf[index], ...NovelInfo };
layerPopup('已存在书架中!', 3)
} else {
// 如果不存在,添加到历史记录
arrBookshelf.push(NovelInfo);
layerPopup('已成功加入书架!', 3)
}
// 添加到书架
arrShujia.push(NovelInfo);
// 更新本地存储
localStorage.setItem('shujiakey', JSON.stringify(arrShujia));
layerPopup('已成功加入书架!',3)
localStorage.setItem(strBookshelfKey, JSON.stringify(arrBookshelf));
}
function displayShujia() {
// 获取书架数据
const shujia = JSON.parse(localStorage.getItem('shujiakey')) || [];
const shujia = JSON.parse(localStorage.getItem(strBookshelfKey)) || [];
if (shujia.length === 0) {
console.log('书架为空');