import { getCommentsList } from '@/api/comments/comments'; import { REPLY_STATUS, COMMENT_STATUS } from '@/types/comments/constant'; import { Records, CommentsQuery } from '@/types/comments/type'; import { onMounted, ref } from 'vue'; export function useCommentsList() { const commentsList = ref([]); const pageNumber = ref(1); const pageSize = ref(10); const totalPage = ref(); const totalRow = ref(); const listFilter = ref({ authStatus: COMMENT_STATUS.ALL, replyStatus: REPLY_STATUS.ALL, }); const getList = () => { const params: CommentsQuery = { pageNumber: pageNumber.value, pageSize: pageSize.value, }; if (listFilter.value.authStatus !== COMMENT_STATUS.ALL) { //若传1,则拉取审核通过的;若传0,则拉取审核未通过的和未审核的 params.queryParam = { isApproved: listFilter.value.authStatus === COMMENT_STATUS.PASSED ? 1 : 0, }; } if (listFilter.value.replyStatus !== REPLY_STATUS.ALL) { params.queryParam = { isReplied: listFilter.value.replyStatus, }; } getCommentsList(params).then((res) => { commentsList.value = res.records; totalPage.value = res.totalPage; totalRow.value = res.totalRow; }); }; onMounted(() => { getList(); }); return { commentsList, pageNumber, pageSize, totalPage, totalRow, getList, listFilter, }; } export default useCommentsList;