You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/vc-pagination/Options.jsx

132 lines
3.2 KiB

import PropTypes from '../_util/vue-types';
import KEYCODE from './KeyCode';
import BaseMixin from '../_util/BaseMixin';
7 years ago
export default {
mixins: [BaseMixin],
7 years ago
props: {
rootPrefixCls: PropTypes.String,
7 years ago
selectPrefixCls: PropTypes.String,
changeSize: PropTypes.func,
quickGo: PropTypes.func,
selectComponentClass: PropTypes.any,
7 years ago
current: PropTypes.number,
pageSizeOptions: PropTypes.array.def(['10', '20', '30', '40']),
pageSize: PropTypes.number,
buildOptionText: PropTypes.func,
7 years ago
locale: PropTypes.object,
goButton: PropTypes.any,
7 years ago
},
data() {
7 years ago
return {
goInputText: '',
};
7 years ago
},
methods: {
defaultBuildOptionText(opt) {
return `${opt.value} ${this.locale.items_per_page}`;
7 years ago
},
handleChange(e) {
this.setState({
goInputText: e.target.value,
});
7 years ago
},
go(e) {
let val = this.goInputText;
7 years ago
if (val === '') {
return;
7 years ago
}
val = isNaN(val) ? this.current : Number(val);
7 years ago
if (e.keyCode === KEYCODE.ENTER || e.type === 'click') {
this.setState({
goInputText: '',
});
this.quickGo(val);
7 years ago
}
},
},
render() {
const {
rootPrefixCls,
locale,
changeSize,
quickGo,
goButton,
selectComponentClass: Select,
defaultBuildOptionText,
} = this;
const prefixCls = `${rootPrefixCls}-options`;
let changeSelect = null;
let goInput = null;
let gotoButton = null;
7 years ago
if (!(changeSize || quickGo)) {
return null;
7 years ago
}
if (changeSize && Select) {
const Option = Select.Option;
const pageSize = this.pageSize || this.pageSizeOptions[0];
const buildOptionText = this.buildOptionText || defaultBuildOptionText;
7 years ago
const options = this.pageSizeOptions.map((opt, i) => (
<Option key={i} value={opt}>
{buildOptionText({ value: opt })}
</Option>
));
7 years ago
changeSelect = (
<Select
prefixCls={this.selectPrefixCls}
showSearch={false}
class={`${prefixCls}-size-changer`}
optionLabelProp="children"
7 years ago
dropdownMatchSelectWidth={false}
value={pageSize.toString()}
onChange={value => this.changeSize(Number(value))}
7 years ago
getPopupContainer={triggerNode => triggerNode.parentNode}
>
{options}
</Select>
);
7 years ago
}
if (quickGo) {
if (goButton) {
if (typeof goButton === 'boolean') {
gotoButton = (
<button type="button" onClick={this.go} onKeyup={this.go}>
7 years ago
{locale.jump_to_confirm}
</button>
);
7 years ago
} else {
gotoButton = (
<span onClick={this.go} onKeyup={this.go}>
{goButton}
</span>
);
7 years ago
}
}
goInput = (
<div class={`${prefixCls}-quick-jumper`}>
{locale.jump_to}
<input
type="text"
7 years ago
value={this.goInputText}
onInput={this.handleChange}
7 years ago
onKeyup={this.go}
/>
{locale.page}
{gotoButton}
</div>
);
7 years ago
}
return (
<li class={`${prefixCls}`}>
{changeSelect}
{goInput}
</li>
);
7 years ago
},
};