diff --git a/components/vc-pagination/Options.jsx b/components/vc-pagination/Options.jsx index 46fd16756..dc1012718 100644 --- a/components/vc-pagination/Options.jsx +++ b/components/vc-pagination/Options.jsx @@ -12,7 +12,7 @@ export default { quickGo: PropTypes.func, selectComponentClass: PropTypes.any, current: PropTypes.number, - pageSizeOptions: PropTypes.array.def(['10', '20', '30', '40']), + pageSizeOptions: PropTypes.array.def(['10', '20', '50', '100']), pageSize: PropTypes.number, buildOptionText: PropTypes.func, locale: PropTypes.object, @@ -27,8 +27,8 @@ export default { }, methods: { getValidValue() { - const { goInputText, current } = this; - return !goInputText || isNaN(goInputText) ? current : Number(goInputText); + const { goInputText } = this; + return !goInputText || isNaN(goInputText) ? undefined : Number(goInputText); }, defaultBuildOptionText(opt) { return `${opt.value} ${this.locale.items_per_page}`; @@ -42,13 +42,18 @@ export default { }, handleBlur(e) { const { goButton, quickGo, rootPrefixCls } = this.$props; - if (goButton) { + + const { goInputText } = this.$data; + if (goButton || goInputText === '') { return; } + this.setState({ + goInputText: '', + }); if ( e.relatedTarget && - (e.relatedTarget.className.indexOf(`${rootPrefixCls}-prev`) >= 0 || - e.relatedTarget.className.indexOf(`${rootPrefixCls}-next`) >= 0) + (e.relatedTarget.className.indexOf(`${rootPrefixCls}-item-link`) >= 0 || + e.relatedTarget.className.indexOf(`${rootPrefixCls}-item`) >= 0) ) { return; } @@ -67,6 +72,19 @@ export default { }); } }, + getPageSizeOptions() { + const { pageSize, pageSizeOptions } = this.$props; + if (pageSizeOptions.some(option => option.toString() === pageSize.toString())) { + return pageSizeOptions; + } + return pageSizeOptions.concat([pageSize.toString()]).sort((a, b) => { + // eslint-disable-next-line no-restricted-globals + const numberA = isNaN(Number(a)) ? 0 : Number(a); + // eslint-disable-next-line no-restricted-globals + const numberB = isNaN(Number(b)) ? 0 : Number(b); + return numberA - numberB; + }); + }, }, render() { const { @@ -79,7 +97,6 @@ export default { defaultBuildOptionText, selectPrefixCls, pageSize, - pageSizeOptions, goInputText, disabled, } = this; @@ -92,6 +109,8 @@ export default { return null; } + const pageSizeOptions = this.getPageSizeOptions(); + if (changeSize && Select) { const buildOptionText = this.buildOptionText || defaultBuildOptionText; const options = pageSizeOptions.map((opt, i) => ( @@ -120,7 +139,13 @@ export default { if (goButton) { gotoButton = typeof goButton === 'boolean' ? ( - ) : ( diff --git a/components/vc-pagination/Pager.jsx b/components/vc-pagination/Pager.jsx index 65214804a..f20055f26 100644 --- a/components/vc-pagination/Pager.jsx +++ b/components/vc-pagination/Pager.jsx @@ -49,7 +49,11 @@ export default { class={cls} style={style} > - {this.itemRender({ page: this.page, type: 'page', originalElement: {this.page} })} + {this.itemRender({ + page: this.page, + type: 'page', + originalElement: {this.page}, + })} ); }, diff --git a/components/vc-pagination/Pagination.jsx b/components/vc-pagination/Pagination.jsx index 7890e44a5..0febb0640 100644 --- a/components/vc-pagination/Pagination.jsx +++ b/components/vc-pagination/Pagination.jsx @@ -1,6 +1,12 @@ import PropTypes from '../_util/vue-types'; import BaseMixin from '../_util/BaseMixin'; -import { hasProp, getOptionProps, getComponent, splitAttrs } from '../_util/props-util'; +import { + hasProp, + getOptionProps, + getComponent, + splitAttrs, + isValidElement, +} from '../_util/props-util'; import Pager from './Pager'; import Options from './Options'; import LOCALE from './locale/zh_CN'; @@ -8,6 +14,7 @@ import KEYCODE from './KeyCode'; import classNames from '../_util/classNames'; import { defineComponent, withDirectives } from 'vue'; import antInput from '../_util/antInputDirective'; +import { cloneElement } from '../_util/vnode'; function noop() {} @@ -21,10 +28,7 @@ function defaultItemRender({ originalElement }) { } function calculatePage(p, state, props) { - let pageSize = p; - if (typeof pageSize === 'undefined') { - pageSize = state.statePageSize; - } + const pageSize = typeof p === 'undefined' ? state.statePageSize : p; return Math.floor((props.total - 1) / pageSize) + 1; } @@ -42,7 +46,7 @@ export default defineComponent({ pageSize: PropTypes.number, defaultPageSize: PropTypes.number.def(10), hideOnSinglePage: PropTypes.looseBool.def(false), - showSizeChanger: PropTypes.looseBool.def(false), + showSizeChanger: PropTypes.looseBool, showLessItems: PropTypes.looseBool.def(false), // showSizeChange: PropTypes.func.def(noop), selectComponentClass: PropTypes.any, @@ -54,11 +58,12 @@ export default defineComponent({ showTotal: PropTypes.func, simple: PropTypes.looseBool, locale: PropTypes.object.def(LOCALE), - itemRender: PropTypes.func, + itemRender: PropTypes.func.def(defaultItemRender), prevIcon: PropTypes.any, nextIcon: PropTypes.any, jumpPrevIcon: PropTypes.any, jumpNextIcon: PropTypes.any, + totalBoundaryShowSizeChanger: PropTypes.number.def(50), }, data() { const props = getOptionProps(this); @@ -149,10 +154,10 @@ export default defineComponent({ this.stateCurrent + (this.showLessItems ? 3 : 5), ); }, - getItemIcon(icon) { + getItemIcon(icon, label) { const { prefixCls } = this.$props; const iconNode = getComponent(this, icon, this.$props) || ( - +