Showing
6 changed files
with
106 additions
and
26 deletions
@@ -7,7 +7,8 @@ | @@ -7,7 +7,8 @@ | ||
7 | <p class="comment-user-name" @click="toUserPage"> | 7 | <p class="comment-user-name" @click="toUserPage"> |
8 | <span class="name">{{parentComment.userName || ' '}}</span> | 8 | <span class="name">{{parentComment.userName || ' '}}</span> |
9 | </p> | 9 | </p> |
10 | - <p class="comment-time">{{parentComment.createTime | time}}</p> | 10 | + <p v-if="parentComment.createTime" class="comment-time">{{parentComment.createTime | time}}</p> |
11 | + <p v-else class="comment-time">刚刚</p> | ||
11 | </div> | 12 | </div> |
12 | <WidgetFav | 13 | <WidgetFav |
13 | class="comment-fav" | 14 | class="comment-fav" |
@@ -34,10 +35,11 @@ | @@ -34,10 +35,11 @@ | ||
34 | v-for="(reply, replyIndex) in replayShowList" | 35 | v-for="(reply, replyIndex) in replayShowList" |
35 | :key="replyIndex" | 36 | :key="replyIndex" |
36 | :dest-id="reply.id" | 37 | :dest-id="reply.id" |
38 | + :root-id="parentComment.id" | ||
37 | :add-type="1" | 39 | :add-type="1" |
38 | :user="reply.userName" | 40 | :user="reply.userName" |
39 | :column-type="columnType" | 41 | :column-type="columnType" |
40 | - @on-comment="() => onReply({destId: parentComment.id})"> | 42 | + @on-comment="onReplyChildren"> |
41 | <span class="reply-user">{{reply.userName}}</span> | 43 | <span class="reply-user">{{reply.userName}}</span> |
42 | <template v-if="reply.parentUserName"> | 44 | <template v-if="reply.parentUserName"> |
43 | <span>回复</span><em class="reply-to-user">@{{reply.parentUserName}}</em> | 45 | <span>回复</span><em class="reply-to-user">@{{reply.parentUserName}}</em> |
@@ -102,8 +104,11 @@ export default { | @@ -102,8 +104,11 @@ export default { | ||
102 | onShowMore() { | 104 | onShowMore() { |
103 | this.isShowAllReply = !this.isShowAllReply; | 105 | this.isShowAllReply = !this.isShowAllReply; |
104 | }, | 106 | }, |
105 | - async onReply({destId}) { | ||
106 | - this.$emit('on-reply', {commentId: destId}); | 107 | + onReplyChildren(info) { |
108 | + this.$emit('on-reply', info); | ||
109 | + }, | ||
110 | + async onReply(info) { | ||
111 | + this.$emit('on-reply', info); | ||
107 | }, | 112 | }, |
108 | toUserPage() { | 113 | toUserPage() { |
109 | this.$emit('on-close'); | 114 | this.$emit('on-close'); |
1 | -import {trim} from 'lodash'; | 1 | +import {get, trim} from 'lodash'; |
2 | import {createNamespacedHelpers} from 'vuex'; | 2 | import {createNamespacedHelpers} from 'vuex'; |
3 | const {mapActions} = createNamespacedHelpers('comment'); | 3 | const {mapActions} = createNamespacedHelpers('comment'); |
4 | import YAS from 'utils/yas-constants'; | 4 | import YAS from 'utils/yas-constants'; |
@@ -20,7 +20,12 @@ export default { | @@ -20,7 +20,12 @@ export default { | ||
20 | }, | 20 | }, |
21 | share: Boolean, | 21 | share: Boolean, |
22 | posId: Number, | 22 | posId: Number, |
23 | - articleId: Number | 23 | + articleId: Number, |
24 | + rootId: Number, | ||
25 | + autoUpdate: { | ||
26 | + type: Boolean, | ||
27 | + default: true | ||
28 | + }, | ||
24 | }, | 29 | }, |
25 | data() { | 30 | data() { |
26 | return { | 31 | return { |
@@ -94,13 +99,21 @@ export default { | @@ -94,13 +99,21 @@ export default { | ||
94 | }; | 99 | }; |
95 | 100 | ||
96 | if (result.code === 200) { | 101 | if (result.code === 200) { |
97 | - const waitData = this.addType === 0 ? this.fetchArticleUpdate({articleId: this.destId}) : Promise.resolve(); | 102 | + if (this.autoUpdate && this.addType === 0) { |
103 | + await this.fetchArticleUpdate({articleId: this.destId}); | ||
104 | + } | ||
98 | 105 | ||
99 | - await waitData; | ||
100 | this.$emit('on-comment', { | 106 | this.$emit('on-comment', { |
101 | destId: this.destId, | 107 | destId: this.destId, |
102 | addType: this.addType, | 108 | addType: this.addType, |
103 | - columnType: this.columnType | 109 | + columnType: this.columnType, |
110 | + comment: { | ||
111 | + content, | ||
112 | + destId: get(result, 'data', ''), | ||
113 | + columnType: this.columnType, | ||
114 | + parentId: this.addType === 1 ? this.destId : void 0, | ||
115 | + rootId: this.rootId || void 0 | ||
116 | + } | ||
104 | }); | 117 | }); |
105 | 118 | ||
106 | this.reportComment(this.destId); | 119 | this.reportComment(this.destId); |
@@ -18,7 +18,10 @@ | @@ -18,7 +18,10 @@ | ||
18 | <ArticleItemTopics class="topics-wrap" :data="topicsData" :share="share"></ArticleItemTopics> | 18 | <ArticleItemTopics class="topics-wrap" :data="topicsData" :share="share"></ArticleItemTopics> |
19 | <p class="publish-time">{{publishTime}}</p> | 19 | <p class="publish-time">{{publishTime}}</p> |
20 | <ArticleDetailCommentList ref="commentList" v-if="data.commentCount" :article-id="data.articleId" :comment-count="data.commentCount"></ArticleDetailCommentList> | 20 | <ArticleDetailCommentList ref="commentList" v-if="data.commentCount" :article-id="data.articleId" :comment-count="data.commentCount"></ArticleDetailCommentList> |
21 | - <LayoutTitle v-if="listTitle" class="rec-article-title">{{listTitle}}</LayoutTitle> | 21 | + |
22 | + <div v-if="listTitle" class="rec-article-title"> | ||
23 | + <LayoutTitle>{{listTitle}}</LayoutTitle> | ||
24 | + </div> | ||
22 | </div> | 25 | </div> |
23 | <ArticleDetailFooter class="detail-fixed-footer" v-bind="footerData" @on-comment-click="toCommentList"> | 26 | <ArticleDetailFooter class="detail-fixed-footer" v-bind="footerData" @on-comment-click="toCommentList"> |
24 | <template v-slot:before> | 27 | <template v-slot:before> |
@@ -32,6 +35,7 @@ | @@ -32,6 +35,7 @@ | ||
32 | :article-id="data.articleId" | 35 | :article-id="data.articleId" |
33 | :pos-id="0" | 36 | :pos-id="0" |
34 | :column-type="1001" | 37 | :column-type="1001" |
38 | + :autoUpdate="false" | ||
35 | @on-comment="onComment"> | 39 | @on-comment="onComment"> |
36 | 添加评论... | 40 | 添加评论... |
37 | </CommentPlaceholder> | 41 | </CommentPlaceholder> |
@@ -150,8 +154,8 @@ export default { | @@ -150,8 +154,8 @@ export default { | ||
150 | onChangeSlide({index}) { | 154 | onChangeSlide({index}) { |
151 | this.slideIndex = index; | 155 | this.slideIndex = index; |
152 | }, | 156 | }, |
153 | - onComment() { | ||
154 | - | 157 | + onComment({comment}) { |
158 | + this.$refs.commentList && this.$refs.commentList.addComment(comment); | ||
155 | }, | 159 | }, |
156 | toCommentList() { | 160 | toCommentList() { |
157 | if (this.data.commentCount) { | 161 | if (this.data.commentCount) { |
@@ -216,7 +220,7 @@ export default { | @@ -216,7 +220,7 @@ export default { | ||
216 | } | 220 | } |
217 | 221 | ||
218 | .rec-article-title { | 222 | .rec-article-title { |
219 | - margin: 14px 0 4px; | 223 | + padding: 14px 0 4px; |
220 | border-top: 1px solid #f0f0f0; | 224 | border-top: 1px solid #f0f0f0; |
221 | } | 225 | } |
222 | 226 |
1 | <template> | 1 | <template> |
2 | <div class="comment-context"> | 2 | <div class="comment-context"> |
3 | - <p class="comment-title">共{{commentCount}}条评论</p> | 3 | + <p class="comment-title">共{{totalComment}}条评论</p> |
4 | <div class="comment-list"> | 4 | <div class="comment-list"> |
5 | <CommentItem | 5 | <CommentItem |
6 | v-for="comment in commentList" | 6 | v-for="comment in commentList" |
@@ -15,19 +15,19 @@ | @@ -15,19 +15,19 @@ | ||
15 | </CommentItem> | 15 | </CommentItem> |
16 | </div> | 16 | </div> |
17 | <div v-show="showMore" class="more-comment hover-opacity" @click="onFetch"> | 17 | <div v-show="showMore" class="more-comment hover-opacity" @click="onFetch"> |
18 | - <p class="loading" v-if="onFetching"> | 18 | + <p class="loading-wrap" v-if="onFetching"> |
19 | <Loading :size="20"></Loading> | 19 | <Loading :size="20"></Loading> |
20 | 加载中 | 20 | 加载中 |
21 | </p> | 21 | </p> |
22 | - <span v-else>展开{{page > 2 ? '更多' : commentCount + '条'}}评论</span> | ||
23 | - | 22 | + <span v-else>展开{{page > 2 ? '更多' : moreCommentNum + '条'}}评论</span> |
24 | </div> | 23 | </div> |
25 | </div> | 24 | </div> |
26 | </template> | 25 | </template> |
27 | 26 | ||
28 | <script> | 27 | <script> |
28 | +import {get, forEach, find} from 'lodash'; | ||
29 | import {Loading} from 'cube-ui'; | 29 | import {Loading} from 'cube-ui'; |
30 | -import {createNamespacedHelpers} from 'vuex'; | 30 | +import {mapState as mapYohoState, mapActions as mapYohoActions, createNamespacedHelpers} from 'vuex'; |
31 | 31 | ||
32 | const {mapActions} = createNamespacedHelpers('comment'); | 32 | const {mapActions} = createNamespacedHelpers('comment'); |
33 | 33 | ||
@@ -47,13 +47,30 @@ export default { | @@ -47,13 +47,30 @@ export default { | ||
47 | commentList: [], | 47 | commentList: [], |
48 | page: 1, | 48 | page: 1, |
49 | onFetching: false, | 49 | onFetching: false, |
50 | - showMore: false | 50 | + showMore: false, |
51 | + addCommentNum: 0, | ||
52 | + moreCommentNum: 0 | ||
51 | } | 53 | } |
52 | }, | 54 | }, |
53 | mounted() { | 55 | mounted() { |
56 | + if (!this.yoho.context.userHeadIco) { | ||
57 | + this.$sdk.getUser().then(user => { | ||
58 | + if (user && user.uid) { | ||
59 | + this.fetchUserProfile(); | ||
60 | + } | ||
61 | + }); | ||
62 | + } | ||
63 | + | ||
54 | this.init(); | 64 | this.init(); |
55 | }, | 65 | }, |
66 | + computed: { | ||
67 | + ...mapYohoState(['yoho']), | ||
68 | + totalComment() { | ||
69 | + return this.commentCount + this.addCommentNum; | ||
70 | + } | ||
71 | + }, | ||
56 | methods: { | 72 | methods: { |
73 | + ...mapYohoActions(['fetchUserProfile']), | ||
57 | ...mapActions(['fetchCommentList', 'fetchReplayList', 'postComment']), | 74 | ...mapActions(['fetchCommentList', 'fetchReplayList', 'postComment']), |
58 | init() { | 75 | init() { |
59 | this.commentList.length = 0; | 76 | this.commentList.length = 0; |
@@ -62,6 +79,15 @@ export default { | @@ -62,6 +79,15 @@ export default { | ||
62 | 79 | ||
63 | this.onFetch(); | 80 | this.onFetch(); |
64 | }, | 81 | }, |
82 | + updateMoreCommentNum(list = []) { | ||
83 | + let moreCommentNum = this.commentCount; | ||
84 | + | ||
85 | + forEach(list, val => { | ||
86 | + val.childrenComments = val.childrenComments || []; | ||
87 | + moreCommentNum -= (val.childrenComments.length + 1); | ||
88 | + }); | ||
89 | + this.moreCommentNum = moreCommentNum; | ||
90 | + }, | ||
65 | async onFetch() { | 91 | async onFetch() { |
66 | if (this.onFetching || (this.page > 1 && !this.showMore)) { | 92 | if (this.onFetching || (this.page > 1 && !this.showMore)) { |
67 | return; | 93 | return; |
@@ -79,16 +105,45 @@ export default { | @@ -79,16 +105,45 @@ export default { | ||
79 | setTimeout(() => { | 105 | setTimeout(() => { |
80 | if (result.code === 200) { | 106 | if (result.code === 200) { |
81 | this.showMore = result.data.totalPage > this.page; | 107 | this.showMore = result.data.totalPage > this.page; |
108 | + this.commentList = this.commentList.concat(result.data.commentInfos || []); | ||
109 | + | ||
110 | + if (this.page === 1) { | ||
111 | + this.updateMoreCommentNum(result.data.commentInfos); | ||
112 | + } | ||
82 | 113 | ||
83 | this.page++; | 114 | this.page++; |
84 | - this.commentList = this.commentList.concat(result.data.commentInfos || []); | ||
85 | } | 115 | } |
86 | 116 | ||
87 | this.onFetching = false; | 117 | this.onFetching = false; |
88 | - }, 800); | 118 | + }, this.page > 1 ? 800 : 0); |
89 | }, | 119 | }, |
90 | - onReply() { | 120 | + onReply({comment}) { |
121 | + const parentId = comment.rootId || comment.parentId; | ||
91 | 122 | ||
123 | + forEach(this.commentList, (val, index) => { | ||
124 | + if (val.parentComment && val.parentComment.id == comment.parentId) { | ||
125 | + this.addCommentNum++; | ||
126 | + val.childrenComments.unshift(Object.assign(comment, { | ||
127 | + id: comment.destId, | ||
128 | + destId: this.articleId, | ||
129 | + headIco: this.yoho.context.userHeadIco, | ||
130 | + userName: this.yoho.context.userName, | ||
131 | + parentUserName: get(find(val.childrenComments, {id: comment.parentId}), 'userName', '') | ||
132 | + })); | ||
133 | + } | ||
134 | + }); | ||
135 | + }, | ||
136 | + addComment(comment) { | ||
137 | + this.addCommentNum++; | ||
138 | + this.commentList.unshift({ | ||
139 | + childrenComments: [], | ||
140 | + parentComment: Object.assign(comment, { | ||
141 | + id: comment.destId, | ||
142 | + destId: this.articleId, | ||
143 | + headIco: this.yoho.context.userHeadIco, | ||
144 | + userName: this.yoho.context.userName | ||
145 | + }) | ||
146 | + }); | ||
92 | } | 147 | } |
93 | }, | 148 | }, |
94 | components: { | 149 | components: { |
@@ -120,7 +175,7 @@ export default { | @@ -120,7 +175,7 @@ export default { | ||
120 | align-items: center; | 175 | align-items: center; |
121 | justify-content: center; | 176 | justify-content: center; |
122 | 177 | ||
123 | - .loading { | 178 | + .loading-wrap { |
124 | display: flex; | 179 | display: flex; |
125 | align-items: center; | 180 | align-items: center; |
126 | justify-content: center; | 181 | justify-content: center; |
@@ -17,7 +17,8 @@ export default function(state = {}) { | @@ -17,7 +17,8 @@ export default function(state = {}) { | ||
17 | path: '', | 17 | path: '', |
18 | needLogin: false, | 18 | needLogin: false, |
19 | isLogin: false, | 19 | isLogin: false, |
20 | - userHeadIco: '' | 20 | + userHeadIco: '', |
21 | + userName: '' | ||
21 | }, | 22 | }, |
22 | window: { | 23 | window: { |
23 | statusBarStatus: false, | 24 | statusBarStatus: false, |
@@ -92,8 +93,9 @@ export default function(state = {}) { | @@ -92,8 +93,9 @@ export default function(state = {}) { | ||
92 | state.window.statusBarColor = color || 'black'; | 93 | state.window.statusBarColor = color || 'black'; |
93 | } | 94 | } |
94 | }, | 95 | }, |
95 | - [Types.FETCH_USER_INFO_SUCCESS](state, {head_ico}) { | 96 | + [Types.FETCH_USER_INFO_SUCCESS](state, {head_ico, nickname}) { |
96 | state.context.userHeadIco = head_ico; | 97 | state.context.userHeadIco = head_ico; |
98 | + state.context.userName = nickname; | ||
97 | }, | 99 | }, |
98 | [Types.FETCH_USER_INFO_FAILD](state) { | 100 | [Types.FETCH_USER_INFO_FAILD](state) { |
99 | state.context.userHeadIco = ''; | 101 | state.context.userHeadIco = ''; |
@@ -12,7 +12,8 @@ module.exports = { | @@ -12,7 +12,8 @@ module.exports = { | ||
12 | auth: true, | 12 | auth: true, |
13 | params: {}, | 13 | params: {}, |
14 | fields: { | 14 | fields: { |
15 | - head_ico: {default: ''} | 15 | + head_ico: {default: ''}, |
16 | + nickname: {default: ''} | ||
16 | } | 17 | } |
17 | }, | 18 | }, |
18 | '/api/grass/labelRealtedArticleDetail': { | 19 | '/api/grass/labelRealtedArticleDetail': { |
-
Please register or login to post a comment