Commit 3918d90d authored by liwei's avatar liwei

完成了基础评论功能

parent c22294db
...@@ -39,7 +39,16 @@ export function getOssUrl(id) { ...@@ -39,7 +39,16 @@ export function getOssUrl(id) {
//查看动态详情 //查看动态详情
export function articleDetail(articleId){ export function articleDetail(articleId){
return request({ return request({
url: '/opmarticle/detail/' + articleId, url: '/app/open/opmArticle/detail/' + articleId,
method: 'GET', method: 'GET',
}) })
} }
//动态评论
export function comment(data) {
return request({
url: '/opmarticle/comment',
data: data,
method: 'POST',
})
}
<template> <template>
<div> <view style="margin-bottom: 150rpx">
<view> <view>
<ArticleItem @delete="deleteFn" :info="articleInfo" @selectShare="selectShare(item)" @praise="praise" <ArticleItem @delete="deleteFn" :info="articleInfo" @praise="praise"
@close="close" @open="open"/> @close="close" @open="open"/>
</view> </view>
<view class="commentTitle"> <view class="commentTitle">
...@@ -25,26 +25,25 @@ ...@@ -25,26 +25,25 @@
<div class="c-comment">{{ info.content }}</div> <div class="c-comment">{{ info.content }}</div>
<div class="c-actions"> <div class="c-actions">
<div class="c-time">{{ info.createDate }}</div> <div class="c-time">{{ info.createDate }}</div>
<div class="action-item"> <!-- <div class="action-item">-->
<image <!-- <image-->
:src="baseUrl+'/article/104.png'" <!-- :src="baseUrl+'/article/104.png'"-->
@click="btnComment(info)" <!-- @click="btnComment(info)"-->
></image> <!-- ></image>-->
<text> <!-- <text>-->
{{ info.replyCount }} <!-- {{ info.replyCount }}-->
</text> <!-- </text>-->
</div> <!-- </div>-->
<div class="action-item"> <!-- <div class="action-item">-->
<image <!-- <image-->
@click="btnPrarse(info)" <!-- @click="btnPrarse(info)"-->
:src=" <!-- :src="info.isLike == '0'-->
info.praise <!-- ? baseUrl+'/article/105.png'-->
? baseUrl+'/article/105.png' <!-- : baseUrl+'/article/105-no.png'-->
: baseUrl+'/article/105-no.png' <!-- "-->
" <!-- ></image>-->
></image> <!-- {{ info.likeCount }}-->
{{ info.likeCount }} <!-- </div>-->
</div>
</div> </div>
<!-- <div v-if="info.childrenCommentInfos.length > 0">--> <!-- <div v-if="info.childrenCommentInfos.length > 0">-->
<!-- <div v-if="info.contentAll">--> <!-- <div v-if="info.contentAll">-->
...@@ -158,7 +157,7 @@ ...@@ -158,7 +157,7 @@
placeholder="走心,说点好听的" placeholder="走心,说点好听的"
border="surround" border="surround"
v-model="commentValue" v-model="commentValue"
@change="change" @confirm="handleEnter"
customStyle="border-radius:36rpx;height:45rpx;background-color:rgb(249, 250, 251);width:60%" customStyle="border-radius:36rpx;height:45rpx;background-color:rgb(249, 250, 251);width:60%"
></u--input> ></u--input>
<view class="bottom-button-area"> <view class="bottom-button-area">
...@@ -179,7 +178,7 @@ ...@@ -179,7 +178,7 @@
<view class="bottom-button"> <view class="bottom-button">
<image <image
@click="" @click=""
:src="info.praise :src="articleInfo.isLike == '0'
? baseUrl+'/article/105.png' ? baseUrl+'/article/105.png'
: baseUrl+'/article/105-no.png'" : baseUrl+'/article/105-no.png'"
></image> ></image>
...@@ -187,12 +186,12 @@ ...@@ -187,12 +186,12 @@
</view> </view>
</view> </view>
</view> </view>
</div> </view>
</template> </template>
<script> <script>
import ArticleItem from './components/articleItem.vue' import ArticleItem from './components/articleItem.vue'
import {articleDetail} from '../api/article/index' import {articleDetail, comment, getOssUrl} from '../api/article/index'
import {getCity, getValue} from "../common/options"; import {getCity, getValue} from "../common/options";
import {calculateAge, parseDate} from "../common"; import {calculateAge, parseDate} from "../common";
export default{ export default{
...@@ -203,83 +202,8 @@ export default{ ...@@ -203,83 +202,8 @@ export default{
return { return {
//图片路径 //图片路径
baseUrl: this.$IMG_URL, baseUrl: this.$IMG_URL,
item:{ //评论值
createTime:'2024-12-28 15:02:01',
headPortrait:'http://192.168.1.80/upload/CmsBanner/20241230/18E63B570FF04DB3A8EFE277D58256C4.jpg',//头像
nickName:'不爱吃辣的小王',//nickName
gender:'MALE',//性别
information:'02·重庆市·硕士·互联网',//个人信息
content:'昨天的快乐留在今天发,那就是100%',//动态内容
time:'2024-11-11 15:02:01',//发布动态的时间
commentCount:'10',//评论数
likeCount:'11',//点赞数
img:[
'http://192.168.1.80/upload/CmsBanner/20241230/18E63B570FF04DB3A8EFE277D58256C4.jpg',
'http://192.168.1.80/upload/CmsBanner/20241230/18E63B570FF04DB3A8EFE277D58256C4.jpg'
]
},
commentValue:'', commentValue:'',
commentChildren:[
{
id:'1',
avatar:'http://192.168.1.80/upload/CmsBanner/20241230/18E63B570FF04DB3A8EFE277D58256C4.jpg',
nickName:'不吃鱼的猫',
content:'11111111111111111111',
createTime:'2024-05-02 15:24:01',
likesNumber:'1',
contentAll:false,
childrenCommentInfos:[
{
id: '1',
avatar: 'http://192.168.1.80/upload/CmsBanner/20241230/18E63B570FF04DB3A8EFE277D58256C4.jpg',
nickName: '不吃鱼的猫11111',
content: '111111111111111111111111111',
createTime: '2024-05-02 15:24:01',
likesNumber: '1',
beRepliedName:'不吃鱼的猫'
},
{
id: '1',
avatar: 'http://192.168.1.80/upload/CmsBanner/20241230/18E63B570FF04DB3A8EFE277D58256C4.jpg',
nickName: '不吃鱼的猫11111',
content: '111111111111111111111111111',
createTime: '2024-05-02 15:24:01',
likesNumber: '1',
beRepliedName:'不吃鱼的猫'
},
{
id: '1',
avatar: 'http://192.168.1.80/upload/CmsBanner/20241230/18E63B570FF04DB3A8EFE277D58256C4.jpg',
nickName: '不吃鱼的猫11111',
content: '111111111111111111111111111',
createTime: '2024-05-02 15:24:01',
likesNumber: '1',
beRepliedName:'不吃鱼的猫'
}
]
},
{
id:'1',
avatar:'http://192.168.1.80/upload/CmsBanner/20241230/18E63B570FF04DB3A8EFE277D58256C4.jpg',
nickName:'不吃鱼的猫',
content:'11111111111111111111',
createTime:'2024-05-02 15:24:01',
likesNumber:'1',
contentAll:false,
childrenCommentInfos:[
{
id: '1',
avatar: 'http://192.168.1.80/upload/CmsBanner/20241230/18E63B570FF04DB3A8EFE277D58256C4.jpg',
nickName: '不吃鱼的猫11111',
content: '111111111111111111111111111',
createTime: '2024-05-02 15:24:01',
likesNumber: '1',
beRepliedName:'不吃鱼的猫'
}
]
}
],
flag: false,
//动态id //动态id
articleId:'', articleId:'',
//动态详情 //动态详情
...@@ -291,93 +215,78 @@ export default{ ...@@ -291,93 +215,78 @@ export default{
this.getArticleDetail() this.getArticleDetail()
}, },
methods: { methods: {
//评论回车事件
handleEnter(value){
if (this.commentValue === ''){
uni.showToast({
title: '评论内容不能为空',
icon: 'none'
})
return;
}
this.commentValue = ''
const params = {
articleId: this.articleInfo.businessId,
commentContent:value
}
comment(params).then(res=>{
if (res.data.code == 200){
this.getArticleDetail()
}
}).catch(err=>{
uni.showToast({
title: '评论失败,请稍后再试',
icon: 'none'
})
})
},
getArticleDetail(){ getArticleDetail(){
articleDetail(this.articleId).then(res=>{ articleDetail(this.articleId).then(res=>{
this.articleInfo = res.data.data this.articleInfo = res.data.data
//处理动态图片 //处理动态图片
if (res.data.data.url != null){ if (res.data.data.pictureId != null){
this.articleInfo.url = res.data.data.url.replace(/\\/g, '/').split(',') const urlArray = JSON.parse(res.data.data.pictureId)
let arr = []
urlArray.id.forEach(item => {
getOssUrl(item).then(res => {
arr.push(res.data.data)
})
})
this.articleInfo.url = arr
} }
//处理头像 //处理头像
if (res.data.data.memAvatar != null){ if (res.data.data.avatarId != null){
this.articleInfo.memAvatar = res.data.data.memAvatar.replace(/\\/g, '/').split(',') getOssUrl(res.data.data.avatarId).then(res => {
this.articleInfo.memAvatar = res.data.data
})
} }
//处理学历 //处理学历
this.articleInfo.memMaxEducation = getValue('education',res.data.data.memMaxEducation) if (res.data.data.memMaxEducation != null && res.data.data.memMaxEducation !== ''){
this.articleInfo.memMaxEducation = getValue('education',res.data.data.memMaxEducation)
}
//处理性别 //处理性别
this.articleInfo.memSex = getValue('sex',res.data.data.memSex) if (res.data.data.memSex != null && res.data.data.memSex !== ''){
this.articleInfo.memSex = getValue('sex',res.data.data.memSex)
}
//处理地址 //处理地址
this.articleInfo.city = getCity(res.data.data.memResidenceProvince,res.data.data.memResidenceCity) if (res.data.data.memResidenceProvince != null && res.data.data.memResidenceProvince != '' && res.data.data.memResidenceCity != null && res.data.data.memResidenceCity != ''){
this.articleInfo.city = getCity(res.data.data.memResidenceProvince,res.data.data.memResidenceCity)
}
//通过生日计算年龄 //通过生日计算年龄
const dataItem = parseDate(res.data.data.memBirthday) if (res.data.data.memBirthday != null && res.data.data.memBirthday != ''){
this.articleInfo.memAge = calculateAge(dataItem.year,dataItem.month,dataItem.day) const dataItem = parseDate(res.data.data.memBirthday)
this.articleInfo.memAge = calculateAge(dataItem.year,dataItem.month,dataItem.day)
}
//处理评论的头像 //处理评论的头像
if (this.articleInfo.articleCommentVOList != null && this.articleInfo.articleCommentVOList.length > 0){ if (this.articleInfo.articleCommentVOList != null && this.articleInfo.articleCommentVOList.length > 0){
this.articleInfo.articleCommentVOList.forEach(item => { this.articleInfo.articleCommentVOList.forEach(item => {
item.avatarUrl = item.avatarUrl.replace(/\\/g, '/') getOssUrl(item.avatarId).then(res =>{
item.avatarUrl = res.data.data
})
}) })
} }
}) })
}, },
changeAllFun(info) {
// console.log(info)
// let list = this.commentChildren
// console.log(list)
// list.forEach((elem) => {
// console.log(elem.id == info.id)
// if (elem.id == info.id) {
// elem.contentAll = !elem.contentAll
// }
// })
// uni.setStorageSync("commentList", list)
// bus.$emit('resComList');
},
btnComment (item) {
// bus.$emit('item', item);
},
btnPrarse (info) {
// let list = uni.getStorageSync('commentList')
// let optType = null
// info.praise ? optType = 1 : optType = 0
// let parmars = {
// optType: optType,
// strategyCommentId: info.id,
// }
//
// likeOrDislikeStrategy(parmars).then(res => {
// if (res.code == 200) {
// this.seachId(list, info.id)
// }
// else {
// this.$toast(res.msg)
// }
// })
},
seachId (list, id) {
// let result = null
// for (let i = 0; i < list.length; i++) {
// if (result !== null) {
// break //跳出循环的关键
// }
// if (list[i].id === id) {
// let res = list[i].nickName;
// result = res //取值关键
// list[i].praise = !list[i].praise
// if (list[i].praise) {
// list[i].likesNumber++
// } else {
// list[i].likesNumber--
// }
// break
// } else if (list[i].childrenCommentInfos) {//递归条件
// this.seachId(list[i].childrenCommentInfos, id);
// } else {
// continue
// }
// }
// uni.setStorageSync("commentList", list)
// bus.$emit('resComList');
}
}, },
} }
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment