This commit is contained in:
make
2025-04-06 01:15:48 +08:00
parent 9945b6b137
commit 57fad274d2
31 changed files with 622 additions and 362 deletions

View File

@@ -322,6 +322,7 @@ display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;}
/*列表*/
.result{background: #fff; width: 1100px; overflow: hidden;}
.search_tip{text-align: center;}
.result ul{overflow: hidden;}
.result ul li{padding: 30px 42px; border-bottom: 1px solid #f0f0f0; overflow: hidden;}
.result ul li .book_cov{width: 120px; height: 150px; float: left;}

View File

@@ -165,8 +165,6 @@ $(function () {
var mod_desc = $('#book_desc');
var height = mod_desc.height();
var min_height = 54, max_height = 180;
console.log(height)
console.log(min_height)
if (height > min_height) {
mod_desc.css({height: min_height + 'px'}).next().show().on('click', function () {
$(this).hide().next().show().end().prev().animate({height: (height < max_height ? max_height : height) + 'px'}, 200);
@@ -179,8 +177,6 @@ $(function () {
var mod_desc2 = $('#book_desc2');
var height2 = mod_desc2.height();
var min_height2 = 54, max_height2 = 180;
console.log(height2)
console.log(min_height2)
if (height2 > min_height2) {
mod_desc2.css({height: min_height2 + 'px'}).next().show().on('click', function () {
$(this).hide().next().show().end().prev().animate({height: (height2 < max_height2 ? max_height2 : height2) + 'px'}, 200);

View File

@@ -126,26 +126,55 @@ function incShouCangFun(intId) {
function addBookshelfFun(NovelInfo) {
if (!NovelInfo) {
layerPopup('操作失败!', 3)
return;
NovelInfo = JSON.parse(arrNovel)
NovelInfo['c_sort_num'] = strChapterSort;
NovelInfo['c_name'] = strChapterName;
}
let arrBookshelf = JSON.parse(localStorage.getItem('strBookshelfKey')) || [];
console.log(arrBookshelf)
// 检查书籍是否已存在
const exists = arrBookshelf.some(item => item.xsxq_id === NovelInfo.xsxq_id);
if (exists) {
layerPopup('该书已在书架中!', 3)
return;
}
const index = arrBookshelf.findIndex(item => item.n_id === NovelInfo.n_id);
// 添加到书架
arrBookshelf.push(NovelInfo);
if (index !== -1) {
// 如果存在,更新该书籍的信息
arrBookshelf[index] = { ...arrBookshelf[index], ...NovelInfo };
layerPopup('已存在书架中!', 3)
} else {
// 如果不存在,添加到历史记录
arrBookshelf.push(NovelInfo);
layerPopup('已成功加入书架!', 3)
}
// 更新本地存储
localStorage.setItem('strBookshelfKey', JSON.stringify(arrBookshelf));
layerPopup('已成功加入书架!', 3)
}
// 删除历史记录
function delBookshelfFun(intNId) {
// 获取书架数据
const arrHistory = JSON.parse(localStorage.getItem('strBookshelfKey')) || [];
// 检查 arrHistory 是否为数组且不为空
if (Array.isArray(arrHistory) && arrHistory.length > 0) {
// 找到匹配 intNId 的索引
const index = arrHistory.findIndex(item => item.n_id === intNId);
// 如果找到匹配项index !== -1则删除
if (index !== -1) {
arrHistory.splice(index, 1); // 删除该项
// 更新 localStorage
localStorage.setItem('strBookshelfKey', JSON.stringify(arrHistory));
} else {
console.log(`未找到 ID 为 ${intNId} 的记录`);
}
} else {
console.log('为空,无需删除');
}
removeElementsByClass('book-shelf')
displayBookshelf()
}
// 展示 书架
@@ -160,74 +189,118 @@ function displayBookshelf() {
}
// 渲染书籍列表
const DomBookshelfContainer = document.getElementById('BookshelfContainer');
DomBookshelfContainer.innerHTML = ''; // 清空原内容
const DomBookshelfContainer = document.getElementById('bookshelfMod-head');
arrBookshelf.forEach(book => {
const bookElement = document.createElement('div');
const bookElement = document.createElement('tr');
bookElement.classList.add('book-shelf'); // 添加类名
if (isMobile()) {
bookElement.innerHTML = `
<dl class="rec-focus-book">
<dt class="book-img">
<a href="/shu/${book.xsxq_id}.html">
<img height="100" width="80" src="${book.xsxq_feng_mian_url}" >
<td>
<a href="/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >
<img class="lazyload-img"
src="/static/img/default.jpg" data-src="${book.n_cover_path}">
</a>
</dt>
<dd class="book-info">
<h2><a href="/shu/${book.xsxq_id}.html">${book.xsxq_ming_zi}</a></h2>
<p>作者: ${book.xsxq_zuozhe}</p>
<p> ${book.xsxq_jie_shao}</p>
</dd>
</dl>
</td>
<td class="t2">
<a href="/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >${book.og_novel_book_name}</a>
</td>
<td class="t3">
<a href="/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}" >${book.c_name}</a>
</td>
<td class="t4">
<a href="/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >${book.og_novel_author}</a>
</td>
<td class="t5">3天前</td>
<td class="t6">${book.og_novel_status}</td>
<td class="t7">
<a href="/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}" class="goon" >阅读</a>
<i><span class="Collection" ajax-get="" onclick="delBookshelfFun(${book.n_id})">删除</span></i>
</td>
`;
} else {
bookElement.innerHTML = `
<div class="item">
<div class="image">
<a href="/shu/${book.xsxq_id}.html">
<img style="min-height:120px;" src="${book.xsxq_feng_mian_url}" alt="${book.xsxq_ming_zi}">
<td>
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >
<img src="${book.n_cover_path}" >
</a>
</div>
<dl>
<dt>
<span>${book.xsxq_zuozhe}</span>
<a href="/shu/${book.xsxq_id}.html">${book.xsxq_ming_zi}</a>
</dt>
<dd style="height:90px">
<a href="/shu/${book.xsxq_id}.html"
style="color: #555">${book.xsxq_jie_shao}</a>
</dd>
</dl>
</div>
</td>
<td class="t2">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >${book.og_novel_book_name}</a>
</td>
<td class="t3">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}" >${book.c_name}</a>
</td>
<td class="t4">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >${book.og_novel_author}</a>
</td>
<td class="t5">${book.og_novel_update_time}</td>
<td class="t6">${book.og_novel_status}</td>
<td class="t7">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}" class="goon" >阅读</a>
<i><span class="Collection" ajax-get="" onclick="delBookshelfFun(${book.n_id})">删除</span></i>
</td>
`;
}
DomBookshelfContainer.appendChild(bookElement);
DomBookshelfContainer.after(bookElement);
});
}
// 加入阅读记录
function addHistoryFun(NovelInfo) {
// 如果没有传入 NovelInfo则使用 arrNovel 并补充字段
if (!NovelInfo) {
return;
}
let arrBookshelf = JSON.parse(localStorage.getItem('strHistoryKey')) || [];
console.log(arrBookshelf)
// 检查书籍是否已存在
const exists = arrBookshelf.some(item => item.xsxq_id === NovelInfo.xsxq_id);
if (exists) {
return;
NovelInfo = JSON.parse(arrNovel);
NovelInfo['c_sort_num'] = strChapterSort;
NovelInfo['c_name'] = strChapterName;
}
// 添加到书架
arrBookshelf.push(NovelInfo);
// 获取本地存储中的历史记录
let arrBookshelf = JSON.parse(localStorage.getItem('strHistoryKey')) || [];
// 检查书籍是否已存在
const index = arrBookshelf.findIndex(item => item.n_id === NovelInfo.n_id);
if (index !== -1) {
// 如果存在,更新该书籍的信息
arrBookshelf[index] = { ...arrBookshelf[index], ...NovelInfo };
} else {
// 如果不存在,添加到历史记录
arrBookshelf.push(NovelInfo);
}
// 更新本地存储
localStorage.setItem('strHistoryKey', JSON.stringify(arrBookshelf));
}
// 删除历史记录
function delHistoryFun(intNId) {
// 获取书架数据
const arrHistory = JSON.parse(localStorage.getItem('strHistoryKey')) || [];
// 检查 arrHistory 是否为数组且不为空
if (Array.isArray(arrHistory) && arrHistory.length > 0) {
// 找到匹配 intNId 的索引
const index = arrHistory.findIndex(item => item.n_id === intNId);
// 如果找到匹配项index !== -1则删除
if (index !== -1) {
arrHistory.splice(index, 1); // 删除该项
// 更新 localStorage
localStorage.setItem('strHistoryKey', JSON.stringify(arrHistory));
} else {
console.log(`未找到 ID 为 ${intNId} 的历史记录`);
}
} else {
console.log('历史记录为空,无需删除');
}
removeElementsByClass('book-history')
// localStorage.setItem('strHistoryKey', JSON.stringify(arrHistory));
displayHistory()
}
// 展示 历史记录
@@ -242,50 +315,63 @@ function displayHistory() {
}
// 渲染书籍列表
const DomHistoryContainer = document.getElementById('HistoryContainer');
DomHistoryContainer.innerHTML = ''; // 清空原内容
const DomHistoryContainer = document.getElementById('bookshelfMod-head');
arrHistory.forEach(book => {
const bookElement = document.createElement('div');
const bookElement = document.createElement('tr');
bookElement.classList.add('book-history'); // 添加类名
if (isMobile()) {
bookElement.innerHTML = `
<dl class="rec-focus-book">
<dt class="book-img">
<a href="/shu/${book.xsxq_id}.html">
<img height="100" width="80" src="${book.xsxq_feng_mian_url}" >
<td>
<a href="/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >
<img class="lazyload-img"
src="/static/img/default.jpg" data-src="${book.n_cover_path}">
</a>
</dt>
<dd class="book-info">
<h2><a href="/shu/${book.xsxq_id}.html">${book.xsxq_ming_zi}</a></h2>
<p>作者: ${book.xsxq_zuozhe}</p>
<p> ${book.xsxq_jie_shao}</p>
</dd>
</dl>
</td>
<td class="t2">
<a href="/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >${book.og_novel_book_name}</a>
</td>
<td class="t3">
<a href="/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}" >${book.c_name}</a>
</td>
<td class="t4">
<a href="/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >${book.og_novel_author}</a>
</td>
<td class="t5">3天前</td>
<td class="t6">${book.og_novel_status}</td>
<td class="t7">
<a href="/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}" class="goon" >阅读</a>
<i><span class="Collection" ajax-get="" onclick="delHistoryFun(${book.n_id})">删除</span></i>
</td>
`;
} else {
bookElement.innerHTML = `
<div class="item">
<div class="image">
<a href="/shu/${book.xsxq_id}.html">
<img style="min-height:120px;" src="${book.xsxq_feng_mian_url}" alt="${book.xsxq_ming_zi}">
<td>
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >
<img src="${book.n_cover_path}" >
</a>
</div>
<dl>
<dt>
<span>${book.xsxq_zuozhe}</span>
<a href="/shu/${book.xsxq_id}.html">${book.xsxq_ming_zi}</a>
</dt>
<dd style="height:90px">
<a href="/shu/${book.xsxq_id}.html"
style="color: #555">${book.xsxq_jie_shao}</a>
</dd>
</dl>
</div>
</td>
<td class="t2">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >${book.og_novel_book_name}</a>
</td>
<td class="t3">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}" >${book.c_name}</a>
</td>
<td class="t4">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}" >${book.og_novel_author}</a>
</td>
<td class="t5">${book.og_novel_update_time}</td>
<td class="t6">${book.og_novel_status}</td>
<td class="t7">
<a href="/pc/xiaoshuo/${book.og_novel_pin_yin}-${book.n_id}/zhang-${book.c_sort_num}" class="goon" >阅读</a>
<i><span class="Collection" ajax-get="" onclick="delHistoryFun(${book.n_id})">删除</span></i>
</td>
`;
}
DomHistoryContainer.appendChild(bookElement);
DomHistoryContainer.after(bookElement);
});
}
@@ -315,9 +401,15 @@ async function reportStats(data) {
console.error('上报错误:', error);
}
}
function removeElementsByClass(className) {
const elements = document.querySelectorAll(`.${className}`);
elements.forEach(element => element.remove());
}
document.addEventListener("DOMContentLoaded", function () {
if(typeof strNovelId !== "undefined") {
if (typeof strNovelId !== "undefined") {
// 使用示例
const statsData = {
@@ -325,5 +417,7 @@ document.addEventListener("DOMContentLoaded", function () {
};
// 调用方法1
reportStats(statsData);
addHistoryFun()
}
})