leaving.vue 7.5 KB

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