44 data : {
55 bIsReady : false , // 页面是否准备就绪
66 sTopicId : '' , // 主题id
7+ oUserInfo : { } , // 当前登录用户的基本信息
78 oTopicDetail : { } // 主题详情
89 } ,
910 onLoad ( options ) {
1011 this . fnFetchTopicDetail ( options . id ) ;
1112 this . setData ( {
12- sTopicId : options . id
13+ sTopicId : options . id ,
14+ oUserInfo : wx . getStorageSync ( 'oUserInfo' ) || { }
1315 } ) ;
1416 } ,
1517 onShow ( ) {
@@ -29,6 +31,50 @@ Page({
2931 this . fnNetSwitchTopicCollectStatus ( ! this . data . oTopicDetail . is_collect ) ;
3032 }
3133 } ,
34+ // 切换评论的点赞状态
35+ fnTapLikeCommentOrDislike ( e ) {
36+ let oDataSet = e . currentTarget . dataset ;
37+ this . fnNetLikeCommentOrDislike ( oDataSet . id , oDataSet . index ) ;
38+ } ,
39+ // 切换评论的点赞状态
40+ fnNetLikeCommentOrDislike ( sCommentId , nCommentIndex ) {
41+ // 显示标题栏加载效果
42+ wx . showNavigationBarLoading ( ) ;
43+ wx . dc . reply
44+ . likeOrDislike ( {
45+ urlData : {
46+ reply_id : sCommentId
47+ }
48+ } )
49+ . then ( res => {
50+ let aCommentUps = this . data . oTopicDetail . replies [ nCommentIndex ] . ups ,
51+ oUpdateData = { } ;
52+ // 点赞评论
53+ if ( res . action === 'up' ) {
54+ // 将当前用户id,加入到该评论的点赞者列表中
55+ aCommentUps . push ( this . data . oUserInfo . id ) ;
56+ oUpdateData = {
57+ [ `oTopicDetail.replies[${ nCommentIndex } ].is_uped` ] : true ,
58+ [ `oTopicDetail.replies[${ nCommentIndex } ].ups` ] : aCommentUps
59+ } ;
60+ }
61+ // 取消点赞评论
62+ if ( res . action === 'down' ) {
63+ // 将当前用户id,从该评论的点赞者列表中移除
64+ aCommentUps = aCommentUps . filter ( sUserId => sUserId !== this . data . oUserInfo . id ) ;
65+ oUpdateData = {
66+ [ `oTopicDetail.replies[${ nCommentIndex } ].is_uped` ] : false ,
67+ [ `oTopicDetail.replies[${ nCommentIndex } ].ups` ] : aCommentUps
68+ } ;
69+ }
70+ // 更新data数据
71+ this . setData ( oUpdateData ) ;
72+ wx . hideNavigationBarLoading ( ) ;
73+ } )
74+ . catch ( ( ) => {
75+ wx . hideNavigationBarLoading ( ) ;
76+ } ) ;
77+ } ,
3278 // 切换主题收藏状态
3379 fnNetSwitchTopicCollectStatus ( bIsCollect ) {
3480 // 显示标题栏加载效果
@@ -118,11 +164,13 @@ Page({
118164 is_collect : oData . is_collect , // 是否收藏
119165 create_at : wx . moment ( oData . create_at ) . fromNow ( ) , // 创建时间
120166 content : oData . content , // 主题内容
121- reply_count : oData . reply_count // 回复数
167+ reply_count : oData . reply_count // 评论数
122168 } ;
123- // 回复列表
169+ // 评论列表
124170 oResult . replies = oData . replies . map ( oItem => {
125171 return {
172+ is_uped : oItem . is_uped , // 当前登录用户是否点赞该评论
173+ id : oItem . id , // 评论id
126174 avatar_url : oItem . author . avatar_url , // 评论者头像
127175 loginname : oItem . author . loginname , // 评论者名称
128176 create_at : wx . moment ( oItem . create_at ) . format ( 'YYYY-MM-DD HH:mm:ss' ) , // 创建时间
0 commit comments