UNPKG

tav-ui

Version:
65 lines (62 loc) 1.94 kB
import { ref, watch, unref, computed } from 'vue'; import '../../../../locales/index2.mjs'; import { isBoolean } from '../../../../utils/is2.mjs'; import { PAGE_SIZE, PAGE_SIZE_OPTIONS } from '../const2.mjs'; import { tavI18n } from '../../../../locales/transfer2.mjs'; function itemRender({ page, type, originalElement }) { if (type === "prev") { return tavI18n("Tav.tablePro.page.1"); } else if (type === "next") { return tavI18n("Tav.tablePro.page.2"); } return originalElement; } function usePagination(refProps) { const configRef = ref({}); const show = ref(true); watch(() => unref(refProps).pagination, (pagination) => { if (!isBoolean(pagination) && pagination) { configRef.value = { ...unref(configRef), ...pagination ?? {} }; } }); const getPaginationInfo = computed(() => { const { pagination } = unref(refProps); if (!unref(show) || isBoolean(pagination) && !pagination) { return false; } return { current: 1, pageSize: PAGE_SIZE, size: "small", defaultPageSize: PAGE_SIZE, showTotal: (total) => "\u5171 {total} \u6761\u6570\u636E".replace("{total}", `${total}`), showSizeChanger: true, pageSizeOptions: PAGE_SIZE_OPTIONS, itemRender, ...isBoolean(pagination) ? {} : pagination, ...unref(configRef) }; }); function setPagination(info) { const paginationInfo = unref(getPaginationInfo); configRef.value = { ...!isBoolean(paginationInfo) ? paginationInfo : {}, ...info }; } function getPagination() { return unref(getPaginationInfo); } function getShowPagination() { return unref(show); } async function setShowPagination(flag) { show.value = flag; } return { getPagination, getPaginationInfo, setShowPagination, getShowPagination, setPagination }; } export { usePagination }; //# sourceMappingURL=usePagination2.mjs.map