import PropTypes from '../_util/vue-types'; import KEYCODE from './KeyCode'; import BaseMixin from '../_util/BaseMixin'; export default { mixins: [BaseMixin], props: { disabled: PropTypes.bool, changeSize: PropTypes.func, quickGo: PropTypes.func, selectComponentClass: PropTypes.any, current: PropTypes.number, pageSizeOptions: PropTypes.array.def(['10', '20', '30', '40']), pageSize: PropTypes.number, buildOptionText: PropTypes.func, locale: PropTypes.object, rootPrefixCls: PropTypes.string, selectPrefixCls: PropTypes.string, goButton: PropTypes.any, }, data() { return { goInputText: '', }; }, methods: { getValidValue() { const { goInputText, current } = this; return isNaN(goInputText) ? current : Number(goInputText); }, defaultBuildOptionText(opt) { return `${opt.value} ${this.locale.items_per_page}`; }, handleChange(e) { this.setState({ goInputText: e.target.value, }); }, handleBlur() { const { goButton, quickGo } = this; if (goButton) { return; } quickGo(this.getValidValue()); }, go(e) { const { goInputText } = this; if (goInputText === '') { return; } if (e.keyCode === KEYCODE.ENTER || e.type === 'click') { this.setState({ goInputText: '', }); this.quickGo(this.getValidValue()); } }, }, render() { const { rootPrefixCls, locale, changeSize, quickGo, goButton, selectComponentClass: Select, defaultBuildOptionText, selectPrefixCls, pageSize, pageSizeOptions, goInputText, disabled, } = this; const prefixCls = `${rootPrefixCls}-options`; let changeSelect = null; let goInput = null; let gotoButton = null; if (!changeSize && !quickGo) { return null; } if (changeSize && Select) { const buildOptionText = this.buildOptionText || defaultBuildOptionText; const options = pageSizeOptions.map((opt, i) => ( {buildOptionText({ value: opt })} )); changeSelect = ( ); } if (quickGo) { if (goButton) { gotoButton = typeof goButton === 'boolean' ? ( ) : ( {goButton} ); } goInput = (
{locale.jump_to} {locale.page} {gotoButton}
); } return (
  • {changeSelect} {goInput}
  • ); }, };