comment-item.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class=" comment-item flex flex-col mt-30 pt-24" :class="{ 'child-comment-item': isChild, 'no-solid': !useSolid, classItem }">
  3. <view class="comment-item_user flex">
  4. <image v-if="comment.isAdmin" class="user-avatar" :src="bloggerInfo.avatar" mode="aspectFill" @error="fnOnImageError(comment)"></image>
  5. <image v-else class="user-avatar" :src="comment.avatar" mode="aspectFill" @error="fnOnImageError(comment)"></image>
  6. <view class="user-info pl-14">
  7. <view class="author">
  8. <text class="mr-6 text-grey-darken-1 text-size-m">{{ comment.author }}</text>
  9. <tm-tags v-if="comment.isAdmin" :dense="true" color="bg-gradient-amber-accent" size="xs" model="fill">博主</tm-tags>
  10. <tm-tags v-else :dense="true" color="bg-gradient-light-blue-lighten " size="xs" model="fill">游客</tm-tags>
  11. </view>
  12. <view class="flex mt-4">
  13. <view v-if="false" class="text-size-s text-grey mr-12">IP属地:浙江省杭州市</view>
  14. <view class="time text-size-xs text-grey">
  15. <text class="">{{ $tm.dayjs(comment.createTime).format('YYYY年MM月DD日') }}</text>
  16. <text class="ml-12">{{ $tm.dayjs(comment.createTime).fromNow(true) }}前</text>
  17. </view>
  18. </view>
  19. </view>
  20. <view v-if="useActions" class="">
  21. <tm-button size="s" text theme="blue" @click="$emit('on-comment', { type: 'user', comment: comment })">回复</tm-button>
  22. <tm-button size="s" text theme="grey" @click="$emit('on-copy', comment.content)">复制</tm-button>
  23. </view>
  24. </view>
  25. <view class="comment-item_content mt-12" :class="{ 'has-bg': useContentBg, 'not-ml': isChild }" @click="$emit('on-detail', comment)" v-html="comment.content"></view>
  26. <!-- <view v-if="useActions" class="comment-item_info text-size-s text-grey">
  27. <text v-if="false" @click="$emit('on-todo')">点赞</text>
  28. <text @click="$emit('on-comment', { type: 'user', comment: comment })">回复</text>
  29. <text v-if="false" class="ml-24" @click="$emit('on-todo')">举报</text>
  30. <text class="ml-24" @click="$emit('on-copy', comment.content)">复制内容</text>
  31. </view> -->
  32. </view>
  33. </template>
  34. <script>
  35. import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
  36. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  37. export default {
  38. name: 'comment-item',
  39. components: { tmTags, tmButton },
  40. props: {
  41. classItem: {
  42. type: Array,
  43. default: () => []
  44. },
  45. useActions: {
  46. type: Boolean,
  47. default: true
  48. },
  49. useSolid: {
  50. type: Boolean,
  51. default: true
  52. },
  53. useContentBg: {
  54. type: Boolean,
  55. default: true
  56. },
  57. isChild: {
  58. type: Boolean,
  59. default: false
  60. },
  61. postId: {
  62. type: Number,
  63. default: null
  64. },
  65. comment: {
  66. type: Object,
  67. default: () => {}
  68. }
  69. },
  70. computed: {
  71. // 获取博主信息
  72. bloggerInfo() {
  73. let blogger = this.$tm.vx.getters().getBlogger;
  74. blogger.avatar = this.$utils.checkAvatarUrl(blogger.avatar, true);
  75. return blogger;
  76. }
  77. },
  78. methods: {
  79. fnOnImageError(data) {
  80. if (data.isAdmin) {
  81. data.avatar = this.$haloConfig.author.avatar;
  82. } else {
  83. data.avatar = `${this.$haloConfig.defaultAvatarUrl}&rt=${new Date().getTime()}`;
  84. }
  85. }
  86. }
  87. };
  88. </script>
  89. <style scoped lang="scss">
  90. .comment-item {
  91. box-sizing: border-box;
  92. border-top: 2rpx solid #f5f5f5;
  93. &.child-comment-item {
  94. padding-top: 0;
  95. margin-left: 80rpx;
  96. border: 0;
  97. }
  98. &.no-solid {
  99. border: 0;
  100. margin-top: 0 !important;
  101. }
  102. &_user {
  103. display: flex;
  104. align-items: center;
  105. .user-avatar {
  106. width: 70rpx;
  107. height: 70rpx;
  108. border-radius: 50%;
  109. box-sizing: border-box;
  110. border: 4rpx solid #ffffff;
  111. box-shadow: 0rpx 2rpx 24rpx rgba(0, 0, 0, 0.05);
  112. }
  113. .user-info {
  114. width: 0;
  115. flex-grow: 1;
  116. }
  117. }
  118. &_content {
  119. font-size: 28rpx;
  120. margin-left: 80rpx;
  121. box-sizing: border-box;
  122. border-radius: 10rpx;
  123. line-height: 1.8;
  124. color: var(--main-text-color);
  125. &.has-bg {
  126. background-color: #fafafa;
  127. padding: 6rpx 24rpx;
  128. }
  129. &.not-ml {
  130. margin-left: 80rpx;
  131. }
  132. }
  133. &_info {
  134. margin-top: 6rpx;
  135. display: flex;
  136. align-items: center;
  137. margin-left: 80rpx;
  138. }
  139. }
  140. </style>