comment-item.vue 3.5 KB

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