comment-list.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view class="comment-list">
  3. <!-- 顶部区域 -->
  4. <view class="comment-list_head">
  5. <view class="title">
  6. <text>评论列表</text>
  7. <text class="count">({{ (result && result.total) || 0 }}条)</text>
  8. </view>
  9. </view>
  10. <!-- 内容区域 -->
  11. <view class="comment-list_content">
  12. <view v-if="loading !== 'success'" class="loading-wrap flex">
  13. <view v-if="loading === 'loading'" class="loading flex flex-center flex-col">
  14. <text class="e-loading-icon iconfont icon-loading text-blue"></text>
  15. <view class="text-size-n text-grey-lighten-1 py-12 mt-12">加载中,请稍等...</view>
  16. </view>
  17. <view v-else-if="loading === 'error'" class="error">
  18. <tm-empty icon="icon-wind-cry" label="加载失败">
  19. <tm-button theme="bg-gradient-light-blue-accent" size="m" v-if="!disallowComment"
  20. @click="fnToComment()">刷新试试
  21. </tm-button>
  22. </tm-empty>
  23. </view>
  24. </view>
  25. <block v-else>
  26. <tm-alerts v-if="disallowComment && dataList.length !== 0" color="red" text :margin="[0, 0]" :shadow="0"
  27. label="Ծ‸Ծ博主已设置该文章禁止评论!" :round="3"></tm-alerts>
  28. <view class="empty pt-50" v-if="dataList.length === 0">
  29. <tm-empty v-if="disallowComment" icon="icon-shiliangzhinengduixiang-" label="暂无评论">
  30. <text class="text-red text-size-s">- 文章已开启禁止评论 -</text>
  31. </tm-empty>
  32. <tm-empty v-else icon="icon-shiliangzhinengduixiang-" label="暂无评论">
  33. <tm-button theme="light-blue" :dense="true" :shadow="0" size="m"
  34. @click="fnToComment(null)">抢沙发
  35. </tm-button>
  36. </tm-empty>
  37. </view>
  38. <block v-else>
  39. <!-- 评论内容 : 目前仅支持二级评论 -->
  40. <block v-for="(comment, index) in dataList" :key="comment.metadata.name">
  41. <comment-item :useContentBg="false" :isChild="false" :comment="comment" :postName="postName"
  42. :disallowComment="disallowComment" @on-copy="fnCopyContent" @on-comment="fnToComment"
  43. @on-todo="fnToDo" @on-detail="fnShowCommentDetail"></comment-item>
  44. <!-- 二级评论 -->
  45. <block v-if="comment.replies && comment.replies.items.length !== 0">
  46. <block v-for="(childComment, childIndex) in comment.replies.items"
  47. :key="childComment.metadata.name">
  48. <comment-item :useContentBg="false" :isChild="true" :comment="childComment"
  49. :postName="postName" :disallowComment="disallowComment" @on-copy="fnCopyContent"
  50. @on-comment="fnToComment" @on-todo="fnToDo"
  51. @on-detail="fnShowCommentDetail"></comment-item>
  52. </block>
  53. </block>
  54. </block>
  55. <view v-if="false" class="to-more-comment">
  56. <tm-button item-class="btn" :block="true" width="90vw" theme="bg-gradient-light-blue-lighten"
  57. size="m">点击查看全部评论
  58. </tm-button>
  59. </view>
  60. </block>
  61. </block>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  67. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  68. import tmAlerts from '@/tm-vuetify/components/tm-alerts/tm-alerts.vue';
  69. export default {
  70. name: 'comment-list',
  71. components: {
  72. tmEmpty,
  73. tmButton,
  74. tmAlerts
  75. },
  76. props: {
  77. // 是否禁用评论
  78. disallowComment: {
  79. type: Boolean,
  80. default: false
  81. },
  82. postName: {
  83. type: String,
  84. default: ""
  85. },
  86. post: {
  87. type: Object,
  88. default: () => {
  89. }
  90. }
  91. },
  92. data() {
  93. return {
  94. loading: 'loading',
  95. queryParams: {
  96. group: "content.halo.run",
  97. kind: "Post",
  98. version: "v1alpha1",
  99. name: "",
  100. page: 1,
  101. size: 50,
  102. withReplies: true,
  103. replySize: 10
  104. },
  105. result: null,
  106. dataList: []
  107. };
  108. },
  109. created() {
  110. this.queryParams.name = this.postName;
  111. this.fnGetData();
  112. uni.$on('comment_list_refresh', () => {
  113. this.fnOnSort(true);
  114. });
  115. },
  116. methods: {
  117. fnOnSort(refresh = false) {
  118. if (refresh === false) return;
  119. this.fnGetData();
  120. },
  121. fnGetData() {
  122. this.loading = 'loading';
  123. this.$httpApi.v2.getPostCommentList(this.queryParams)
  124. .then(res => {
  125. console.log("日志:", res)
  126. this.result = res;
  127. this.dataList = res.items;
  128. this.loading = 'success';
  129. this.$emit('on-loaded', this.dataList);
  130. })
  131. .catch(err => {
  132. this.loading = 'error';
  133. })
  134. .finally(() => {
  135. uni.hideLoading();
  136. });
  137. },
  138. fnToDo() {
  139. uni.$tm.toast('Halo暂未支持!');
  140. },
  141. fnToComment(data) {
  142. if (this.disallowComment) {
  143. return uni.$tm.toast('文章已禁止评论!');
  144. }
  145. let _comment = {};
  146. if (data) {
  147. let {
  148. type,
  149. comment
  150. } = data;
  151. // 来自用户
  152. _comment = {
  153. isComment: false,
  154. postName: comment.metadata.name,
  155. title: comment.owner.displayName,
  156. from: 'posts',
  157. formPage: 'comment_list',
  158. type: 'user'
  159. };
  160. } else {
  161. // 来自文章
  162. _comment = {
  163. isComment: true,
  164. postName: this.post.metadata.name,
  165. title: '评论文章:' + this.post.spec.title,
  166. formPage: 'comment_list',
  167. from: 'posts',
  168. type: 'post'
  169. };
  170. }
  171. this.$emit("on-comment", {
  172. _comment
  173. })
  174. },
  175. fnCopyContent(content) {
  176. uni.$tm.u.setClipboardData(content);
  177. uni.$tm.toast('内容已复制成功!');
  178. },
  179. fnShowCommentDetail(comment) {
  180. this.$emit('on-comment-detail', {
  181. postName: this.postName,
  182. comment: comment
  183. });
  184. }
  185. }
  186. };
  187. </script>
  188. <style lang="scss" scoped>
  189. .comment-list {
  190. &_head {
  191. display: flex;
  192. align-items: center;
  193. justify-content: space-between;
  194. position: relative;
  195. box-sizing: border-box;
  196. padding-left: 24rpx;
  197. font-size: 30rpx;
  198. font-weight: bold;
  199. &:before {
  200. content: '';
  201. position: absolute;
  202. left: 0rpx;
  203. top: 8rpx;
  204. width: 8rpx;
  205. height: 26rpx;
  206. background-color: rgb(3, 174, 252);
  207. border-radius: 6rpx;
  208. }
  209. .title {
  210. .count {
  211. font-size: 28rpx;
  212. font-weight: normal;
  213. }
  214. }
  215. .filter {
  216. font-size: 26rpx;
  217. font-weight: normal;
  218. &-item {
  219. margin-left: 20rpx;
  220. color: #666;
  221. &.active {
  222. font-weight: bold;
  223. color: rgb(255, 152, 0);
  224. font-size: 26rpx;
  225. }
  226. }
  227. }
  228. }
  229. &_content {
  230. margin-top: 24rpx;
  231. padding-bottom: 36rpx;
  232. }
  233. }
  234. .loading-wrap {
  235. width: 100%;
  236. height: 506rpx;
  237. .loading {
  238. width: 100%;
  239. }
  240. .e-loading-icon {
  241. font-size: 100rpx;
  242. }
  243. }
  244. .to-more-comment {
  245. width: 100%;
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. margin-top: 80rpx;
  250. ::v-deep {
  251. .tm-button .tm-button-btn uni-button {
  252. height: 70rpx;
  253. }
  254. }
  255. }
  256. </style>