| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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<Records[]>([]);
- const pageNumber = ref<number>(1);
- const pageSize = ref<number>(10);
- const totalPage = ref<number>();
- const totalRow = ref<number>();
- 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;
|