修复文章前后端相关问题
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?php /*a:5:{s:63:"E:\Demos\DemoOwns\PHP\yunzer\app\index\view\articles\detail.php";i:1747818914;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: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;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
@@ -632,6 +632,7 @@ $loginStatus = [
|
||||
<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>
|
||||
@@ -1205,6 +1206,22 @@ $loginStatus = [
|
||||
} 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');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载完成后执行
|
||||
@@ -1222,13 +1239,8 @@ $loginStatus = [
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
// console.log('Response status:', response.status);
|
||||
// console.log('Response headers:', response.headers);
|
||||
return response.json();
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
// console.log('API response:', result);
|
||||
if (result.code === 1) {
|
||||
renderArticleDetail(result.data);
|
||||
// 更新访问次数
|
||||
@@ -1240,28 +1252,13 @@ $loginStatus = [
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('获取文章详情失败:', error);
|
||||
console.error('Error details:', {
|
||||
message: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
alert('获取文章详情失败,请检查网络连接或刷新页面重试');
|
||||
});
|
||||
|
||||
// 点赞功能
|
||||
const likeBtn = document.getElementById('likeBtn');
|
||||
if (likeBtn) {
|
||||
// 检查是否已经点赞
|
||||
if (likeBtn.classList.contains('liked')) {
|
||||
likeBtn.style.pointerEvents = 'none'; // 禁用点击
|
||||
likeBtn.style.cursor = 'default'; // 改变鼠标样式
|
||||
return;
|
||||
}
|
||||
|
||||
likeBtn.addEventListener('click', function () {
|
||||
// 立即禁用按钮,防止重复点击
|
||||
likeBtn.style.pointerEvents = 'none';
|
||||
likeBtn.style.cursor = 'default';
|
||||
|
||||
fetch('/index/articles/like?id=' + articleId, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -1271,26 +1268,19 @@ $loginStatus = [
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.code === 1) {
|
||||
const countElement = document.getElementById('articlesLikes');
|
||||
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 {
|
||||
// 如果请求失败,恢复按钮状态
|
||||
likeBtn.style.pointerEvents = 'auto';
|
||||
likeBtn.style.cursor = 'pointer';
|
||||
layer.msg('点赞失败:' + data.msg, { icon: 2 });
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
// 如果请求失败,恢复按钮状态
|
||||
likeBtn.style.pointerEvents = 'auto';
|
||||
likeBtn.style.cursor = 'pointer';
|
||||
console.error('点赞请求失败:', error);
|
||||
layer.msg('点赞失败,请稍后重试', { icon: 2 });
|
||||
});
|
||||
@@ -1299,8 +1289,6 @@ $loginStatus = [
|
||||
|
||||
// 返回顶部功能
|
||||
const goToTop = document.getElementById('goToTop');
|
||||
|
||||
// 监听滚动事件
|
||||
window.addEventListener('scroll', function () {
|
||||
if (window.pageYOffset > 300) {
|
||||
goToTop.classList.add('show');
|
||||
@@ -1309,13 +1297,27 @@ $loginStatus = [
|
||||
}
|
||||
});
|
||||
|
||||
// 点击返回顶部
|
||||
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 });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 更新文章访问次数
|
||||
@@ -1332,7 +1334,6 @@ $loginStatus = [
|
||||
.then(response => response.json())
|
||||
.then(result => {
|
||||
if (result.code === 1) {
|
||||
// 更新成功,更新页面上的访问次数显示
|
||||
const viewsElement = document.getElementById('articleViews');
|
||||
if (viewsElement) {
|
||||
viewsElement.textContent = result.data.views;
|
||||
@@ -1343,30 +1344,6 @@ $loginStatus = [
|
||||
console.error('更新访问次数失败:', error);
|
||||
});
|
||||
}
|
||||
|
||||
// 分享功能
|
||||
const shareBtn = document.getElementById('shareBtn');
|
||||
if (shareBtn) {
|
||||
shareBtn.addEventListener('click', function () {
|
||||
// 获取当前页面URL
|
||||
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);
|
||||
|
||||
// 提示用户复制成功
|
||||
alert('链接已复制到剪贴板');
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user