Pagination: add disabled prop (#10006)

pull/10014/merge
Hi-Linlin 2018-03-07 11:47:19 +08:00 committed by 杨奕
parent 810cae1c64
commit e92d1d13aa
7 changed files with 52 additions and 15 deletions

View File

@ -221,6 +221,7 @@ Add more modules based on your scenario.
| popper-class | custom class name for the page size Select's dropdown | string | — | — | | popper-class | custom class name for the page size Select's dropdown | string | — | — |
| prev-text | text for the prev button | string | — | — | | prev-text | text for the prev button | string | — | — |
| next-text | text for the next button | string | — | — | | next-text | text for the next button | string | — | — |
| disabled | whether Pagination is disabled | boolean | — | false |
### Events ### Events
| Event Name | Description | Parameters | | Event Name | Description | Parameters |

View File

@ -207,6 +207,7 @@ Agrega más modulos basados en su escenario.
| popper-class | clase propia para el `dropdown` del `select` del número de páginas | string | — | — | | popper-class | clase propia para el `dropdown` del `select` del número de páginas | string | — | — |
| prev-text | texto para el botón `prev` | string | — | — | | prev-text | texto para el botón `prev` | string | — | — |
| next-text | texto para el botón `next` | string | — | — | | next-text | texto para el botón `next` | string | — | — |
| disabled | whether Pagination is disabled | boolean | — | false |
### Eventos ### Eventos
| Nombre del evento | Descripción | Parámetros | | Nombre del evento | Descripción | Parámetros |

View File

@ -221,6 +221,7 @@
| popper-class | 每页显示个数选择器的下拉框类名 | string | — | — | | popper-class | 每页显示个数选择器的下拉框类名 | string | — | — |
| prev-text | 替代图标显示的上一页文字 | string | — | — | | prev-text | 替代图标显示的上一页文字 | string | — | — |
| next-text | 替代图标显示的下一页文字 | string | — | — | | next-text | 替代图标显示的下一页文字 | string | — | — |
| disabled | 是否禁用 | boolean | — | false |
### Events ### Events
| 事件名称 | 说明 | 回调参数 | | 事件名称 | 说明 | 回调参数 |

View File

@ -1,30 +1,30 @@
<template> <template>
<ul @click="onPagerClick" class="el-pager"> <ul @click="onPagerClick" class="el-pager">
<li <li
:class="{ active: currentPage === 1 }" :class="{ active: currentPage === 1, disabled }"
v-if="pageCount > 0" v-if="pageCount > 0"
class="number">1</li> class="number">1</li>
<li <li
class="el-icon more btn-quickprev" class="el-icon more btn-quickprev"
:class="[quickprevIconClass]" :class="[quickprevIconClass, { disabled }]"
v-if="showPrevMore" v-if="showPrevMore"
@mouseenter="quickprevIconClass = 'el-icon-d-arrow-left'" @mouseenter="onMouseenter('left')"
@mouseleave="quickprevIconClass = 'el-icon-more'"> @mouseleave="quickprevIconClass = 'el-icon-more'">
</li> </li>
<li <li
v-for="pager in pagers" v-for="pager in pagers"
:key="pager" :key="pager"
:class="{ active: currentPage === pager }" :class="{ active: currentPage === pager, disabled }"
class="number">{{ pager }}</li> class="number">{{ pager }}</li>
<li <li
class="el-icon more btn-quicknext" class="el-icon more btn-quicknext"
:class="[quicknextIconClass]" :class="[quicknextIconClass, { disabled }]"
v-if="showNextMore" v-if="showNextMore"
@mouseenter="quicknextIconClass = 'el-icon-d-arrow-right'" @mouseenter="onMouseenter('right')"
@mouseleave="quicknextIconClass = 'el-icon-more'"> @mouseleave="quicknextIconClass = 'el-icon-more'">
</li> </li>
<li <li
:class="{ active: currentPage === pageCount }" :class="{ active: currentPage === pageCount, disabled }"
class="number" class="number"
v-if="pageCount > 1">{{ pageCount }}</li> v-if="pageCount > 1">{{ pageCount }}</li>
</ul> </ul>
@ -37,7 +37,9 @@
props: { props: {
currentPage: Number, currentPage: Number,
pageCount: Number pageCount: Number,
disabled: Boolean
}, },
watch: { watch: {
@ -53,7 +55,7 @@
methods: { methods: {
onPagerClick(event) { onPagerClick(event) {
const target = event.target; const target = event.target;
if (target.tagName === 'UL') { if (target.tagName === 'UL' || this.disabled) {
return; return;
} }
@ -83,6 +85,15 @@
if (newPage !== currentPage) { if (newPage !== currentPage) {
this.$emit('change', newPage); this.$emit('change', newPage);
} }
},
onMouseenter(direction) {
if (this.disabled) return;
if (direction === 'left') {
this.quickprevIconClass = 'el-icon-d-arrow-left';
} else {
this.quicknextIconClass = 'el-icon-d-arrow-right';
}
} }
}, },

View File

@ -42,7 +42,9 @@ export default {
nextText: String, nextText: String,
background: Boolean background: Boolean,
disabled: Boolean
}, },
data() { data() {
@ -62,7 +64,7 @@ export default {
const TEMPLATE_MAP = { const TEMPLATE_MAP = {
prev: <prev></prev>, prev: <prev></prev>,
jumper: <jumper></jumper>, jumper: <jumper></jumper>,
pager: <pager currentPage={ this.internalCurrentPage } pageCount={ this.internalPageCount } on-change={ this.handleCurrentChange }></pager>, pager: <pager currentPage={ this.internalCurrentPage } pageCount={ this.internalPageCount } on-change={ this.handleCurrentChange } disabled={ this.disabled }></pager>,
next: <next></next>, next: <next></next>,
sizes: <sizes pageSizes={ this.pageSizes }></sizes>, sizes: <sizes pageSizes={ this.pageSizes }></sizes>,
slot: <my-slot></my-slot>, slot: <my-slot></my-slot>,
@ -107,7 +109,7 @@ export default {
return ( return (
<button <button
type="button" type="button"
class={['btn-prev', { disabled: this.$parent.internalCurrentPage <= 1 }]} class={['btn-prev', { disabled: this.$parent.disabled || this.$parent.internalCurrentPage <= 1 }]}
on-click={ this.$parent.prev }> on-click={ this.$parent.prev }>
{ {
this.$parent.prevText this.$parent.prevText
@ -126,7 +128,7 @@ export default {
type="button" type="button"
class={[ class={[
'btn-next', 'btn-next',
{ disabled: this.$parent.internalCurrentPage === this.$parent.internalPageCount || this.$parent.internalPageCount === 0 } { disabled: this.$parent.disabled || this.$parent.internalCurrentPage === this.$parent.internalPageCount || this.$parent.internalPageCount === 0 }
]} ]}
on-click={ this.$parent.next }> on-click={ this.$parent.next }>
{ {
@ -166,7 +168,8 @@ export default {
<el-select <el-select
value={ this.$parent.internalPageSize } value={ this.$parent.internalPageSize }
popperClass={ this.$parent.popperClass || '' } popperClass={ this.$parent.popperClass || '' }
on-input={ this.handleChange }> on-input={ this.handleChange }
disabled={ this.$parent.disabled }>
{ {
this.pageSizes.map(item => this.pageSizes.map(item =>
<el-option <el-option
@ -253,6 +256,7 @@ export default {
domPropsValue={ this.$parent.internalCurrentPage } domPropsValue={ this.$parent.internalCurrentPage }
type="number" type="number"
ref="input" ref="input"
disabled={ this.$parent.disabled }
nativeOnKeyup={ this.handleKeyup } nativeOnKeyup={ this.handleKeyup }
onChange={ this.handleChange } onChange={ this.handleChange }
onFocus={ this.handleFocus } onFocus={ this.handleFocus }
@ -284,11 +288,13 @@ export default {
}, },
prev() { prev() {
if (this.disabled) return;
const newVal = this.internalCurrentPage - 1; const newVal = this.internalCurrentPage - 1;
this.internalCurrentPage = this.getValidCurrentPage(newVal); this.internalCurrentPage = this.getValidCurrentPage(newVal);
}, },
next() { next() {
if (this.disabled) return;
const newVal = this.internalCurrentPage + 1; const newVal = this.internalCurrentPage + 1;
this.internalCurrentPage = this.getValidCurrentPage(newVal); this.internalCurrentPage = this.getValidCurrentPage(newVal);
}, },

View File

@ -87,6 +87,11 @@
padding-left: 12px; padding-left: 12px;
} }
.el-pager li.disabled {
color: $--color-text-placeholder;
cursor: not-allowed;
}
@include m(small) { @include m(small) {
.btn-prev, .btn-prev,
.btn-next, .btn-next,
@ -173,6 +178,10 @@
color: $--color-text-regular; color: $--color-text-regular;
min-width: 30px; min-width: 30px;
border-radius: 2px; border-radius: 2px;
&.disabled {
color: $--color-text-placeholder;
}
} }
.btn-prev, .btn-next { .btn-prev, .btn-next {
@ -183,7 +192,7 @@
} }
} }
.el-pager li { .el-pager li:not(.disabled) {
&:hover { &:hover {
color: $--pagination-hover-fill; color: $--pagination-hover-fill;
} }
@ -236,6 +245,10 @@
&.btn-quickprev { &.btn-quickprev {
line-height: 28px; line-height: 28px;
color: $--pagination-button-color; color: $--pagination-button-color;
&.disabled {
color: $--color-text-placeholder;
}
} }
&.btn-quickprev:hover { &.btn-quickprev:hover {

View File

@ -2434,6 +2434,10 @@ eslint-config-defaults@*:
version "9.0.0" version "9.0.0"
resolved "https://registry.yarnpkg.com/eslint-config-defaults/-/eslint-config-defaults-9.0.0.tgz#a090adc13b2935e3f43b3cd048a92701654e5ad5" resolved "https://registry.yarnpkg.com/eslint-config-defaults/-/eslint-config-defaults-9.0.0.tgz#a090adc13b2935e3f43b3cd048a92701654e5ad5"
eslint-config-elemefe@*:
version "0.3.0"
resolved "https://registry.yarnpkg.com/eslint-config-elemefe/-/eslint-config-elemefe-0.3.0.tgz#6f06cd6a8c6949bf58fa7fe2d4b4a4fde89bf008"
eslint-config-elemefe@0.1.1: eslint-config-elemefe@0.1.1:
version "0.1.1" version "0.1.1"
resolved "https://registry.yarnpkg.com/eslint-config-elemefe/-/eslint-config-elemefe-0.1.1.tgz#5a1664ce3f7d91f68528b508d040044ae6c10aa3" resolved "https://registry.yarnpkg.com/eslint-config-elemefe/-/eslint-config-elemefe-0.1.1.tgz#5a1664ce3f7d91f68528b508d040044ae6c10aa3"