comments.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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="(index + 1) * 50">
  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
  96. :vertical="true"
  97. :borderBottom="false"
  98. input-type="textarea"
  99. title="我的回复"
  100. bg-color="grey-lighten-5"
  101. v-model="reply.form.content"
  102. :height="150"
  103. :focus="true"
  104. :adjustPosition="true"
  105. ></tm-input>
  106. </scroll-view>
  107. <view class="btn-wrap flex flex-center">
  108. <!-- 审核状态 -->
  109. <block v-if="reply.data.status == 'AUDITING'">
  110. <tm-button size="m" navtie-type="form" theme="bg-gradient-blue-accent" @click="fnReplyPass()">通过</tm-button>
  111. <tm-button size="m" navtie-type="form" theme="bg-gradient-blue-accent" @click="fnReplySubmit()">通过并回复</tm-button>
  112. </block>
  113. <!-- 已发布状态 -->
  114. <block v-else-if="reply.data.status == 'PUBLISHED'">
  115. <tm-button size="m" navtie-type="form" theme="bg-gradient-blue-accent" @click="fnReplySubmit()">回复</tm-button>
  116. </block>
  117. <!-- 回收站 -->
  118. <block v-else-if="reply.data.status == 'RECYCLE'">暂无操作</block>
  119. <tm-button size="m" theme="bg-gradient-blue-grey-accent" @click="reply.show = false">关 闭</tm-button>
  120. </view>
  121. </view>
  122. </tm-poup>
  123. </view>
  124. </view>
  125. </template>
  126. <script>
  127. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  128. import tmButton from '@/tm-vuetify/components/tm-button/tm-button.vue';
  129. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  130. import tmTabs from '@/tm-vuetify/components/tm-tabs/tm-tabs.vue';
  131. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  132. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  133. import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
  134. import tmPoup from '@/tm-vuetify/components/tm-poup/tm-poup.vue';
  135. import tmInput from '@/tm-vuetify/components/tm-input/tm-input.vue';
  136. export default {
  137. components: {
  138. tmSkeleton,
  139. tmButton,
  140. tmEmpty,
  141. tmTabs,
  142. tmTranslate,
  143. tmFlotbutton,
  144. tmTags,
  145. tmPoup,
  146. tmInput
  147. },
  148. data() {
  149. return {
  150. loading: 'loading',
  151. tab: {
  152. adtiveIndex: 0,
  153. list: ['文章评论', '页面评论', '日记评论']
  154. },
  155. queryParams: {
  156. size: 10,
  157. page: 0
  158. },
  159. result: {},
  160. dataList: [],
  161. queryType: 'Posts',
  162. isLoadMore: false,
  163. loadMoreText: '加载中...',
  164. reply: {
  165. show: false,
  166. data: {},
  167. form: {
  168. allowNotification: true,
  169. author: '',
  170. authorUrl: '',
  171. content: '',
  172. email: '',
  173. parentId: 0,
  174. postId: 0
  175. }
  176. }
  177. };
  178. },
  179. computed: {
  180. // 获取博主信息
  181. bloggerInfo() {
  182. return this.$tm.vx.getters().getBlogger;
  183. }
  184. },
  185. onLoad() {
  186. this.fnSetPageTitle('评论管理');
  187. },
  188. created() {
  189. this.fnGetData();
  190. },
  191. onPullDownRefresh() {
  192. this.isLoadMore = false;
  193. this.queryParams.page = 0;
  194. this.fnGetData();
  195. },
  196. onReachBottom(e) {
  197. if (this.result.hasNext) {
  198. this.queryParams.page += 1;
  199. this.isLoadMore = true;
  200. this.fnGetData();
  201. } else {
  202. uni.showToast({
  203. icon: 'none',
  204. title: '没有更多数据了'
  205. });
  206. }
  207. },
  208. methods: {
  209. fnOnTabChange(index) {
  210. this.fnResetReply();
  211. this.dataList = [];
  212. this.queryType = ['Posts', 'Sheets', 'Journals'][index];
  213. this.fnToTopPage();
  214. this.fnGetData();
  215. },
  216. fnGetData() {
  217. uni.showLoading({
  218. mask: true,
  219. title: '加载中...'
  220. });
  221. // 设置状态为加载中
  222. if (!this.isLoadMore) {
  223. this.loading = 'loading';
  224. }
  225. this.loadMoreText = '加载中...';
  226. this.$httpApi.admin[`get${this.queryType}Comments`](this.queryParams)
  227. .then(res => {
  228. console.log('请求结果:');
  229. console.log(res);
  230. this.loading = 'success';
  231. this.loadMoreText = res.data.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  232. const _list = res.data.content.map(x => {
  233. x.avatar = this.$utils.checkAvatarUrl(x.avatar, x.isAdmin);
  234. return x;
  235. });
  236. // 处理数据
  237. this.result = res.data;
  238. if (this.isLoadMore) {
  239. this.dataList = this.dataList.concat(_list);
  240. } else {
  241. this.dataList = _list;
  242. }
  243. })
  244. .catch(err => {
  245. console.error(err);
  246. this.loading = 'error';
  247. this.loadMoreText = '加载失败,请下拉刷新!';
  248. })
  249. .finally(() => {
  250. setTimeout(() => {
  251. uni.hideLoading();
  252. uni.stopPullDownRefresh();
  253. }, 800);
  254. });
  255. },
  256. fnShowReplyModal(comment) {
  257. this.reply.data = comment;
  258. this.reply.form.parentId = comment.id;
  259. switch (this.queryType) {
  260. case 'Posts':
  261. this.reply.form.postId = comment.post.id;
  262. break;
  263. case 'Sheets':
  264. this.reply.form.postId = comment.sheet.id;
  265. break;
  266. case 'Journals':
  267. this.reply.form.postId = comment.journal.id;
  268. break;
  269. }
  270. this.reply.show = true;
  271. },
  272. fnResetReply() {
  273. this.reply = {
  274. show: false,
  275. data: {},
  276. form: {
  277. allowNotification: true,
  278. author: '',
  279. authorUrl: '',
  280. content: '',
  281. email: '',
  282. parentId: 0,
  283. postId: 0
  284. }
  285. };
  286. },
  287. // 审核通过
  288. fnReplyPass(comment) {
  289. uni.$eShowModal({
  290. title: '提示',
  291. content: `您是否要通过 ${comment.author} 的评论?`,
  292. showCancel: true,
  293. cancelText: '否',
  294. cancelColor: '#999999',
  295. confirmText: '是',
  296. confirmColor: '#03a9f4'
  297. })
  298. .then(res => {
  299. this.$httpApi.admin[`update${this.queryType}CommentsStatus`](comment.id, 'PUBLISHED')
  300. .then(res => {
  301. if (res.status == 200) {
  302. uni.$tm.toast(`操作成功!`);
  303. comment.status = 'PUBLISHED';
  304. // uni.startPullDownRefresh();
  305. } else {
  306. uni.$tm.toast('操作失败,请重试!');
  307. }
  308. })
  309. .catch(err => {
  310. uni.$tm.toast('操作失败,请重试!');
  311. });
  312. })
  313. .catch(err => {});
  314. },
  315. // 回复评论
  316. fnReplySubmit() {
  317. this.reply.form.author = this.bloggerInfo.nickname;
  318. this.reply.form.authorUrl = this.$haloConfig.social.blog || this.$haloConfig.apiUrl;
  319. this.reply.form.email = this.bloggerInfo.email;
  320. uni.showLoading({
  321. title: '正在回复中...'
  322. });
  323. this.$httpApi.admin[`post${this.queryType}Comments`](this.reply.form)
  324. .then(res => {
  325. if (res.status == 200) {
  326. uni.$tm.toast('回复成功');
  327. this.fnResetReply();
  328. this.fnToTopPage();
  329. uni.startPullDownRefresh();
  330. } else {
  331. uni.$tm.toast('回复失败,请重试!');
  332. }
  333. })
  334. .catch(err => {
  335. uni.$tm.toast('回复失败,请重试!');
  336. });
  337. },
  338. // 还原
  339. fnRestore(comment) {
  340. uni.$eShowModal({
  341. title: '提示',
  342. content: `您是否要将 ${comment.author} 的评论还原?`,
  343. showCancel: true,
  344. cancelText: '否',
  345. cancelColor: '#999999',
  346. confirmText: '是',
  347. confirmColor: '#03a9f4'
  348. })
  349. .then(res => {
  350. this.$httpApi.admin[`update${this.queryType}CommentsStatus`](comment.id, 'PUBLISHED')
  351. .then(res => {
  352. if (res.status == 200) {
  353. uni.$tm.toast(`已将 ${comment.author} 的评论还原!`);
  354. // uni.startPullDownRefresh();
  355. comment.status = 'PUBLISHED';
  356. } else {
  357. uni.$tm.toast('操作失败,请重试!');
  358. }
  359. })
  360. .catch(err => {
  361. uni.$tm.toast('操作失败,请重试!');
  362. });
  363. })
  364. .catch(err => {});
  365. },
  366. // 移到回收站
  367. fnRecycle(comment) {
  368. uni.$eShowModal({
  369. title: '提示',
  370. content: `您是否要将 ${comment.author} 的评论移到回收站?`,
  371. showCancel: true,
  372. cancelText: '否',
  373. cancelColor: '#999999',
  374. confirmText: '是',
  375. confirmColor: '#03a9f4'
  376. })
  377. .then(res => {
  378. this.$httpApi.admin[`update${this.queryType}CommentsStatus`](comment.id, 'RECYCLE')
  379. .then(res => {
  380. if (res.status == 200) {
  381. uni.$tm.toast(`已将 ${comment.author} 的评论移到回收站!`);
  382. comment.status = 'RECYCLE';
  383. // uni.startPullDownRefresh();
  384. } else {
  385. uni.$tm.toast('操作失败,请重试!');
  386. }
  387. })
  388. .catch(err => {
  389. uni.$tm.toast('操作失败,请重试!');
  390. });
  391. })
  392. .catch(err => {});
  393. },
  394. // 删除评论(永久删除)
  395. fnDelete(comment) {
  396. uni.$eShowModal({
  397. title: '提示',
  398. content: `您是否要将 ${comment.author} 的评论删除?`,
  399. showCancel: true,
  400. cancelText: '否',
  401. cancelColor: '#999999',
  402. confirmText: '是',
  403. confirmColor: '#03a9f4'
  404. })
  405. .then(res => {
  406. this.$httpApi.admin[`delete${this.queryType}CommentsById`](comment.id)
  407. .then(res => {
  408. if (res.status == 200) {
  409. uni.$tm.toast(`${comment.author} 的评论已删除!`);
  410. const delIndex = this.dataList.findIndex(x => x.id == comment.id);
  411. this.dataList.splice(delIndex, 1);
  412. // uni.startPullDownRefresh();
  413. } else {
  414. uni.$tm.toast('操作失败,请重试!');
  415. }
  416. })
  417. .catch(err => {
  418. uni.$tm.toast('操作失败,请重试!');
  419. });
  420. })
  421. .catch(err => {});
  422. }
  423. }
  424. };
  425. </script>
  426. <style lang="scss" scoped>
  427. .app-page {
  428. width: 100vw;
  429. min-height: 100vh;
  430. }
  431. .loading-wrap {
  432. padding: 24rpx;
  433. .loading-error {
  434. height: 65vh;
  435. }
  436. }
  437. .content-empty {
  438. width: 100%;
  439. height: 60vh;
  440. }
  441. .comment-card {
  442. box-sizing: border-box;
  443. box-shadow: 0rpx 0rpx 24rpx rgba(0, 0, 0, 0.05);
  444. margin-bottom: 24rpx;
  445. .avatar {
  446. width: 56rpx;
  447. height: 56rpx;
  448. box-sizing: border-box;
  449. border: 4rpx solid #fff;
  450. box-shadow: 0rpx 0rpx 24rpx rgba(0, 0, 0, 0.15);
  451. }
  452. .comment-content {
  453. line-height: 1.6;
  454. }
  455. }
  456. .poup-content {
  457. overflow: hidden;
  458. }
  459. .poup-body {
  460. height: 60vh;
  461. box-sizing: border-box;
  462. }
  463. </style>