7fa943eb
梁灏
init
|
1
|
<template>
|
c9080021
梁灏
update readme
|
2
|
<ul :class="simpleWrapClasses" :style="styles" v-if="simple">
|
7fa943eb
梁灏
init
|
3
|
<li
|
012cbf28
梁灏
update locale
|
4
|
:title="t('i.page.prev')"
|
7fa943eb
梁灏
init
|
5
6
|
:class="prevClasses"
@click="prev">
|
93064e3b
梁灏
add Page UI
|
7
|
<a><i class="ivu-icon ivu-icon-ios-arrow-left"></i></a>
|
7fa943eb
梁灏
init
|
8
|
</li>
|
87c51597
梁灏
support Page
|
9
|
<div :class="simplePagerClasses" :title="currentPage + '/' + allPages">
|
7fa943eb
梁灏
init
|
10
11
|
<input
type="text"
|
87c51597
梁灏
support Page
|
12
|
:value="currentPage"
|
7fa943eb
梁灏
init
|
13
14
15
16
17
18
19
|
@keydown="keyDown"
@keyup="keyUp"
@change="keyUp">
<span>/</span>
{{ allPages }}
</div>
<li
|
012cbf28
梁灏
update locale
|
20
|
:title="t('i.page.next')"
|
7fa943eb
梁灏
init
|
21
22
|
:class="nextClasses"
@click="next">
|
93064e3b
梁灏
add Page UI
|
23
|
<a><i class="ivu-icon ivu-icon-ios-arrow-right"></i></a>
|
7fa943eb
梁灏
init
|
24
25
|
</li>
</ul>
|
c9080021
梁灏
update readme
|
26
|
<ul :class="wrapClasses" :style="styles" v-else>
|
d6342fe1
jingsam
fixed ie bug
|
27
|
<span :class="[prefixCls + '-total']" v-if="showTotal">
|
012cbf28
梁灏
update locale
|
28
|
<slot>{{ t('i.page.total') }} {{ total }} <template v-if="total <= 1">{{ t('i.page.item') }}</template><template v-else>{{ t('i.page.items') }}</template></slot>
|
7fa943eb
梁灏
init
|
29
30
|
</span>
<li
|
012cbf28
梁灏
update locale
|
31
|
:title="t('i.page.prev')"
|
7fa943eb
梁灏
init
|
32
33
|
:class="prevClasses"
@click="prev">
|
93064e3b
梁灏
add Page UI
|
34
|
<a><i class="ivu-icon ivu-icon-ios-arrow-left"></i></a>
|
7fa943eb
梁灏
init
|
35
|
</li>
|
012cbf28
梁灏
update locale
|
36
|
<li title="1" :class="firstPageClasses" @click="changePage(1)"><a>1</a></li>
|
87c51597
梁灏
support Page
|
37
38
39
40
41
42
43
|
<li :title="t('i.page.prev5')" v-if="currentPage - 3 > 1" :class="[prefixCls + '-item-jump-prev']" @click="fastPrev"><a><i class="ivu-icon ivu-icon-ios-arrow-left"></i></a></li>
<li :title="currentPage - 2" v-if="currentPage - 2 > 1" :class="[prefixCls + '-item']" @click="changePage(currentPage - 2)"><a>{{ currentPage - 2 }}</a></li>
<li :title="currentPage - 1" v-if="currentPage - 1 > 1" :class="[prefixCls + '-item']" @click="changePage(currentPage - 1)"><a>{{ currentPage - 1 }}</a></li>
<li :title="currentPage" v-if="currentPage != 1 && currentPage != allPages" :class="[prefixCls + '-item',prefixCls + '-item-active']"><a>{{ currentPage }}</a></li>
<li :title="currentPage + 1" v-if="currentPage + 1 < allPages" :class="[prefixCls + '-item']" @click="changePage(currentPage + 1)"><a>{{ currentPage + 1 }}</a></li>
<li :title="currentPage + 2" v-if="currentPage + 2 < allPages" :class="[prefixCls + '-item']" @click="changePage(currentPage + 2)"><a>{{ currentPage + 2 }}</a></li>
<li :title="t('i.page.next5')" v-if="currentPage + 3 < allPages" :class="[prefixCls + '-item-jump-next']" @click="fastNext"><a><i class="ivu-icon ivu-icon-ios-arrow-right"></i></a></li>
|
012cbf28
梁灏
update locale
|
44
|
<li :title="allPages" v-if="allPages > 1" :class="lastPageClasses" @click="changePage(allPages)"><a>{{ allPages }}</a></li>
|
7fa943eb
梁灏
init
|
45
|
<li
|
012cbf28
梁灏
update locale
|
46
|
:title="t('i.page.next')"
|
7fa943eb
梁灏
init
|
47
48
|
:class="nextClasses"
@click="next">
|
93064e3b
梁灏
add Page UI
|
49
|
<a><i class="ivu-icon ivu-icon-ios-arrow-right"></i></a>
|
7fa943eb
梁灏
init
|
50
51
52
|
</li>
<Options
:show-sizer="showSizer"
|
87c51597
梁灏
support Page
|
53
|
:page-size="currentPageSize"
|
7fa943eb
梁灏
init
|
54
55
|
:page-size-opts="pageSizeOpts"
:show-elevator="showElevator"
|
87c51597
梁灏
support Page
|
56
57
|
:_current.once="currentPage"
:current="currentPage"
|
7fa943eb
梁灏
init
|
58
|
:all-pages="allPages"
|
6932b4d7
梁灏
update Page compo...
|
59
|
:is-small="isSmall"
|
7fa943eb
梁灏
init
|
60
61
62
63
64
65
66
67
|
@on-size="onSize"
@on-page="onPage">
</Options>
</ul>
</template>
<script>
import { oneOf } from '../../utils/assist';
import Options from './options.vue';
|
012cbf28
梁灏
update locale
|
68
|
import Locale from '../../mixins/locale';
|
7fa943eb
梁灏
init
|
69
70
71
72
|
const prefixCls = 'ivu-page';
export default {
|
87c51597
梁灏
support Page
|
73
|
name: 'Page',
|
012cbf28
梁灏
update locale
|
74
|
mixins: [ Locale ],
|
7fa943eb
梁灏
init
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
components: { Options },
props: {
current: {
type: Number,
default: 1
},
total: {
type: Number,
default: 0
},
pageSize: {
type: Number,
default: 10
},
pageSizeOpts: {
type: Array,
default () {
|
b0893113
jingsam
add eslint
|
92
|
return [10, 20, 30, 40];
|
7fa943eb
梁灏
init
|
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
}
},
size: {
validator (value) {
return oneOf(value, ['small']);
}
},
simple: {
type: Boolean,
default: false
},
showTotal: {
type: Boolean,
default: false
},
showElevator: {
type: Boolean,
default: false
},
showSizer: {
type: Boolean,
default: false
|
e0cd7f90
梁灏
fixed #134
|
115
|
},
|
87c51597
梁灏
support Page
|
116
|
className: {
|
e0cd7f90
梁灏
fixed #134
|
117
118
|
type: String
},
|
c9080021
梁灏
update readme
|
119
|
styles: {
|
e0cd7f90
梁灏
fixed #134
|
120
|
type: Object
|
7fa943eb
梁灏
init
|
121
122
123
124
|
}
},
data () {
return {
|
87c51597
梁灏
support Page
|
125
126
127
|
prefixCls: prefixCls,
currentPage: this.current,
currentPageSize: this.pageSize
|
b0893113
jingsam
add eslint
|
128
|
};
|
7fa943eb
梁灏
init
|
129
|
},
|
87c51597
梁灏
support Page
|
130
131
132
133
134
135
136
137
|
watch: {
current (val) {
this.currentPage = val;
},
pageSize (val) {
this.currentPageSize = val;
}
},
|
7fa943eb
梁灏
init
|
138
|
computed: {
|
6932b4d7
梁灏
update Page compo...
|
139
140
141
|
isSmall () {
return !!this.size;
},
|
7fa943eb
梁灏
init
|
142
|
allPages () {
|
87c51597
梁灏
support Page
|
143
|
const allPage = Math.ceil(this.total / this.currentPageSize);
|
4935594e
梁灏
fixed #21
|
144
|
return (allPage === 0) ? 1 : allPage;
|
7fa943eb
梁灏
init
|
145
146
147
148
|
},
simpleWrapClasses () {
return [
`${prefixCls}`,
|
e0cd7f90
梁灏
fixed #134
|
149
150
|
`${prefixCls}-simple`,
{
|
87c51597
梁灏
support Page
|
151
|
[`${this.className}`]: !!this.className
|
e0cd7f90
梁灏
fixed #134
|
152
|
}
|
b0893113
jingsam
add eslint
|
153
|
];
|
7fa943eb
梁灏
init
|
154
|
},
|
93064e3b
梁灏
add Page UI
|
155
156
157
|
simplePagerClasses () {
return `${prefixCls}-simple-pager`;
},
|
7fa943eb
梁灏
init
|
158
159
160
161
|
wrapClasses () {
return [
`${prefixCls}`,
{
|
87c51597
梁灏
support Page
|
162
|
[`${this.className}`]: !!this.className,
|
7fa943eb
梁灏
init
|
163
164
|
'mini': !!this.size
}
|
b0893113
jingsam
add eslint
|
165
|
];
|
7fa943eb
梁灏
init
|
166
167
168
169
170
|
},
prevClasses () {
return [
`${prefixCls}-prev`,
{
|
87c51597
梁灏
support Page
|
171
|
[`${prefixCls}-disabled`]: this.currentPage === 1
|
7fa943eb
梁灏
init
|
172
|
}
|
b0893113
jingsam
add eslint
|
173
|
];
|
7fa943eb
梁灏
init
|
174
175
176
177
178
|
},
nextClasses () {
return [
`${prefixCls}-next`,
{
|
87c51597
梁灏
support Page
|
179
|
[`${prefixCls}-disabled`]: this.currentPage === this.allPages
|
7fa943eb
梁灏
init
|
180
|
}
|
b0893113
jingsam
add eslint
|
181
|
];
|
d6342fe1
jingsam
fixed ie bug
|
182
183
184
185
186
|
},
firstPageClasses () {
return [
`${prefixCls}-item`,
{
|
87c51597
梁灏
support Page
|
187
|
[`${prefixCls}-item-active`]: this.currentPage === 1
|
d6342fe1
jingsam
fixed ie bug
|
188
|
}
|
b0893113
jingsam
add eslint
|
189
|
];
|
d6342fe1
jingsam
fixed ie bug
|
190
191
192
193
194
|
},
lastPageClasses () {
return [
`${prefixCls}-item`,
{
|
87c51597
梁灏
support Page
|
195
|
[`${prefixCls}-item-active`]: this.currentPage === this.allPages
|
d6342fe1
jingsam
fixed ie bug
|
196
|
}
|
b0893113
jingsam
add eslint
|
197
|
];
|
7fa943eb
梁灏
init
|
198
199
200
201
|
}
},
methods: {
changePage (page) {
|
87c51597
梁灏
support Page
|
202
203
|
if (this.currentPage != page) {
this.currentPage = page;
|
7fa943eb
梁灏
init
|
204
205
206
207
|
this.$emit('on-change', page);
}
},
prev () {
|
87c51597
梁灏
support Page
|
208
|
const current = this.currentPage;
|
7fa943eb
梁灏
init
|
209
210
211
212
213
214
|
if (current <= 1) {
return false;
}
this.changePage(current - 1);
},
next () {
|
87c51597
梁灏
support Page
|
215
|
const current = this.currentPage;
|
7fa943eb
梁灏
init
|
216
217
218
219
220
221
|
if (current >= this.allPages) {
return false;
}
this.changePage(current + 1);
},
fastPrev () {
|
87c51597
梁灏
support Page
|
222
|
const page = this.currentPage - 5;
|
7fa943eb
梁灏
init
|
223
224
225
226
227
228
229
|
if (page > 0) {
this.changePage(page);
} else {
this.changePage(1);
}
},
fastNext () {
|
87c51597
梁灏
support Page
|
230
|
const page = this.currentPage + 5;
|
7fa943eb
梁灏
init
|
231
232
233
234
235
236
237
|
if (page > this.allPages) {
this.changePage(this.allPages);
} else {
this.changePage(page);
}
},
onSize (pageSize) {
|
87c51597
梁灏
support Page
|
238
|
this.currentPageSize = pageSize;
|
7fa943eb
梁灏
init
|
239
|
this.changePage(1);
|
07f400e5
梁灏
fixed #136
|
240
|
this.$emit('on-page-size-change', pageSize);
|
7fa943eb
梁灏
init
|
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
},
onPage (page) {
this.changePage(page);
},
keyDown (e) {
const key = e.keyCode;
const condition = (key >= 48 && key <= 57) || key == 8 || key == 37 || key == 39;
if (!condition) {
e.preventDefault();
}
},
keyUp (e) {
const key = e.keyCode;
const val = parseInt(e.target.value);
if (key === 38) {
|
b0893113
jingsam
add eslint
|
258
|
this.prev();
|
7fa943eb
梁灏
init
|
259
|
} else if (key === 40) {
|
b0893113
jingsam
add eslint
|
260
|
this.next();
|
7fa943eb
梁灏
init
|
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
} else if (key == 13) {
let page = 1;
if (val > this.allPages) {
page = this.allPages;
} else if (val <= 0) {
page = 1;
} else {
page = val;
}
e.target.value = page;
this.changePage(page);
}
}
}
|
b0893113
jingsam
add eslint
|
277
|
};
|
d6342fe1
jingsam
fixed ie bug
|
278
|
</script>
|