use-comments.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { getCommentsList } from '@/api/comments/comments';
  2. import { REPLY_STATUS, COMMENT_STATUS } from '@/types/comments/constant';
  3. import { Records, CommentsQuery } from '@/types/comments/type';
  4. import { onMounted, ref } from 'vue';
  5. export function useCommentsList() {
  6. const commentsList = ref<Records[]>([]);
  7. const pageNumber = ref<number>(1);
  8. const pageSize = ref<number>(10);
  9. const totalPage = ref<number>();
  10. const totalRow = ref<number>();
  11. const listFilter = ref({
  12. authStatus: COMMENT_STATUS.ALL,
  13. replyStatus: REPLY_STATUS.ALL,
  14. });
  15. const getList = () => {
  16. const params: CommentsQuery = {
  17. pageNumber: pageNumber.value,
  18. pageSize: pageSize.value,
  19. };
  20. if (listFilter.value.authStatus !== COMMENT_STATUS.ALL) {
  21. //若传1,则拉取审核通过的;若传0,则拉取审核未通过的和未审核的
  22. params.queryParam = {
  23. isApproved: listFilter.value.authStatus === COMMENT_STATUS.PASSED ? 1 : 0,
  24. };
  25. }
  26. if (listFilter.value.replyStatus !== REPLY_STATUS.ALL) {
  27. params.queryParam = {
  28. isReplied: listFilter.value.replyStatus,
  29. };
  30. }
  31. getCommentsList(params).then((res) => {
  32. commentsList.value = res.records;
  33. totalPage.value = res.totalPage;
  34. totalRow.value = res.totalRow;
  35. });
  36. };
  37. onMounted(() => {
  38. getList();
  39. });
  40. return {
  41. commentsList,
  42. pageNumber,
  43. pageSize,
  44. totalPage,
  45. totalRow,
  46. getList,
  47. listFilter,
  48. };
  49. }
  50. export default useCommentsList;