68 lines
2.3 KiB
Plaintext
68 lines
2.3 KiB
Plaintext
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="mb-0">评论管理</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>评论内容</th>
|
|
<th>用户</th>
|
|
<th>文章</th>
|
|
<th>评论时间</th>
|
|
<th>操作</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<% comments.forEach(comment => { %>
|
|
<tr>
|
|
<td><%= comment.content %></td>
|
|
<td><%= comment.author ? comment.author.username : '未知用户' %></td>
|
|
<td><%= comment.post ? comment.post.title : '未知文章' %></td>
|
|
<td><%= new Date(comment.createdAt).toLocaleString() %></td>
|
|
<td>
|
|
<button class="btn btn-sm btn-danger delete-comment-btn" data-id="<%= comment._id %>">删除</button>
|
|
</td>
|
|
</tr>
|
|
<% }); %>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- 分页组件 -->
|
|
<%- include('../../components/pagination', {
|
|
currentPage: pagination.currentPage,
|
|
totalPages: pagination.totalPages,
|
|
baseUrl: baseUrl,
|
|
query: query
|
|
}) %>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// 删除评论
|
|
document.querySelectorAll('.delete-comment-btn').forEach(btn => {
|
|
btn.addEventListener('click', function() {
|
|
const commentId = this.getAttribute('data-id');
|
|
if (confirm('确定要删除这条评论吗?')) {
|
|
fetch(`/admin/comments/${commentId}`, {
|
|
method: 'DELETE'
|
|
})
|
|
.then(response => response.json())
|
|
.then(result => {
|
|
if (result.success) {
|
|
location.reload();
|
|
} else {
|
|
alert('删除失败');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error(error);
|
|
alert('删除失败');
|
|
});
|
|
}
|
|
});
|
|
});
|
|
</script>
|