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