comment-list.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view class="comment-list">
  3. <view v-if="showIcon" class="icon-wrapper">
  4. <image
  5. :src="$static('images/oa/log_comment.png')"
  6. class="icon-pic" />
  7. </view>
  8. <view class="wrapper">
  9. <view
  10. v-for="item in replyList"
  11. :key="item.commentId"
  12. class="comment-item"
  13. @click.stop="handleChoose(item, $event)">
  14. <template v-if="showAvatar">
  15. <view class="avatar-wrapper">
  16. <wk-avatar
  17. :avatar="item.user.img"
  18. :name="item.user.realname"
  19. :size="12"
  20. :preview="false"
  21. class="avatar" />
  22. <view class="username">
  23. {{ item.user.realname }}
  24. </view>
  25. <view class="time">
  26. {{ item.createTime | formatTime }}
  27. </view>
  28. </view>
  29. <view class="content-text">
  30. {{ item.content }}
  31. </view>
  32. </template>
  33. <template v-else>
  34. <view class="content">
  35. <text class="username">
  36. {{ item.user.realname }}:
  37. </text>
  38. <text class="content-text">
  39. {{ item.content }}
  40. </text>
  41. </view>
  42. <view class="time">
  43. {{ item.createTime | formatTime }}
  44. </view>
  45. </template>
  46. <view
  47. v-if="!$isEmpty(item.childCommentList)"
  48. class="child-comment">
  49. <view
  50. v-for="child in item.childCommentList"
  51. :key="child.commentId"
  52. class="comment-item"
  53. @click.stop="handleChoose(child, $event)">
  54. <view class="content">
  55. <text class="username">
  56. {{ child.user.realname }}
  57. </text>
  58. <text class="reply-text">
  59. 回复
  60. </text>
  61. <text class="username">
  62. {{ child.replyUser.realname }}:
  63. </text>
  64. <text class="content-text">
  65. {{ child.content }}
  66. </text>
  67. </view>
  68. <view class="time">
  69. {{ child.createTime | formatTime }}
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import moment from 'moment'
  79. export default {
  80. name: 'CommentList',
  81. filters: {
  82. formatTime(data) {
  83. if (!data) return ''
  84. return moment(data).format('MM-DD HH:mm')
  85. }
  86. },
  87. props: {
  88. replyList: {
  89. type: Array,
  90. default: () => []
  91. },
  92. showIcon: {
  93. type: Boolean,
  94. default: true
  95. },
  96. showAvatar: {
  97. type: Boolean,
  98. default: true
  99. }
  100. },
  101. methods: {
  102. handleChoose(item, evt) {
  103. this.$emit('choose', item, evt)
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .comment-list {
  110. position: relative;
  111. width: 100%;
  112. overflow: hidden;
  113. .icon-wrapper {
  114. position: absolute;
  115. top: 0;
  116. left: 0;
  117. .icon-pic {
  118. width: 36rpx;
  119. height: 36rpx;
  120. margin: 8rpx 0;
  121. }
  122. }
  123. .wrapper {
  124. width: 100%;
  125. overflow: hidden;
  126. padding-left: 50rpx;
  127. .comment-item {
  128. padding: 15rpx 0;
  129. &:first-child {
  130. padding-top: 0;
  131. }
  132. .content-text {
  133. color: $dark;
  134. font-size: $wk-font-base;
  135. word-wrap: break-word;
  136. white-space: pre-wrap;
  137. }
  138. .avatar-wrapper {
  139. margin-bottom: 20rpx;
  140. @include left;
  141. .avatar {
  142. width: 60rpx;
  143. height: 60rpx;
  144. margin-right: 20rpx;
  145. }
  146. .username {
  147. flex: 1;
  148. @include ellipsis;
  149. }
  150. .time {
  151. font-size: 24rpx;
  152. color: #AAAAAA;
  153. margin-left: 10rpx;
  154. }
  155. }
  156. .content {
  157. margin-bottom: 5rpx;
  158. .username {
  159. color: $theme-color;
  160. font-size: $wk-font-base;
  161. }
  162. .reply-text {
  163. color: $dark;
  164. font-size: $wk-font-base;
  165. }
  166. }
  167. .time {
  168. font-size: 24rpx;
  169. color: #AAAAAA;
  170. }
  171. }
  172. .child-comment {
  173. border-radius: 4rpx;
  174. background-color: #F5F5F5;
  175. padding: 15rpx 20rpx 0 50rpx;
  176. margin: 15rpx 0 0 -50rpx;
  177. }
  178. }
  179. }
  180. </style>