|
|
|
|
@ -1,4 +1,7 @@
|
|
|
|
|
<dev>
|
|
|
|
|
<!-- 在文件开头添加Font Awesome和CSS样式 -->
|
|
|
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<section id="comments" class="themeform">
|
|
|
|
|
{% load blog_tags %}
|
|
|
|
|
{% load comments_tags %}
|
|
|
|
|
@ -7,39 +10,317 @@
|
|
|
|
|
<ul class="comment-tabs group">
|
|
|
|
|
<li class="active"><a href="#commentlist-container"><i
|
|
|
|
|
class="fa fa-comments-o"></i>评论<span>{{ comment_count }}</span></a></li>
|
|
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
{% if article_comments %}
|
|
|
|
|
<div id="commentlist-container" class="comment-tab" style="display: block;">
|
|
|
|
|
<ol class="commentlist">
|
|
|
|
|
{# {% query article_comments parent_comment=None as parent_comments %}#}
|
|
|
|
|
{% for comment_item in p_comments %}
|
|
|
|
|
|
|
|
|
|
{# 杨智鑫:确保这里使用正确的变量名 #}
|
|
|
|
|
{% for comment_item in article_comments %}
|
|
|
|
|
{% with 0 as depth %}
|
|
|
|
|
{% include "comments/tags/comment_item_tree.html" %}
|
|
|
|
|
{% endwith %}
|
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
|
|
</ol><!--/.commentlist-->
|
|
|
|
|
|
|
|
|
|
<div class="navigation">
|
|
|
|
|
<nav class="nav-single">
|
|
|
|
|
{% if comment_prev_page_url %}
|
|
|
|
|
<div class="nav-previous">
|
|
|
|
|
<span><a href="{{ comment_prev_page_url }}" rel="prev"><span
|
|
|
|
|
class="meta-nav">←</span> 上一页</a></span>
|
|
|
|
|
<span><a href="{{ comment_prev_page_url }}" rel="prev"><span
|
|
|
|
|
class="meta-nav">←</span> 上一页</a></span>
|
|
|
|
|
</div>
|
|
|
|
|
{% endif %}
|
|
|
|
|
{% if comment_next_page_url %}
|
|
|
|
|
<div class="nav-next">
|
|
|
|
|
<span><a href="{{ comment_next_page_url }}" rel="next">下一页 <span
|
|
|
|
|
class="meta-nav">→</span></a></span>
|
|
|
|
|
<span><a href="{{ comment_prev_page_url }}" rel="next">下一页 <span
|
|
|
|
|
class="meta-nav">→</span></a></span>
|
|
|
|
|
</div>
|
|
|
|
|
{% endif %}
|
|
|
|
|
</nav>
|
|
|
|
|
</div>
|
|
|
|
|
<br/>
|
|
|
|
|
</div>
|
|
|
|
|
{% else %}
|
|
|
|
|
<div id="commentlist-container" class="comment-tab" style="display: block;">
|
|
|
|
|
<p>暂无评论</p>
|
|
|
|
|
</div>
|
|
|
|
|
{% endif %}
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- 杨智鑫:添加点赞和举报功能的CSS样式 -->
|
|
|
|
|
<style>
|
|
|
|
|
/* 评论操作按钮样式 */
|
|
|
|
|
.comment-actions {
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 15px;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.like-action, .report-action, .reply {
|
|
|
|
|
display: inline-block;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn-like, .btn-report {
|
|
|
|
|
background: none;
|
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
|
padding: 4px 8px;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
color: #666;
|
|
|
|
|
transition: all 0.3s ease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn-like:hover {
|
|
|
|
|
background: #e8f5e8;
|
|
|
|
|
border-color: #4CAF50;
|
|
|
|
|
color: #4CAF50;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn-report:hover {
|
|
|
|
|
background: #ffe8e8;
|
|
|
|
|
border-color: #f44336;
|
|
|
|
|
color: #f44336;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn-like.liked {
|
|
|
|
|
background: #4CAF50;
|
|
|
|
|
color: white;
|
|
|
|
|
border-color: #4CAF50;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn-like .like-count {
|
|
|
|
|
margin-left: 4px;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 举报模态框样式 */
|
|
|
|
|
.report-modal {
|
|
|
|
|
display: none;
|
|
|
|
|
position: fixed;
|
|
|
|
|
z-index: 1000;
|
|
|
|
|
left: 0;
|
|
|
|
|
top: 0;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
background-color: rgba(0,0,0,0.5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.report-modal-content {
|
|
|
|
|
background-color: #fefefe;
|
|
|
|
|
margin: 15% auto;
|
|
|
|
|
padding: 20px;
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
width: 400px;
|
|
|
|
|
max-width: 90%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.report-reason-options {
|
|
|
|
|
margin: 15px 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.report-reason-options label {
|
|
|
|
|
display: block;
|
|
|
|
|
margin: 8px 0;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.report-description {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 80px;
|
|
|
|
|
margin: 10px 0;
|
|
|
|
|
padding: 8px;
|
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
resize: vertical;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.report-actions {
|
|
|
|
|
text-align: right;
|
|
|
|
|
margin-top: 15px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn-cancel, .btn-submit-report {
|
|
|
|
|
padding: 8px 16px;
|
|
|
|
|
border: none;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
margin-left: 10px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn-cancel {
|
|
|
|
|
background: #f5f5f5;
|
|
|
|
|
color: #333;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn-submit-report {
|
|
|
|
|
background: #f44336;
|
|
|
|
|
color: white;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<!-- 杨智鑫:添加点赞和举报功能的JavaScript -->
|
|
|
|
|
<script>
|
|
|
|
|
// 杨智鑫:评论点赞和举报功能
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
|
// 点赞功能
|
|
|
|
|
document.querySelectorAll('.btn-like').forEach(button => {
|
|
|
|
|
button.addEventListener('click', function() {
|
|
|
|
|
const commentId = this.dataset.commentId;
|
|
|
|
|
likeComment(commentId, this);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 举报功能
|
|
|
|
|
document.querySelectorAll('.btn-report').forEach(button => {
|
|
|
|
|
button.addEventListener('click', function() {
|
|
|
|
|
const commentId = this.dataset.commentId;
|
|
|
|
|
showReportModal(commentId);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 点赞评论 - 修改URL
|
|
|
|
|
function likeComment(commentId, button) {
|
|
|
|
|
fetch(`/comment/${commentId}/like/`, { // 修改URL
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'X-CSRFToken': getCsrfToken()
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({})
|
|
|
|
|
})
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|
.then(data => {
|
|
|
|
|
if (data.success) {
|
|
|
|
|
const likeCount = button.querySelector('.like-count');
|
|
|
|
|
likeCount.textContent = data.like_count;
|
|
|
|
|
|
|
|
|
|
if (data.liked) {
|
|
|
|
|
button.classList.add('liked');
|
|
|
|
|
} else {
|
|
|
|
|
button.classList.remove('liked');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 显示成功消息
|
|
|
|
|
showMessage(data.message, 'success');
|
|
|
|
|
} else {
|
|
|
|
|
showMessage(data.message, 'error');
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error('Error:', error);
|
|
|
|
|
showMessage('操作失败,请稍后重试', 'error');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 显示举报模态框
|
|
|
|
|
function showReportModal(commentId) {
|
|
|
|
|
// 创建模态框
|
|
|
|
|
const modal = document.createElement('div');
|
|
|
|
|
modal.className = 'report-modal';
|
|
|
|
|
modal.style.display = 'block';
|
|
|
|
|
modal.innerHTML = `
|
|
|
|
|
<div class="report-modal-content">
|
|
|
|
|
<h3>举报评论</h3>
|
|
|
|
|
<p>请选择举报原因:</p>
|
|
|
|
|
<div class="report-reason-options">
|
|
|
|
|
<label>
|
|
|
|
|
<input type="radio" name="report_reason" value="spam" required>
|
|
|
|
|
垃圾广告
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
<input type="radio" name="report_reason" value="abuse" required>
|
|
|
|
|
辱骂攻击
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
<input type="radio" name="report_reason" value="illegal" required>
|
|
|
|
|
违法信息
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
<input type="radio" name="report_reason" value="other" required>
|
|
|
|
|
其他原因
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
<textarea class="report-description" placeholder="请简要描述举报原因(可选)"></textarea>
|
|
|
|
|
<div class="report-actions">
|
|
|
|
|
<button class="btn-cancel" onclick="closeReportModal()">取消</button>
|
|
|
|
|
<button class="btn-submit-report" onclick="submitReport(${commentId})">提交举报</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
document.body.appendChild(modal);
|
|
|
|
|
|
|
|
|
|
// 点击模态框外部关闭
|
|
|
|
|
modal.addEventListener('click', function(e) {
|
|
|
|
|
if (e.target === modal) {
|
|
|
|
|
closeReportModal();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 关闭举报模态框
|
|
|
|
|
function closeReportModal() {
|
|
|
|
|
const modal = document.querySelector('.report-modal');
|
|
|
|
|
if (modal) {
|
|
|
|
|
modal.remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 提交举报 - 修改URL
|
|
|
|
|
function submitReport(commentId) {
|
|
|
|
|
const reason = document.querySelector('input[name="report_reason"]:checked');
|
|
|
|
|
const description = document.querySelector('.report-description').value;
|
|
|
|
|
|
|
|
|
|
if (!reason) {
|
|
|
|
|
showMessage('请选择举报原因', 'error');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fetch(`/comment/${commentId}/report/`, { // 修改URL
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'X-CSRFToken': getCsrfToken()
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
reason: reason.value,
|
|
|
|
|
description: description
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|
.then(data => {
|
|
|
|
|
if (data.success) {
|
|
|
|
|
showMessage(data.message, 'success');
|
|
|
|
|
closeReportModal();
|
|
|
|
|
} else {
|
|
|
|
|
showMessage(data.message, 'error');
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error('Error:', error);
|
|
|
|
|
showMessage('举报失败,请稍后重试', 'error');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取CSRF Token
|
|
|
|
|
function getCsrfToken() {
|
|
|
|
|
const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]');
|
|
|
|
|
return csrfToken ? csrfToken.value : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</dev>
|
|
|
|
|
// 显示消息
|
|
|
|
|
function showMessage(message, type) {
|
|
|
|
|
// 这里可以使用你项目中已有的消息提示组件
|
|
|
|
|
// 如果没有,可以简单使用alert或创建临时提示
|
|
|
|
|
if (type === 'error') {
|
|
|
|
|
alert('错误: ' + message);
|
|
|
|
|
} else {
|
|
|
|
|
alert(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|