Authored by yyq

commit

@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 <Loading></Loading> 6 <Loading></Loading>
7 </div> 7 </div>
8 <Scroll v-else ref="scroll" :data="commentList" :scroll-events="['scroll', 'scroll-end']" :options="scrollOption" @scroll="onScrollHandle" @scroll-end="onScrollEndHandle" @pulling-up="onPullingUp"> 8 <Scroll v-else ref="scroll" :data="commentList" :scroll-events="['scroll', 'scroll-end']" :options="scrollOption" @scroll="onScrollHandle" @scroll-end="onScrollEndHandle" @pulling-up="onPullingUp">
9 - <div class="comment-list"> 9 + <div ref="commentList" class="comment-list">
10 <div ref="commentListTop" class="comment-list-top"> 10 <div ref="commentListTop" class="comment-list-top">
11 <div ref="commentPre" class="comment-pre-list"> 11 <div ref="commentPre" class="comment-pre-list">
12 <div 12 <div
@@ -29,6 +29,7 @@ @@ -29,6 +29,7 @@
29 <CommentItem 29 <CommentItem
30 v-for="comment in commentList" 30 v-for="comment in commentList"
31 :key="comment.parentComment.id" 31 :key="comment.parentComment.id"
  32 + :class="'comment-' + comment.parentComment.id"
32 :parent-comment="comment.parentComment" 33 :parent-comment="comment.parentComment"
33 :children-comments="comment.childrenComments" 34 :children-comments="comment.childrenComments"
34 :column-type="columnType" 35 :column-type="columnType"
@@ -165,6 +166,18 @@ export default { @@ -165,6 +166,18 @@ export default {
165 } else { 166 } else {
166 if (this.page <= 2) { 167 if (this.page <= 2) {
167 this.commentList = comments; 168 this.commentList = comments;
  169 +
  170 + // 将评论滚动到可视区域
  171 + if (this.commentId) {
  172 + setTimeout(() => {
  173 + let scrollHeight = this.$refs.scroll.$el.offsetHeight;
  174 + let dom = this.$refs.commentList.getElementsByClassName('comment-' + this.commentId);
  175 +
  176 + if (scrollHeight && dom.length && (dom[0].offsetHeight + dom[0].offsetoffsetTop > scrollHeight)) {
  177 + this.$refs.scroll.scrollTo(0, scrollHeight - this.$refs.commentList.offsetoffsetTop);
  178 + }
  179 + }, 500);
  180 + }
168 } else { 181 } else {
169 this.commentList = this.commentList.concat(comments); 182 this.commentList = this.commentList.concat(comments);
170 } 183 }