评论添加删除

This commit is contained in:
浅念
2025-12-23 17:08:13 +08:00
parent 3c40ea3ee3
commit 3f0f7f6103
2 changed files with 68 additions and 0 deletions
+7
View File
@@ -85,4 +85,11 @@ export class classifyService {
params
})
}
//评论删除 /admin/post/comment/destroy
static deleteclassifycontentcomment(params: any) {
return request.post<any>({
url: '/admin/post/comment/destroy',
params
})
}
}
@@ -234,6 +234,16 @@
<div class="comment-author">{{ comment.user.nickname }}</div>
<div class="comment-time">{{ formatTime(comment.created_at) }}</div>
</div>
<div>
<el-button
type="danger"
link
@click="deleteComment(comment)"
v-if="hasAuth('classify_item@del')"
>
删除
</el-button>
</div>
</div>
<div class="comment-content">{{ comment.content || '-' }}</div>
<!-- 回复列表 -->
@@ -247,6 +257,16 @@
formatTime(reply.created_at || reply.timestamp)
}}</div>
</div>
<div>
<el-button
type="danger"
link
@click="deleteComment(reply)"
v-if="hasAuth('classify_item@del')"
>
删除
</el-button>
</div>
</div>
<div class="reply-content">{{ reply.content || '-' }}</div>
</div>
@@ -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('删除失败')
}
})
}
</script>
<style lang="scss" scoped>