This commit is contained in:
浅念
2025-12-26 11:52:22 +08:00
parent 988a4f47c2
commit 1fa9dfd61e
6 changed files with 981 additions and 252 deletions
+72 -10
View File
@@ -36,6 +36,9 @@
<view class="post-content">
<text>{{detail.content}}</text>
</view>
<view class="post-content" v-if="detail.model">
型号:<text>{{detail.model}}</text>
</view>
<view class="post-actions">
<view class="action-item" @click="toggleLike(detail)">
<uni-icons :type="detail.is_like ? 'heart-filled' : 'heart'" :color="detail.is_like ? '#FF5757' : '#999'" size="18"></uni-icons>
@@ -71,6 +74,8 @@
<text class="comment-time">{{item.created_at}}</text>
</view>
<image @click="replyComment(item)" src="/static/image/msg.png" mode="" class="icons20"></image>
<uni-icons @click="delComment(item.id)" v-if="openid==item.user.openid ||openid==detail.user.openid" type="trash" color="#999" size="20"></uni-icons>
</view>
<text class="comment-text">{{item.content}}</text>
<view class="comment-footer">
@@ -86,8 +91,9 @@
<view class="reply-item-left">
<image class="reply-avatar" :src="reply.user.avatar_pull"></image>
<text class="reply-name">{{reply.user.nickname}}:</text>
<uni-icons type="trash" @click="delComment(reply.id)" v-if="openid==reply.user.openid||openid==detail.user.openid" color="#999" size="20"></uni-icons>
</view>
<view>
<view>
<view class="reply-text">{{reply.content}}</view>
<view class="reply-text">{{reply.created_at}}</view>
</view>
@@ -166,6 +172,7 @@
data() {
return {
showlogin: false,
openid:uni.getStorageSync('openid'),
detail: {},
comments: [],
postid:'',
@@ -227,13 +234,12 @@
phone_code: e.detail.code,
}
}).then(res => {
if (res.data.code == -1) {
uni.showToast({
title: res.data.msg,
icon: 'none'
});
} else if (res.data.code == 200) {
uni.showToast({
title: res.data.message,
icon: 'none'
});
if(res.data.code == 200) {
this.showlogin = false
//返回数据接收成功
uni.setStorageSync('is_login', true);
}
@@ -258,6 +264,7 @@
if (res.data.code == 200) {
this.article = res.data.data
this.detail = res.data.data
this.detail.model = this.detail.model.join(',')
}
})
},
@@ -513,6 +520,61 @@
}
})
},
//删除评论
delComment(item){
const that = this;
uni.showModal({
title: '提示',
content: '确定要删除当前评论吗?',
success: function (res) {
if (res.confirm) {
request({
url:'common/post/comment/destroy',
method:'POST',
data:{
id:item
}
}).then(res => {
if(res.data.code === 200){
// 从评论列表中移除
// 先尝试在主评论列表中找到
const mainIndex = that.comments.findIndex(comment => comment.id === item);
if(mainIndex > -1){
// 删除主评论
that.comments.splice(mainIndex, 1);
} else {
// 在子评论中查找并删除
for(let i = 0; i < that.comments.length; i++){
if(that.comments[i].child && that.comments[i].child.length > 0){
const childIndex = that.comments[i].child.findIndex(child => child.id === item);
if(childIndex > -1){
that.comments[i].child.splice(childIndex, 1);
// 如果子评论数组为空,可以删除child属性或保持为空数组
if(that.comments[i].child.length === 0){
that.$set(that.comments[i], 'child', []);
}
break;
}
}
}
}
// 更新评论数量
that.getCommentCount();
uni.showToast({
title:res.data.message || '删除成功',
icon: 'none'
});
} else {
uni.showToast({
title:res.data.message || '删除失败',
icon: 'none'
});
}
})
}
}
});
},
// 预览图片(点击放大)
previewImage(index) {
if (!this.detail.media || this.detail.media.length === 0) return
@@ -742,6 +804,7 @@
.comment-header {
display: flex;
align-items: center;
justify-content: space-between;
// justify-content: space-between;
// gap: 20rpx;
margin-bottom: 10rpx;
@@ -834,8 +897,7 @@
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 60%;
flex: 1;
}
.reply-text {