1
0

comment-item.vue 3.7 KB

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