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,32 +150,39 @@ function incShouCangFun(intId){
}
}
const strBookshelfKey = window.location.hostname + 'strBookshelfKey';
// 加入书架
function addShujiaFun(NovelInfo){
function addBookshelfFun(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));
localStorage.setItem(strBookshelfKey, JSON.stringify(arrBookshelf));
layerPopup('已成功加入书架!',3)
}
function displayShujia() {
// 获取书架数据
const shujia = JSON.parse(localStorage.getItem('shujiakey')) || [];
const shujia = JSON.parse(localStorage.getItem(strBookshelfKey)) || [];
if (shujia.length === 0) {
console.log('书架为空');