comment-list.vue 6.6 KB

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