diff --git a/src/api/classify.ts b/src/api/classify.ts index 67e7a25..e1ca3c6 100644 --- a/src/api/classify.ts +++ b/src/api/classify.ts @@ -85,4 +85,11 @@ export class classifyService { params }) } + //评论删除 /admin/post/comment/destroy + static deleteclassifycontentcomment(params: any) { + return request.post({ + url: '/admin/post/comment/destroy', + params + }) + } } diff --git a/src/views/admin/classify/classify_item.vue b/src/views/admin/classify/classify_item.vue index 1ea7645..3d38258 100644 --- a/src/views/admin/classify/classify_item.vue +++ b/src/views/admin/classify/classify_item.vue @@ -234,6 +234,16 @@
{{ comment.user.nickname }}
{{ formatTime(comment.created_at) }}
+
+ + 删除 + +
{{ comment.content || '-' }}
@@ -247,6 +257,16 @@ formatTime(reply.created_at || reply.timestamp) }} +
+ + 删除 + +
{{ reply.content || '-' }}
@@ -496,6 +516,47 @@ console.error('修改状态失败:', error) } } + //删除评论 + const deleteComment = (row: any) => { + ElMessageBox.confirm('确定删除该评论吗?', '删除确认', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'error' + }).then(async () => { + try { + const { message } = await classifyService.deleteclassifycontentcomment({ id: row.id }) + ElMessage.success(message) + getMonthlyList() + // 从评论列表中移除已删除的评论 + const removeComment = (list: any[]) => { + const index = list.findIndex((item) => item.id === row.id) + if (index > -1) { + list.splice(index, 1) + return true + } + // 检查是否有子回复需要删除 + for (const item of list) { + if (item.child && item.child.length > 0) { + const childIndex = item.child.findIndex((child: any) => child.id === row.id) + if (childIndex > -1) { + item.child.splice(childIndex, 1) + return true + } + } + } + return false + } + const removed = removeComment(commentList.value) + if (removed) { + // 更新详情中的评论总数 + detailData.value.comment = Math.max(0, detailData.value.comment - 1) + } + } catch (error) { + console.error('删除失败:', error) + ElMessage.error('删除失败') + } + }) + }