comment-item.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. imageConfigs() {
  74. return this.$tm.vx.getters().getConfigs.imagesConfig;
  75. },
  76. bloggerInfo() {
  77. let blogger = this.$tm.vx.getters().getConfigs.authorConfig.blogger;
  78. blogger.avatar = this.$utils.checkAvatarUrl(blogger.avatar, true);
  79. return blogger;
  80. }
  81. },
  82. methods: {
  83. fnOnImageError(data) {
  84. if (data && data.owner) {
  85. if (this.imageConfigs.defaultAvatarUrl.indexOf('?') == -1) {
  86. data.owner.avatar = `${this.imageConfigs.defaultAvatarUrl}?next-v=${new Date().getTime()}`
  87. } else {
  88. data.owner.avatar = `${this.imageConfigs.defaultAvatarUrl}&next-v=${new Date().getTime()}`
  89. }
  90. }
  91. }
  92. },
  93. created() {
  94. console.log("comment", this.comment)
  95. }
  96. };
  97. </script>
  98. <style scoped lang="scss">
  99. .comment-item {
  100. box-sizing: border-box;
  101. border-top: 2rpx solid #f5f5f5;
  102. &.child-comment-item {
  103. padding-top: 0;
  104. margin-left: 80rpx;
  105. border: 0;
  106. }
  107. &.no-solid {
  108. border: 0;
  109. margin-top: 0 !important;
  110. }
  111. &_user {
  112. display: flex;
  113. align-items: center;
  114. .user-avatar {
  115. width: 70rpx;
  116. height: 70rpx;
  117. box-sizing: border-box;
  118. box-shadow: 0rpx 2rpx 24rpx rgba(0, 0, 0, 0.05);
  119. border: 4rpx solid #ffffff;
  120. border-radius: 12rpx;
  121. &.is-radius {
  122. border-radius: 50%;
  123. }
  124. }
  125. .user-info {
  126. width: 0;
  127. flex-grow: 1;
  128. }
  129. }
  130. &_content {
  131. font-size: 28rpx;
  132. margin-left: 80rpx;
  133. box-sizing: border-box;
  134. border-radius: 10rpx;
  135. line-height: 1.8;
  136. color: var(--main-text-color);
  137. &.has-bg {
  138. background-color: #fafafa;
  139. padding: 6rpx 24rpx;
  140. }
  141. &.not-ml {
  142. margin-left: 80rpx;
  143. }
  144. }
  145. &_info {
  146. margin-top: 6rpx;
  147. display: flex;
  148. align-items: center;
  149. margin-left: 80rpx;
  150. }
  151. }
  152. </style>