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