comments.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <template>
  2. <view class="app-page flex flex-col">
  3. <view class="e-fixed bg-white"><tm-tabs color="light-blue" v-model="tab.activeIndex" :list="tab.list" align="center" @change="fnOnTabChange"></tm-tabs></view>
  4. <!-- 占位区域 -->
  5. <view style="width: 100vw;height: 90rpx;"></view>
  6. <view v-if="loading != 'success'" class="loading-wrap">
  7. <block v-if="loading == 'loading'">
  8. <tm-skeleton model="listAvatr"></tm-skeleton>
  9. <tm-skeleton model="listAvatr"></tm-skeleton>
  10. <tm-skeleton model="listAvatr"></tm-skeleton>
  11. <tm-skeleton model="listAvatr"></tm-skeleton>
  12. <tm-skeleton model="listAvatr"></tm-skeleton>
  13. </block>
  14. <view v-else-if="loading == 'error'" class="loading-error flex flex-col flex-center">
  15. <tm-empty icon="icon-wind-cry" label="加载失败"><tm-button theme="light-blue" size="m" @click="fnGetData()">重新加载</tm-button></tm-empty>
  16. </view>
  17. </view>
  18. <view v-else class="app-page-content pa-24">
  19. <view v-if="dataList.length == 0" class="content-empty flex flex-center"><tm-empty icon="icon-shiliangzhinengduixiang-" label="无数据"></tm-empty></view>
  20. <block v-else>
  21. <block v-for="(comment, index) in dataList" :key="index">
  22. <tm-translate animation-name="fadeUp" :wait="calcAniWait(index)">
  23. <view class="comment-card bg-white round-3 pt-24 pb-24">
  24. <view class="head flex flex-between pl-24 pr-24">
  25. <view class="left flex flex-center">
  26. <image class="avatar round-24" :src="comment.avatar" mode="aspectFill"></image>
  27. <text class=" ml-12 text-weight-b text-grey-darken-2">{{ comment.author }}</text>
  28. <tm-tags v-if="comment.isAdmin" color="bg-gradient-orange-lighten" size="s" model="fill" :shadow="0">博主</tm-tags>
  29. </view>
  30. <view class="right flex">
  31. <!-- 待审核 -->
  32. <block v-if="comment.status == 'AUDITING'">
  33. <tm-button theme="light-blue" :shadow="0" size="s" @click="fnReplyPass(comment)">通过</tm-button>
  34. <tm-button theme="light-blue" :shadow="0" size="s" @click="fnShowReplyModal(comment)">回复</tm-button>
  35. <tm-button theme="orange" :shadow="0" size="s" @click="fnRecycle(comment)">回收站</tm-button>
  36. </block>
  37. <!-- 已发布 -->
  38. <block v-if="comment.status == 'PUBLISHED'">
  39. <tm-button theme="light-blue" :shadow="0" size="s" @click="fnShowReplyModal(comment)">回复</tm-button>
  40. <tm-button theme="orange" :shadow="0" size="s" @click="fnRecycle(comment)">回收站</tm-button>
  41. </block>
  42. <!-- 回收站 -->
  43. <block v-if="comment.status == 'RECYCLE'">
  44. <tm-button theme="light-blue" :shadow="0" size="s" @click="fnRestore(comment)">还原</tm-button>
  45. <tm-button theme="red" :shadow="0" size="s" @click="fnDelete(comment)">删除</tm-button>
  46. </block>
  47. </view>
  48. </view>
  49. <view class="body pl-24 pr-24 mt-24 text-size-m">
  50. <view v-if="queryType == 'Posts'" class="text-grey-darken-1">文章:{{ comment.post.title }}</view>
  51. <view v-else-if="queryType == 'Sheets'" class="text-grey-darken-1">页面:{{ comment.sheet.title }}</view>
  52. <view v-else-if="queryType == 'Journals'" class="text-grey-darken-1">日记:{{ comment.journal.title }}</view>
  53. <view class="mt-16 comment-content">评论:{{ comment.content }}</view>
  54. </view>
  55. <view class="foot flex mt-24 pl-14 pr-14">
  56. <tm-tags color="bg-gradient-orange-accent" size="s" :round="6" model="text">ID:{{ comment.id }}</tm-tags>
  57. <tm-tags v-if="comment.status == 'AUDITING'" color="bg-gradient-blue-accent" size="s" :round="6" model="text">状态:审核中</tm-tags>
  58. <tm-tags v-else-if="comment.status == 'PUBLISHED'" color="bg-gradient-green-accent" size="s" :round="6" model="text">状态:已发布</tm-tags>
  59. <tm-tags v-if="comment.status == 'RECYCLE'" color="bg-gradient-red-accent" size="s" :round="6" model="text">状态:回收站</tm-tags>
  60. <tm-tags size="s" :round="6" color="bg-gradient-blue-grey-accent" model="text">
  61. {{ $tm.dayjs(comment.createTime).format('YYYY年MM月DD日 HH点mm分') }}
  62. </tm-tags>
  63. </view>
  64. </view>
  65. </tm-translate>
  66. </block>
  67. <tm-flotbutton @click="fnToTopPage" size="m" color="light-blue" icon="icon-angle-up"></tm-flotbutton>
  68. <view class="load-text">{{ loadMoreText }}</view>
  69. </block>
  70. <!-- 回复框 -->
  71. <tm-poup v-model="reply.show" position="bottom" height="75vh">
  72. <view class="poup-content">
  73. <view class="poup-head text-align-center text-weight-b text-size-g ma-24">回复评论</view>
  74. <scroll-view class="poup-body pa-24" :scroll-y="true" @touchmove.stop>
  75. <view class="text-size-m pa-30 pt-0 flex flex-center">
  76. <view class="pr-12">访客昵称</view>
  77. <view class="flex-1 pa-24 pt-12 pb-12 grey-lighten-5 text-grey round-3">{{ reply.data.author }}</view>
  78. </view>
  79. <view class="text-size-m pa-30 pt-0 flex flex-center">
  80. <view class="pr-12">邮箱地址</view>
  81. <view class="flex-1 pa-24 pt-12 pb-12 grey-lighten-5 text-grey round-3" @click="$utils.copyText(reply.data.email, '邮箱地址复制成功!')">
  82. {{ reply.data.email }}
  83. </view>
  84. </view>
  85. <view class="text-size-m pa-30 pt-0 flex flex-center">
  86. <view class="pr-12">网站地址</view>
  87. <view class="flex-1 pa-24 pt-12 pb-12 grey-lighten-5 text-grey round-3" @click="$utils.copyText(reply.data.authorUrl, '网站地址复制成功!')">
  88. {{ reply.data.authorUrl || '该访客未填写网站地址' }}
  89. </view>
  90. </view>
  91. <view class="text-size-m pa-30 pt-0">
  92. <view class="mb-24">评论内容</view>
  93. <view class="pa-24 pt-12 pb-12 grey-lighten-5 text-grey round-3">{{ reply.data.content }}</view>
  94. </view>
  95. <tm-input :vertical="true" :borderBottom="false" input-type="textarea" title="我的回复" bg-color="grey-lighten-5" v-model="reply.form.content" :height="150" :focus="true" :adjustPosition="true"></tm-input>
  96. </scroll-view>
  97. <view class="btn-wrap flex flex-center">
  98. <!-- 审核状态 -->
  99. <block v-if="reply.data.status == 'AUDITING'">
  100. <tm-button size="m" navtie-type="form" theme="bg-gradient-blue-accent" @click="fnReplyPass()">通过</tm-button>
  101. <tm-button size="m" navtie-type="form" theme="bg-gradient-blue-accent" @click="fnReplySubmit()">通过并回复</tm-button>
  102. </block>
  103. <!-- 已发布状态 -->
  104. <block v-else-if="reply.data.status == 'PUBLISHED'">
  105. <tm-button size="m" navtie-type="form" theme="bg-gradient-blue-accent" @click="fnReplySubmit()">回复</tm-button>
  106. </block>
  107. <!-- 回收站 -->
  108. <block v-else-if="reply.data.status == 'RECYCLE'">暂无操作</block>
  109. <tm-button size="m" theme="bg-gradient-blue-grey-accent" @click="reply.show = false">关 闭</tm-button>
  110. </view>
  111. </view>
  112. </tm-poup>
  113. </view>
  114. </view>
  115. </template>
  116. <script>
  117. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  118. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  119. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  120. import tmTabs from '@/tm-vuetify/components/tm-tabs/tm-tabs.vue';
  121. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  122. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  123. import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
  124. import tmPoup from '@/tm-vuetify/components/tm-poup/tm-poup.vue';
  125. import tmInput from '@/tm-vuetify/components/tm-input/tm-input.vue';
  126. export default {
  127. components: {
  128. tmSkeleton,
  129. tmButton,
  130. tmEmpty,
  131. tmTabs,
  132. tmTranslate,
  133. tmFlotbutton,
  134. tmTags,
  135. tmPoup,
  136. tmInput
  137. },
  138. data() {
  139. return {
  140. loading: 'loading',
  141. tab: {
  142. adtiveIndex: 0,
  143. list: ['文章评论', '页面评论', '日记评论']
  144. },
  145. queryParams: {
  146. size: 10,
  147. page: 0
  148. },
  149. result: {},
  150. dataList: [],
  151. queryType: 'Posts',
  152. isLoadMore: false,
  153. loadMoreText: '加载中...',
  154. reply: {
  155. show: false,
  156. data: {},
  157. form: {
  158. allowNotification: true,
  159. author: '',
  160. authorUrl: '',
  161. content: '',
  162. email: '',
  163. parentId: 0,
  164. postId: 0
  165. }
  166. }
  167. };
  168. },
  169. computed: {
  170. // 获取博主信息
  171. bloggerInfo() {
  172. return this.$tm.vx.getters().getBlogger;
  173. }
  174. },
  175. onLoad() {
  176. this.fnSetPageTitle('评论管理');
  177. },
  178. created() {
  179. this.fnGetData();
  180. },
  181. onPullDownRefresh() {
  182. this.isLoadMore = false;
  183. this.queryParams.page = 0;
  184. this.fnGetData();
  185. },
  186. onReachBottom(e) {
  187. if (this.result.hasNext) {
  188. this.queryParams.page += 1;
  189. this.isLoadMore = true;
  190. this.fnGetData();
  191. } else {
  192. uni.showToast({
  193. icon: 'none',
  194. title: '没有更多数据了'
  195. });
  196. }
  197. },
  198. methods: {
  199. fnOnTabChange(index) {
  200. this.fnResetSetAniWaitIndex();
  201. this.fnResetReply();
  202. this.dataList = [];
  203. this.queryType = ['Posts', 'Sheets', 'Journals'][index];
  204. this.fnToTopPage();
  205. this.fnGetData();
  206. },
  207. fnGetData() {
  208. uni.showLoading({
  209. mask: true,
  210. title: '加载中...'
  211. });
  212. // 设置状态为加载中
  213. if (!this.isLoadMore) {
  214. this.loading = 'loading';
  215. }
  216. this.loadMoreText = '加载中...';
  217. this.$httpApi.admin[`get${this.queryType}Comments`](this.queryParams)
  218. .then(res => {
  219. console.log('请求结果:');
  220. console.log(res);
  221. this.loading = 'success';
  222. this.loadMoreText = res.data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  223. const _list = res.data.content.map(x => {
  224. x.avatar = this.$utils.checkAvatarUrl(x.avatar, x.isAdmin);
  225. return x;
  226. });
  227. // 处理数据
  228. this.result = res.data;
  229. if (this.isLoadMore) {
  230. this.dataList = this.dataList.concat(_list);
  231. } else {
  232. this.dataList = _list;
  233. }
  234. })
  235. .catch(err => {
  236. console.error(err);
  237. this.loading = 'error';
  238. this.loadMoreText = '加载失败,请下拉刷新!';
  239. })
  240. .finally(() => {
  241. setTimeout(() => {
  242. uni.hideLoading();
  243. uni.stopPullDownRefresh();
  244. }, 800);
  245. });
  246. },
  247. fnShowReplyModal(comment) {
  248. this.reply.data = comment;
  249. this.reply.form.parentId = comment.id;
  250. switch (this.queryType) {
  251. case 'Posts':
  252. this.reply.form.postId = comment.post.id;
  253. break;
  254. case 'Sheets':
  255. this.reply.form.postId = comment.sheet.id;
  256. break;
  257. case 'Journals':
  258. this.reply.form.postId = comment.journal.id;
  259. break;
  260. }
  261. this.reply.show = true;
  262. },
  263. fnResetReply() {
  264. this.reply = {
  265. show: false,
  266. data: {},
  267. form: {
  268. allowNotification: true,
  269. author: '',
  270. authorUrl: '',
  271. content: '',
  272. email: '',
  273. parentId: 0,
  274. postId: 0
  275. }
  276. };
  277. },
  278. // 审核通过
  279. fnReplyPass(comment) {
  280. uni.$eShowModal({
  281. title: '提示',
  282. content: `您是否要通过 ${comment.author} 的评论?`,
  283. showCancel: true,
  284. cancelText: '否',
  285. cancelColor: '#999999',
  286. confirmText: '是',
  287. confirmColor: '#03a9f4'
  288. })
  289. .then(res => {
  290. this.$httpApi.admin[`update${this.queryType}CommentsStatus`](comment.id, 'PUBLISHED')
  291. .then(res => {
  292. if (res.status == 200) {
  293. uni.$tm.toast(`操作成功!`);
  294. comment.status = 'PUBLISHED';
  295. // uni.startPullDownRefresh();
  296. } else {
  297. uni.$tm.toast('操作失败,请重试!');
  298. }
  299. })
  300. .catch(err => {
  301. uni.$tm.toast('操作失败,请重试!');
  302. });
  303. })
  304. .catch(err => {});
  305. },
  306. // 回复评论
  307. fnReplySubmit() {
  308. this.reply.form.author = this.bloggerInfo.nickname;
  309. this.reply.form.authorUrl = this.$haloConfig.social.blog || this.$baseApiUrl;
  310. this.reply.form.email = this.bloggerInfo.email;
  311. uni.showLoading({
  312. title: '正在回复中...'
  313. });
  314. this.$httpApi.admin[`post${this.queryType}Comments`](this.reply.form)
  315. .then(res => {
  316. if (res.status == 200) {
  317. uni.$tm.toast('回复成功');
  318. this.fnResetReply();
  319. this.fnToTopPage();
  320. uni.startPullDownRefresh();
  321. } else {
  322. uni.$tm.toast('回复失败,请重试!');
  323. }
  324. })
  325. .catch(err => {
  326. uni.$tm.toast('回复失败,请重试!');
  327. });
  328. },
  329. // 还原
  330. fnRestore(comment) {
  331. uni.$eShowModal({
  332. title: '提示',
  333. content: `您是否要将 ${comment.author} 的评论还原?`,
  334. showCancel: true,
  335. cancelText: '否',
  336. cancelColor: '#999999',
  337. confirmText: '是',
  338. confirmColor: '#03a9f4'
  339. })
  340. .then(res => {
  341. this.$httpApi.admin[`update${this.queryType}CommentsStatus`](comment.id, 'PUBLISHED')
  342. .then(res => {
  343. if (res.status == 200) {
  344. uni.$tm.toast(`已将 ${comment.author} 的评论还原!`);
  345. // uni.startPullDownRefresh();
  346. comment.status = 'PUBLISHED';
  347. } else {
  348. uni.$tm.toast('操作失败,请重试!');
  349. }
  350. })
  351. .catch(err => {
  352. uni.$tm.toast('操作失败,请重试!');
  353. });
  354. })
  355. .catch(err => {});
  356. },
  357. // 移到回收站
  358. fnRecycle(comment) {
  359. uni.$eShowModal({
  360. title: '提示',
  361. content: `您是否要将 ${comment.author} 的评论移到回收站?`,
  362. showCancel: true,
  363. cancelText: '否',
  364. cancelColor: '#999999',
  365. confirmText: '是',
  366. confirmColor: '#03a9f4'
  367. })
  368. .then(res => {
  369. this.$httpApi.admin[`update${this.queryType}CommentsStatus`](comment.id, 'RECYCLE')
  370. .then(res => {
  371. if (res.status == 200) {
  372. uni.$tm.toast(`已将 ${comment.author} 的评论移到回收站!`);
  373. comment.status = 'RECYCLE';
  374. // uni.startPullDownRefresh();
  375. } else {
  376. uni.$tm.toast('操作失败,请重试!');
  377. }
  378. })
  379. .catch(err => {
  380. uni.$tm.toast('操作失败,请重试!');
  381. });
  382. })
  383. .catch(err => {});
  384. },
  385. // 删除评论(永久删除)
  386. fnDelete(comment) {
  387. uni.$eShowModal({
  388. title: '提示',
  389. content: `您是否要将 ${comment.author} 的评论删除?`,
  390. showCancel: true,
  391. cancelText: '否',
  392. cancelColor: '#999999',
  393. confirmText: '是',
  394. confirmColor: '#03a9f4'
  395. })
  396. .then(res => {
  397. this.$httpApi.admin[`delete${this.queryType}CommentsById`](comment.id)
  398. .then(res => {
  399. if (res.status == 200) {
  400. uni.$tm.toast(`${comment.author} 的评论已删除!`);
  401. const delIndex = this.dataList.findIndex(x => x.id == comment.id);
  402. this.dataList.splice(delIndex, 1);
  403. // uni.startPullDownRefresh();
  404. } else {
  405. uni.$tm.toast('操作失败,请重试!');
  406. }
  407. })
  408. .catch(err => {
  409. uni.$tm.toast('操作失败,请重试!');
  410. });
  411. })
  412. .catch(err => {});
  413. }
  414. }
  415. };
  416. </script>
  417. <style lang="scss" scoped>
  418. .app-page {
  419. width: 100vw;
  420. min-height: 100vh;
  421. }
  422. .loading-wrap {
  423. padding: 24rpx;
  424. .loading-error {
  425. height: 65vh;
  426. }
  427. }
  428. .content-empty {
  429. width: 100%;
  430. height: 60vh;
  431. }
  432. .comment-card {
  433. box-sizing: border-box;
  434. box-shadow: 0rpx 0rpx 24rpx rgba(0, 0, 0, 0.05);
  435. margin-bottom: 24rpx;
  436. .avatar {
  437. width: 56rpx;
  438. height: 56rpx;
  439. box-sizing: border-box;
  440. border: 4rpx solid #fff;
  441. box-shadow: 0rpx 0rpx 24rpx rgba(0, 0, 0, 0.15);
  442. }
  443. .comment-content {
  444. line-height: 1.6;
  445. }
  446. }
  447. .poup-content {
  448. overflow: hidden;
  449. }
  450. .poup-body {
  451. height: 60vh;
  452. box-sizing: border-box;
  453. }
  454. </style>