leaving.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view class="app-page">
  3. <view v-if="loading != 'success'" class="loading-wrap pa-24">
  4. <tm-skeleton model="listAvatr"></tm-skeleton>
  5. <tm-skeleton model="listAvatr"></tm-skeleton>
  6. <tm-skeleton model="listAvatr"></tm-skeleton>
  7. </view>
  8. <!-- 内容区域 -->
  9. <view v-else class="app-page-content pa-24" :class="{ 'bg-white': dataList.length !== 0 }">
  10. <view v-if="dataList.length == 0" class="content-empty flex flex-center">
  11. <!-- 空布局 -->
  12. <tm-empty icon="icon-shiliangzhinengduixiang-" label="啊偶,博主还没有留言~"></tm-empty>
  13. </view>
  14. <block v-else>
  15. <block v-for="(item, index) in dataList" :key="index">
  16. <tm-translate animation-name="fadeUp" :wait="(index + 1) * 50">
  17. <!-- 列表项 -->
  18. <comment-item
  19. class="mb-12"
  20. :isChild="false"
  21. :comment="item"
  22. :postId="sheetId"
  23. :useSolid="false"
  24. @on-copy="fnCopyContent"
  25. @on-comment="fnToComment"
  26. @on-detail="fnOnShowCommentDetail"
  27. ></comment-item>
  28. </tm-translate>
  29. </block>
  30. <tm-flotbutton :offset="[16, 80]" @click="fnToTopPage" size="m" color="light-blue" icon="icon-angle-up"></tm-flotbutton>
  31. <view class="load-text">{{ loadMoreText }}</view>
  32. </block>
  33. <tm-flotbutton actions-pos="left" :show-text="true" color="bg-gradient-orange-accent" @click="fnToComment(null)"></tm-flotbutton>
  34. </view>
  35. <!-- 评论详情 -->
  36. <tm-poup v-model="commentDetail.show" height="auto" :round="6" :over-close="true" position="bottom">
  37. <view class="pa-24">
  38. <view class="poup-head pb-24">
  39. <view class="poup-title text-align-center text-size-g text-weight-b mb-32">留言详情</view>
  40. <comment-item :useActions="false" :isChild="false" :comment="commentDetail.comment" :postId="sheetId"></comment-item>
  41. </view>
  42. <scroll-view :scroll-y="true" class="poup-body">
  43. <view v-if="commentDetail.loading != 'success'" class="poup-loading-wrap flex flex-center">
  44. <view v-if="commentDetail.loading == 'loading'" class="loading flex flex-center flex-col">
  45. <text class="e-loading-icon iconfont icon-loading text-blue"></text>
  46. <view class="text-size-n text-grey-lighten-1 py-12 mt-12">加载中,请稍等...</view>
  47. </view>
  48. <view v-else-if="commentDetail.loading == 'error'" class="error">
  49. <tm-empty icon="icon-wind-cry" label="加载失败">
  50. <tm-button theme="bg-gradient-light-blue-accent" size="m" @click="fnGetChildComments()">刷新试试</tm-button>
  51. </tm-empty>
  52. </view>
  53. </view>
  54. <block v-else>
  55. <view v-if="commentDetail.list.length == 0" class="poup-empty flex flex-center">
  56. <tm-empty icon="icon-shiliangzhinengduixiang-" label="没有更多评论啦~"></tm-empty>
  57. </view>
  58. <block v-else>
  59. <comment-item
  60. v-for="(comment, index) in commentDetail.list"
  61. :useSolid="false"
  62. :useActions="false"
  63. :key="index"
  64. :isChild="false"
  65. :comment="comment"
  66. :postId="sheetId"
  67. ></comment-item>
  68. </block>
  69. </block>
  70. </scroll-view>
  71. </view>
  72. </tm-poup>
  73. </view>
  74. </template>
  75. <script>
  76. import AppKeys from '@/config/keys.js';
  77. import SheetConfig from '@/config/sheets.config.js';
  78. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  79. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  80. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  81. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  82. import tmPoup from '@/tm-vuetify/components/tm-poup/tm-poup.vue';
  83. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  84. import commentItem from '@/components/comment-item/comment-item.vue';
  85. export default {
  86. components: {
  87. tmSkeleton,
  88. tmFlotbutton,
  89. tmTranslate,
  90. tmEmpty,
  91. tmPoup,
  92. tmButton,
  93. commentItem
  94. },
  95. data() {
  96. return {
  97. loading: 'loading',
  98. queryParams: {
  99. size: 10,
  100. page: 0
  101. },
  102. result: null,
  103. dataList: [],
  104. isLoadMore: false,
  105. loadMoreText: '加载中...',
  106. sheetId: SheetConfig[AppKeys.SHEET_LEAVING],
  107. commentDetail: {
  108. loading: 'loading',
  109. show: false,
  110. comment: {},
  111. postId: undefined,
  112. list: []
  113. }
  114. };
  115. },
  116. onLoad() {
  117. this.fnSetPageTitle('留言板');
  118. },
  119. created() {
  120. this.fnGetData();
  121. uni.$on('leaving_refresh', () => {
  122. this.fnGetData();
  123. });
  124. },
  125. onPullDownRefresh() {
  126. this.isLoadMore = false;
  127. this.queryParams.page = 0;
  128. this.fnGetData();
  129. },
  130. onReachBottom(e) {
  131. if (this.result.hasNext) {
  132. this.queryParams.page += 1;
  133. this.isLoadMore = true;
  134. this.fnGetData();
  135. } else {
  136. uni.showToast({
  137. icon: 'none',
  138. title: '没有更多数据了'
  139. });
  140. }
  141. },
  142. methods: {
  143. fnGetData() {
  144. uni.showLoading({
  145. mask: true,
  146. title: '加载中...'
  147. });
  148. // 设置状态为加载中
  149. if (!this.isLoadMore) {
  150. this.loading = 'loading';
  151. }
  152. this.loadMoreText = '加载中...';
  153. this.$httpApi
  154. .getSheetsCommentsTreeBySheetId(this.sheetId, this.queryParams)
  155. .then(res => {
  156. if (res.status == 200) {
  157. this.loading = 'success';
  158. // return;
  159. this.loadMoreText = res.data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  160. // 处理数据
  161. this.result = res.data;
  162. if (this.isLoadMore) {
  163. this.dataList = this.dataList.concat(res.data.content);
  164. } else {
  165. this.dataList = res.data.content;
  166. }
  167. } else {
  168. this.loading = 'error';
  169. this.loadMoreText = '加载失败,请下拉刷新!';
  170. }
  171. })
  172. .catch(err => {
  173. console.error(err);
  174. this.loading = 'error';
  175. this.loadMoreText = '加载失败,请下拉刷新!';
  176. })
  177. .finally(() => {
  178. setTimeout(() => {
  179. uni.hideLoading();
  180. uni.stopPullDownRefresh();
  181. }, 500);
  182. });
  183. },
  184. fnToComment(data) {
  185. let _comment = {};
  186. if (data) {
  187. _comment = {
  188. id: this.sheetId,
  189. parentId: data.comment.id,
  190. title: data.comment.author,
  191. from: 'sheets',
  192. formPage: 'leaving',
  193. type: 'user'
  194. };
  195. } else {
  196. _comment = {
  197. id: this.sheetId,
  198. parentId: 0,
  199. title: '留言板留言',
  200. from: 'sheets',
  201. formPage: 'leaving',
  202. type: 'post'
  203. };
  204. }
  205. uni.$tm.vx.commit('comment/setCommentInfo', _comment);
  206. this.$Router.push({
  207. path: '/pagesA/comment/comment',
  208. query: _comment
  209. });
  210. },
  211. fnCopyContent(content) {
  212. uni.$tm.u.setClipboardData(content);
  213. uni.$tm.toast('内容已复制成功!');
  214. },
  215. fnOnShowCommentDetail(comment) {
  216. this.commentDetail.comment = comment;
  217. this.commentDetail.list = [];
  218. this.commentDetail.show = true;
  219. this.fnGetChildComments();
  220. },
  221. fnGetChildComments() {
  222. this.commentDetail.loading = 'loading';
  223. this.$httpApi
  224. .getSheetsChildrenCommentList(this.sheetId, this.commentDetail.comment.id, {})
  225. .then(res => {
  226. if (res.status == 200) {
  227. this.commentDetail.loading = 'success';
  228. this.commentDetail.list = res.data;
  229. } else {
  230. this.commentDetail.loading = 'error';
  231. }
  232. })
  233. .catch(err => {
  234. this.commentDetail.loading = 'error';
  235. });
  236. }
  237. }
  238. };
  239. </script>
  240. <style lang="scss" scoped>
  241. .app-page {
  242. width: 100vw;
  243. display: flex;
  244. flex-direction: column;
  245. background-color: #fafafd;
  246. }
  247. .app-page-content {
  248. box-sizing: border-box;
  249. // box-shadow: 0rpx 0rpx 24rpx rgba(0, 0, 0, 0.05);
  250. }
  251. .content-empty {
  252. width: 100%;
  253. height: 60vh;
  254. }
  255. .loading-wrap {
  256. box-sizing: border-box;
  257. padding: 24rpx;
  258. }
  259. </style>