UNPKG

vue-admin-core

Version:
31 lines (28 loc) 1.16 kB
import '../../../../components/config-provider/index.mjs'; import { toValue } from 'vue'; import { useGlobalConfig } from '../../../../components/config-provider/src/hooks/use-global-config.mjs'; const usePaginationPlugin = (fetchInstance, { pageSize, current, defaultParams = [] }) => { if (!current) return {}; const config = useGlobalConfig(); const pageSizeKey = config.value.pageSizeKey || "pageSize"; const currentPageKey = config.value.currentPageKey || "currentPage"; const _originRunAsync = fetchInstance.runAsync.bind(fetchInstance); const __params = { [pageSizeKey]: pageSize || 10, [currentPageKey]: current || 1 }; fetchInstance.runAsync = (...params) => { const _params = toValue(params[0]); if (_params) { if (_params[currentPageKey]) __params[currentPageKey] = _params[currentPageKey]; if (_params[pageSizeKey]) __params[pageSizeKey] = _params[pageSizeKey]; } return _originRunAsync({ ...defaultParams[0], ..._params, ...__params }, ...params.slice(1)); }; return {}; }; export { usePaginationPlugin as default }; //# sourceMappingURL=usePaginationPlugin.mjs.map