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