更新界面详情

This commit is contained in:
2025-05-28 17:25:16 +08:00
parent 5d791d84ed
commit 352540b500
13 changed files with 1742 additions and 1312 deletions
@@ -1,4 +1,4 @@
<?php /*a:5:{s:63:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\articles\detail.php";i:1748400078;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\head.php";i:1747617129;s:71:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\header-simple.php";i:1748316508;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\footer.php";i:1747617266;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\foot.php";i:1747616844;}*/ ?>
<?php /*a:5:{s:63:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\articles\detail.php";i:1748423296;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\head.php";i:1747617129;s:71:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\header-simple.php";i:1748316508;s:64:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\footer.php";i:1747617266;s:62:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\component\foot.php";i:1747616844;}*/ ?>
<!DOCTYPE html>
<html>
@@ -624,68 +624,148 @@ $loginStatus = [
<div class="location-item">
<a href="/">首页</a>
<span>></span>
<a href="/index/articles/index" id="cateLink"></a>
<a href="/index/articles/index"><?php echo htmlentities((string) $cateName); ?></a>
</div>
</div>
</div>
<div class="article-detail-container">
<div class="article-header">
<h1 class="article-title" id="articleTitle"></h1>
<div class="trans" id="transDiv" style="display: none;">转载至:<span id="transUrl"></span></div>
<div class="article-meta">
<span class="article-author"><i class="fa fa-user"></i> <span id="articleAuthor"></span></span>
<span class="article-date"><i class="fa fa-calendar"></i> <span id="articleDate"></span></span>
<span class="article-views"><i class="fa-solid fa-eye"></i> <span id="articleViews"></span> 阅读</span>
<div class="body-container">
<div class="article-detail-container">
<div class="article-header">
<h1 class="article-title"><?php echo htmlentities((string) $article['title']); ?></h1>
<?php if($article['is_trans'] == 1 && $article['transurl']): ?>
<div class="trans">转载至:<span class="trans-url" data-url="<?php echo htmlentities((string) $article['transurl']); ?>"><?php echo htmlentities((string) $article['transurl']); ?></span>
</div>
<?php endif; ?>
<div class="article-meta">
<span class="article-author"><i class="fa fa-user"></i> <span><?php echo htmlentities((string) $article['author']); ?></span></span>
<span class="article-date"><i class="fa fa-calendar"></i>
<span><?php echo htmlentities((string) date("Y-m-d",!is_numeric($article['create_time'])? strtotime($article['create_time']) : $article['create_time'])); ?></span></span>
<span class="article-views"><i class="fa-solid fa-eye"></i> <span><?php echo htmlentities((string) $article['views']); ?></span> 阅读</span>
</div>
</div>
</div>
<div class="article-content" id="articleContent">
</div>
<div class="article-content">
<?php echo $article['content']; ?>
</div>
<div class="disclaimers">
<div class="disclaimer-item">
<div class="disclaimer-title">免责声明:</div>
<div class="disclaimer-content">
<?php echo $config['disclaimers'] ?>
<div class="disclaimers">
<div class="disclaimer-item">
<div class="disclaimer-title">免责声明:</div>
<div class="disclaimer-content">
<?php echo $config['disclaimers'] ?>
</div>
</div>
</div>
<div class="article-tags">
<span class="tag-label">标签:</span>
<div>
<?php if($article['tags']): if(is_array(explode($article['tags'],',',',')) || explode($article['tags'],',',',') instanceof \think\Collection || explode($article['tags'],',',',') instanceof \think\Paginator): $i = 0; $__LIST__ = explode($article['tags'],',',',');if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$tag): $mod = ($i % 2 );++$i;?>
<span class="tag-item"><?php echo htmlentities((string) $tag); ?></span>
<?php endforeach; endif; else: echo "" ;endif; else: ?>
<span class="no-tags">暂无标签</span>
<?php endif; ?>
</div>
</div>
<div class="article-actions">
<div class="action-item like-btn" data-id="<?php echo htmlentities((string) $article['id']); ?>">
<i class="fa fa-thumbs-up"></i>
<span class="action-text">点赞</span>
<span class="action-count"><?php echo htmlentities((string) $article['likes']); ?></span>
</div>
<div class="action-item share-btn">
<i class="fa fa-share-alt"></i>
<span class="action-text">分享</span>
</div>
</div>
<div class="article-navigation">
<div class="prev-article">
<?php if($prevArticle): ?>
<a href="/index/articles/detail?id=<?php echo htmlentities((string) $prevArticle['id']); ?>">
<i class="fa fa-arrow-left"></i> 上一篇:<?php echo htmlentities((string) $prevArticle['title']); ?>
</a>
<?php else: ?>
<span class="disabled"><i class="fa fa-arrow-left"></i> 没有上一篇了</span>
<?php endif; ?>
</div>
<div class="next-article">
<?php if($nextArticle): ?>
<a href="/index/articles/detail?id=<?php echo htmlentities((string) $nextArticle['id']); ?>">
下一篇:<?php echo htmlentities((string) $nextArticle['title']); ?> <i class="fa fa-arrow-right"></i>
</a>
<?php else: ?>
<span class="disabled">没有下一篇了 <i class="fa fa-arrow-right"></i></span>
<?php endif; ?>
</div>
</div>
<div class="related-articles">
<h3 class="related-title">相关推荐</h3>
<div class="related-list">
<?php if(is_array($relatedArticles) || $relatedArticles instanceof \think\Collection || $relatedArticles instanceof \think\Paginator): $i = 0; $__LIST__ = $relatedArticles;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$related): $mod = ($i % 2 );++$i;?>
<div class="related-item">
<a href="/index/articles/detail?id=<?php echo htmlentities((string) $related['id']); ?>">
<div class="related-image">
<img src="<?php echo htmlentities((string) $related['image']); ?>" alt="<?php echo htmlentities((string) $related['title']); ?>">
</div>
<div class="related-info">
<div class="related-item-title"><?php echo htmlentities((string) $related['title']); ?></div>
</div>
</a>
</div>
<?php endforeach; endif; else: echo "" ;endif; ?>
</div>
</div>
</div>
<div class="article-detail-right">
<div class="aboutauthor">
<div class="aboutauthor-title">关于作者</div>
<div class="aboutauthor-main">
<div class="aboutauthor-main-top">
<div class="aboutauthor-avatar">
<img src="<?php echo htmlentities((string) $authorInfo['avatar']); ?>" alt="作者头像">
</div>
<div class="aboutauthor-info">
<div class="author-name"><?php echo htmlentities((string) $authorInfo['name']); ?></div>
</div>
</div>
<div class="aboutauthor-main-middle">
<div class="author-stats">
<div class="article-tags">
<span class="tag-label">标签:</span>
<div id="articleTags"></div>
</div>
<div class="article-actions">
<div class="action-item like-btn" id="likeBtn">
<i class="fa fa-thumbs-up"></i>
<span class="action-text">点赞</span>
<span class="action-count" id="articleLikes">0</span>
</div>
<div class="action-item share-btn" id="shareBtn">
<i class="fa fa-share-alt"></i>
<span class="action-text">分享</span>
</div>
</div>
<div class="article-navigation">
<div class="prev-article" id="prevArticle">
</div>
<div class="next-article" id="nextArticle">
</div>
</div>
<div class="related-articles">
<h3 class="related-title">相关推荐</h3>
<div class="related-list" id="relatedArticles">
<div class="author-stats-item">
<h6>资源</h6>
<span class="count"><?php echo htmlentities((string) $authorInfo['resource_count']); ?></span>
</div>
<div class="author-stats-item">
<h6>文章</h6>
<span class="count"><?php echo htmlentities((string) $authorInfo['article_count']); ?></span>
</div>
<div class="author-stats-item">
<h6>粉丝</h6>
<span class="count">
0
</span>
</div>
</div>
</div>
</div>
<div class="aboutauthor-btn">
<button class="follow-btn">
<i class="fa fa-user-plus"></i> 关注他
</button>
<button class="message-btn">
<i class="fa fa-envelope"></i> 发私信
</button>
</div>
</div>
</div>
</div>
</div>
<!-- 返回顶部按钮 -->
<div class="go-to-top" id="goToTop">
<div class="go-to-top">
<i class="layui-icon-up"></i>
</div>
@@ -746,20 +826,197 @@ $loginStatus = [
</div>
</section>
<script>
// 更新访问次数
async function updateArticleViews(articleId) {
try {
await fetch('/index/articles/updateViews', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: articleId })
});
} catch (error) {
console.error('更新访问次数失败:', error);
}
}
// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', function () {
const articleId = '<?php echo htmlentities((string) $article['id']); ?>';
// 更新访问次数
updateArticleViews(articleId);
// 点赞功能
document.querySelector('.like-btn').addEventListener('click', async function () {
try {
const response = await fetch('/index/articles/like?id=' + articleId, {
method: 'POST',
headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
const result = await response.json();
if (result.code === 1) {
const countElement = this.querySelector('.action-count');
countElement.textContent = parseInt(countElement.textContent) + 1;
this.classList.add('liked');
this.querySelector('i').style.color = '#f57005';
layer.msg('点赞成功', { icon: 1 });
} else {
layer.msg(result.msg, { icon: 2 });
}
} catch (error) {
layer.msg('点赞失败,请稍后重试', { icon: 2 });
}
});
// 分享功能
document.querySelector('.share-btn').addEventListener('click', function () {
const url = window.location.href;
navigator.clipboard.writeText(url).then(() => {
layer.msg('链接已复制到剪贴板', { icon: 1 });
}).catch(() => {
layer.msg('复制失败,请手动复制', { icon: 2 });
});
});
// 转载链接点击
document.querySelector('.trans-url')?.addEventListener('click', function () {
const url = this.dataset.url;
if (url) {
window.open(url, '_blank');
}
});
// 返回顶部
const goToTop = document.querySelector('.go-to-top');
window.addEventListener('scroll', function () {
if (window.scrollY > 300) {
goToTop.classList.add('show');
} else {
goToTop.classList.remove('show');
}
});
goToTop.addEventListener('click', function () {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
});
</script>
<style>
.location {
max-width: 1000px;
max-width: 1200px;
margin: 30px auto;
}
.main .body-container {
display: flex;
max-width: 1200px;
margin: 30px auto;
gap: 30px;
}
.main .body-container .article-detail-right {
width: 30%;
}
.article-detail-container {
max-width: 1000px;
margin: 30px auto;
padding: 50px;
background: #fff;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
border-radius: 8px;
width: 70%;
}
.main .body-container .article-detail-right .aboutauthor {
background: #fff;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
.main .body-container .article-detail-right .aboutauthor-title {
height: 60px;
display: flex;
align-items: center;
padding-left: 20px;
border-bottom: 1px solid #eee;
font-weight: 700;
}
.main .body-container .article-detail-right .aboutauthor-main {
display: flex;
flex-direction: column;
}
.main .body-container .article-detail-right .aboutauthor-main .aboutauthor-main-top {
display: flex;
align-items: center;
padding-left: 20px !important;
padding: 20px 0;
border-bottom: 1px solid #efefef;
margin-bottom: 20px;
}
.main .body-container .article-detail-right .aboutauthor-main .aboutauthor-main-top .aboutauthor-avatar {
margin-right: 12px;
}
.main .body-container .article-detail-right .aboutauthor-main .aboutauthor-main-top .aboutauthor-info .author-name {
font-size: 20px;
font-weight: 700;
}
.main .body-container .article-detail-right .aboutauthor-main .aboutauthor-main-top .aboutauthor-avatar img {
width: 60px;
height: 60px;
border-radius: 4px;
box-sizing: border-box;
margin: 0px;
min-width: 0px;
max-width: 100%;
background-color: #fff;
}
.main .body-container .article-detail-right .aboutauthor-main .aboutauthor-main-middle {
/* margin-left: 20px; */
}
.main .body-container .article-detail-right .aboutauthor-main .aboutauthor-main-middle .author-stats {
display: flex;
justify-content: space-evenly;
}
.main .body-container .article-detail-right .aboutauthor-main .aboutauthor-main-middle .author-stats .author-stats-item {
display: flex;
flex-direction: column;
align-items: center;
}
.main .body-container .article-detail-right .aboutauthor-main .aboutauthor-main-middle .author-stats .author-stats-item .count {
/* font-size: 30px; */
font-weight: 700;
}
.main .body-container .article-detail-right .aboutauthor-btn {
display: flex;
justify-content: space-evenly;
padding: 20px 0;
}
.main .body-container .article-detail-right .aboutauthor-btn .follow-btn {
background-color: #0081ff;
color: #fff;
padding: 10px 20px;
border-radius: 8px;
border: none;
}
.main .body-container .article-detail-right .aboutauthor-btn .message-btn {
color: #0081ff;
padding: 10px 20px;
border-radius: 8px;
border: 1px solid #eee;
}
.article-header {
@@ -1123,228 +1380,6 @@ $loginStatus = [
}
</style>
<script>
// 格式化日期
function formatDate(timestamp) {
const date = new Date(timestamp * 1000);
return date.toLocaleDateString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit'
});
}
// 渲染文章详情
function renderArticleDetail(data) {
// 渲染分类链接
document.getElementById('cateLink').textContent = data.cateName;
// 渲染文章标题
document.getElementById('articleTitle').textContent = data.article.title;
// 渲染文章元信息
document.getElementById('articleAuthor').textContent = data.article.author;
document.getElementById('articleDate').textContent = formatDate(data.article.create_time);
document.getElementById('articleViews').textContent = data.article.views;
// 渲染文章内容
document.getElementById('articleContent').innerHTML = data.article.content;
// 渲染标签
const tagsContainer = document.getElementById('articleTags');
if (data.article.tags && data.article.tags.length > 0) {
tagsContainer.innerHTML = data.article.tags.map(tag =>
`<span class="tag-item">${tag}</span>`
).join('');
} else {
tagsContainer.innerHTML = '<span class="no-tags">暂无标签</span>';
}
// 渲染点赞数
document.getElementById('articleLikes').textContent = data.article.likes || 0;
// 渲染上一篇
const prevArticle = document.getElementById('prevArticle');
if (data.prevArticle) {
prevArticle.innerHTML = `
<a href="/index/articles/detail?id=${data.prevArticle.id}">
<i class="fa fa-arrow-left"></i> 上一篇:${data.prevArticle.title}
</a>
`;
} else {
prevArticle.innerHTML = '<span class="disabled"><i class="fa fa-arrow-left"></i> 没有上一篇了</span>';
}
// 渲染下一篇
const nextArticle = document.getElementById('nextArticle');
if (data.nextArticle) {
nextArticle.innerHTML = `
<a href="/index/articles/detail?id=${data.nextArticle.id}">
下一篇:${data.nextArticle.title} <i class="fa fa-arrow-right"></i>
</a>
`;
} else {
nextArticle.innerHTML = '<span class="disabled">没有下一篇了 <i class="fa fa-arrow-right"></i></span>';
}
// 渲染相关文章
const relatedArticles = document.getElementById('relatedArticles');
if (data.relatedArticles && data.relatedArticles.length > 0) {
relatedArticles.innerHTML = data.relatedArticles.map(article => `
<div class="related-item">
<a href="/index/articles/detail?id=${article.id}">
<div class="related-image">
<img src="${article.image}" alt="${article.title}">
</div>
<div class="related-info">
<div class="related-item-title">${article.title}</div>
<div class="related-item-desc">${article.desc || ''}</div>
</div>
</a>
</div>
`).join('');
} else {
relatedArticles.innerHTML = '<div class="no-related">暂无相关文章</div>';
}
// 处理转载信息
if (data.article.is_trans === 1 && data.article.transurl) {
const transDiv = document.getElementById('transDiv');
const transUrlSpan = document.getElementById('transUrl');
transUrlSpan.textContent = data.article.transurl;
transDiv.style.display = 'block';
// 添加点击事件,在新窗口打开原文章
transUrlSpan.style.cursor = 'pointer';
transUrlSpan.style.color = '#007bff';
transUrlSpan.addEventListener('click', function() {
window.open(data.article.transurl, '_blank');
});
}
}
// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', function () {
// 获取文章ID
const articleId = new URLSearchParams(window.location.search).get('id');
if (!articleId) {
alert('文章ID不存在');
return;
}
// 获取文章详情
fetch(`/index/articles/detail?id=${articleId}`, {
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(response => response.json())
.then(result => {
if (result.code === 1) {
renderArticleDetail(result.data);
// 更新访问次数
updateArticleViews(articleId);
} else {
console.error('API error:', result.msg);
alert(result.msg || '获取文章详情失败');
}
})
.catch(error => {
console.error('获取文章详情失败:', error);
alert('获取文章详情失败,请检查网络连接或刷新页面重试');
});
// 点赞功能
const likeBtn = document.getElementById('likeBtn');
if (likeBtn) {
likeBtn.addEventListener('click', function () {
fetch('/index/articles/like?id=' + articleId, {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(response => response.json())
.then(data => {
if (data.code === 1) {
const countElement = document.getElementById('articleLikes');
if (countElement) {
let count = parseInt(countElement.textContent) || 0;
countElement.textContent = count + 1;
}
likeBtn.classList.add('liked');
likeBtn.querySelector('i').style.color = '#f57005';
layer.msg('点赞成功', { icon: 1 });
} else {
layer.msg('点赞失败:' + data.msg, { icon: 2 });
}
})
.catch(error => {
console.error('点赞请求失败:', error);
layer.msg('点赞失败,请稍后重试', { icon: 2 });
});
});
}
// 返回顶部功能
const goToTop = document.getElementById('goToTop');
window.addEventListener('scroll', function () {
if (window.pageYOffset > 300) {
goToTop.classList.add('show');
} else {
goToTop.classList.remove('show');
}
});
goToTop.addEventListener('click', function () {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// 分享功能
const shareBtn = document.getElementById('shareBtn');
if (shareBtn) {
shareBtn.addEventListener('click', function () {
const currentUrl = window.location.href;
const tempInput = document.createElement('input');
tempInput.value = currentUrl;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
document.body.removeChild(tempInput);
layer.msg('链接已复制到剪贴板', { icon: 1 });
});
}
});
// 更新文章访问次数
function updateArticleViews(articleId) {
fetch('/index/articles/updateViews', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: articleId
})
})
.then(response => response.json())
.then(result => {
if (result.code === 1) {
const viewsElement = document.getElementById('articleViews');
if (viewsElement) {
viewsElement.textContent = result.data.views;
}
}
})
.catch(error => {
console.error('更新访问次数失败:', error);
});
}
</script>
</body>
</html>