common.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view class="comment_item">
  3. <img class="user_avatar" @click="goToUserHomepage(data.user_id)" :src="data.user_avatar" />
  4. <view class="comment_content">
  5. <view class="top">
  6. <view class="top_left" @click="goToUserHomepage(data.user_id)">
  7. <uni-tag v-if="data.author" class="tag" type="primary" :inverted="false" text="作者" size="mini" circle />
  8. <span class="user_name">{{ data.user_name }}</span>
  9. <span class="user_name cReplyName" v-if="cReplyName">▸</span>
  10. <span class="user_name">{{ cReplyName }}</span>
  11. </view>
  12. </view>
  13. <view class="content" @click="replyClick(data)">
  14. {{ c_content }}
  15. <span class="shrink" v-if="isShrink" @click.stop="expandContentFun(data.user_content)">...展开</span>
  16. <span class="shrink" v-if="!isShrink && user_content.length > contentShowLength"
  17. @click.stop="shrinkContentFun(data.user_content)">
  18. 收起</span>
  19. </view>
  20. <view class="bottom">
  21. <view>
  22. <span class="create_time">{{ data.create_time }}</span>
  23. <span v-if="data.owner" class="delete" @click="deleteClick(data)">删除</span>
  24. </view>
  25. <!-- <span v-else class="reply" @click="replyClick(props.data)"
  26. >回复</span
  27. > -->
  28. <view class="bottom_right" @click="likeClick(data)">
  29. <image style="width: 32rpx; height: 32rpx;" v-show="!data.is_like" src="@/static/icon/icon-19.png"></image>
  30. <image style="width: 32rpx; height: 32rpx;" v-show="data.is_like" src="@/static/icon/icon-18.png"></image>
  31. <span :class="[data.is_like ? 'active' : '', 'like_count']">{{ cLikeCount }}</span>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. props: {
  40. // 评论数据
  41. data: {
  42. type: Object,
  43. default: () => { },
  44. },
  45. },
  46. data() {
  47. return {
  48. // 评论过长处理
  49. contentShowLength: 70, // 默认显示评论字符
  50. user_content: "",
  51. isShrink: false, // 是否收缩评论
  52. c_content: "",
  53. };
  54. },
  55. computed: {
  56. // 被回复人名称
  57. cReplyName: function () {
  58. return this.data?.reply_name ? this.data?.reply_name : "";
  59. },
  60. // 点赞数显示
  61. cLikeCount: function () {
  62. return this.data.like_count === 0 ? "" : this.data.like_count > 99 ? `99+` : this.data.like_count;
  63. },
  64. },
  65. watch: {
  66. // 删除变更显示定制
  67. "data.user_content": function (newVal, oldVal) {
  68. if (newVal !== oldVal) {
  69. this.c_content = newVal;
  70. }
  71. },
  72. // 监听isShrink变化,更新c_content
  73. isShrink: function (newVal) {
  74. this.c_content = newVal ? this.user_content.slice(0, this.contentShowLength + 1) : this.user_content;
  75. },
  76. },
  77. methods: {
  78. // 展开文字
  79. expandContentFun() {
  80. this.isShrink = false;
  81. },
  82. // 收起文字
  83. shrinkContentFun() {
  84. this.isShrink = true;
  85. },
  86. // 点赞
  87. likeClick(item) {
  88. this.$emit("likeClick", item);
  89. },
  90. // 回复
  91. replyClick(item) {
  92. // 自己不能回复自己
  93. // if (item.owner) return;
  94. this.$emit("replyClick", item);
  95. },
  96. // 删除
  97. deleteClick(item) {
  98. this.$emit("deleteClick", item);
  99. },
  100. goToUserHomepage(id) {
  101. uni.$emit('check_login', () => {
  102. if (!id) {
  103. return;
  104. }
  105. uni.navigateTo({
  106. url: "/pages/my/userHomepage?id=" + id,
  107. });
  108. })
  109. },
  110. },
  111. mounted() {
  112. this.user_content = this.data.user_content;
  113. this.isShrink = this.user_content.length > this.contentShowLength;
  114. this.c_content = this.isShrink ? this.user_content.slice(0, this.contentShowLength + 1) : this.user_content;
  115. },
  116. };
  117. </script>
  118. <style lang="scss" scoped>
  119. ////////////////////
  120. .center {
  121. display: flex;
  122. align-items: center;
  123. }
  124. .ellipsis {
  125. overflow: hidden;
  126. white-space: nowrap;
  127. text-overflow: ellipsis;
  128. }
  129. ////////////////////
  130. .comment_item {
  131. font-size: 28rpx;
  132. display: flex;
  133. align-items: flex-start;
  134. justify-content: space-between;
  135. width: 100%;
  136. margin-top: 16rpx;
  137. .user_avatar {
  138. width: 68rpx;
  139. height: 68rpx;
  140. border-radius: 50%;
  141. margin-right: 20rpx;
  142. }
  143. .comment_content {
  144. display: flex;
  145. flex-direction: column;
  146. justify-content: space-between;
  147. width: 100%;
  148. }
  149. .top {
  150. @extend .center;
  151. justify-content: space-between;
  152. width: 100%;
  153. .top_left {
  154. display: flex;
  155. align-items: flex-start;
  156. overflow: hidden;
  157. .tag {
  158. margin-right: 6rpx;
  159. }
  160. .user_name {
  161. @extend .ellipsis;
  162. max-width: 180rpx;
  163. color: #8c8c8c;
  164. }
  165. }
  166. .top_right {
  167. @extend .center;
  168. margin-left: auto;
  169. min-width: 60rpx;
  170. justify-content: flex-end;
  171. .like_count {
  172. color: #8c8c8c;
  173. &.active {
  174. color: #8de10b;
  175. }
  176. }
  177. }
  178. }
  179. .content {
  180. padding: 12rpx;
  181. padding-left: 0;
  182. color: #1f1f1f;
  183. font-family: "PingFang SC Bold";
  184. font-weight: 400;
  185. &:active {
  186. background-color: #f2f2f2;
  187. }
  188. .shrink {
  189. padding: 20rpx 20rpx 20rpx 0rpx;
  190. color: #007aff;
  191. }
  192. }
  193. .bottom {
  194. font-size: 24rpx;
  195. display: flex;
  196. align-items: center;
  197. justify-content: space-between;
  198. .create_time {
  199. color: #8c8c8c;
  200. }
  201. .delete {
  202. padding: 20rpx 20rpx 0 20rpx;
  203. color: #c0c0c0;
  204. }
  205. .reply {
  206. color: #007aff;
  207. }
  208. .bottom_right {
  209. @extend .center;
  210. margin-left: auto;
  211. min-width: 60rpx;
  212. justify-content: flex-end;
  213. .like_count {
  214. color: #8c8c8c;
  215. &.active {
  216. color: #8de10b;
  217. }
  218. }
  219. }
  220. }
  221. .cReplyName{
  222. display: inline-block;
  223. padding: 0 6rpx;
  224. }
  225. }
  226. </style>