vben
2023-04-05 8e5a6b7ce547ba8edb1d767bb4d820f3b66ff95a
src/components/Table/src/hooks/usePagination.tsx
@@ -1,11 +1,8 @@
import type { PaginationProps } from '../types/pagination';
import type { BasicTableProps } from '../types/table';
import { computed, unref, ref, ComputedRef } from 'vue';
import { computed, unref, ref, ComputedRef, watch } from 'vue';
import { LeftOutlined, RightOutlined } from '@ant-design/icons-vue';
import { isBoolean } from '/@/utils/is';
import { PAGE_SIZE, PAGE_SIZE_OPTIONS } from '../const';
import { useI18n } from '/@/hooks/web/useI18n';
@@ -25,15 +22,30 @@
}
export function usePagination(refProps: ComputedRef<BasicTableProps>) {
  const configRef = ref<PaginationProps>({});
  const { t } = useI18n();
  const configRef = ref<PaginationProps>({});
  const show = ref(true);
  watch(
    () => unref(refProps).pagination,
    (pagination) => {
      if (!isBoolean(pagination) && pagination) {
        configRef.value = {
          ...unref(configRef),
          ...(pagination ?? {}),
        };
      }
    },
  );
  const getPaginationInfo = computed((): PaginationProps | boolean => {
    const { pagination } = unref(refProps);
    if (isBoolean(pagination) && !pagination) {
    if (!unref(show) || (isBoolean(pagination) && !pagination)) {
      return false;
    }
    return {
      current: 1,
      pageSize: PAGE_SIZE,
@@ -60,5 +72,14 @@
  function getPagination() {
    return unref(getPaginationInfo);
  }
  return { getPagination, getPaginationInfo, setPagination };
  function getShowPagination() {
    return unref(show);
  }
  async function setShowPagination(flag: boolean) {
    show.value = flag;
  }
  return { getPagination, getPaginationInfo, setShowPagination, getShowPagination, setPagination };
}