@10yun/cv-mobile-ui 0.5.20 → 0.5.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugins/jumps.js +57 -12
- package/plugins/lbs.js +17 -8
- package/ui-cv/components/cv-grid-item/cv-grid-item.vue +1 -1
- package/uni-ui/lib/uni-badge/uni-badge.vue +150 -1
- package/uni-ui/lib/uni-breadcrumb/uni-breadcrumb.vue +37 -1
- package/uni-ui/lib/uni-breadcrumb-item/uni-breadcrumb-item.vue +83 -1
- package/uni-ui/lib/uni-calendar/uni-calendar-item.vue +122 -1
- package/uni-ui/lib/uni-calendar/uni-calendar.vue +366 -1
- package/uni-ui/lib/uni-card/uni-card.vue +124 -1
- package/uni-ui/lib/uni-col/uni-col.vue +1 -1
- package/uni-ui/lib/uni-collapse/uni-collapse.vue +135 -1
- package/uni-ui/lib/uni-collapse-item/uni-collapse-item.vue +266 -1
- package/uni-ui/lib/uni-combox/uni-combox.vue +1 -1
- package/uni-ui/lib/uni-countdown/uni-countdown.vue +239 -1
- package/uni-ui/lib/uni-data-checkbox/uni-data-checkbox.vue +487 -1
- package/uni-ui/lib/uni-data-picker/uni-data-picker.vue +530 -1
- package/uni-ui/lib/uni-data-pickerview/uni-data-picker.js +157 -150
- package/uni-ui/lib/uni-data-pickerview/uni-data-pickerview.vue +166 -1
- package/uni-ui/lib/uni-data-select/uni-data-select.vue +289 -1
- package/uni-ui/lib/uni-datetime-picker/calendar-item.vue +70 -1
- package/uni-ui/lib/uni-datetime-picker/calendar.vue +629 -1
- package/uni-ui/lib/uni-datetime-picker/time-picker.vue +741 -1
- package/uni-ui/lib/uni-datetime-picker/uni-datetime-picker.vue +847 -1
- package/uni-ui/lib/uni-drawer/uni-drawer.vue +115 -1
- package/uni-ui/lib/uni-easyinput/uni-easyinput.vue +515 -1
- package/uni-ui/lib/uni-fab/uni-fab.vue +257 -1
- package/uni-ui/lib/uni-fav/uni-fav.vue +123 -1
- package/uni-ui/lib/uni-file-picker/uni-file-picker.vue +642 -1
- package/uni-ui/lib/uni-file-picker/upload-file.vue +177 -1
- package/uni-ui/lib/uni-file-picker/upload-image.vue +176 -1
- package/uni-ui/lib/uni-forms/uni-forms.vue +375 -1
- package/uni-ui/lib/uni-forms-item/uni-forms-item.vue +429 -1
- package/uni-ui/lib/uni-goods-nav/uni-goods-nav.vue +129 -1
- package/uni-ui/lib/uni-grid/uni-grid.vue +115 -1
- package/uni-ui/lib/uni-grid-item/uni-grid-item.vue +78 -1
- package/uni-ui/lib/uni-group/uni-group.vue +85 -1
- package/uni-ui/lib/uni-icons/uni-icons.vue +85 -1
- package/uni-ui/lib/uni-indexed-list/uni-indexed-list-item.vue +68 -1
- package/uni-ui/lib/uni-indexed-list/uni-indexed-list.vue +294 -1
- package/uni-ui/lib/uni-list/uni-list.vue +81 -1
- package/uni-ui/lib/uni-list-ad/uni-list-ad.vue +77 -1
- package/uni-ui/lib/uni-list-chat/uni-list-chat.vue +294 -1
- package/uni-ui/lib/uni-list-item/uni-list-item.vue +346 -1
- package/uni-ui/lib/uni-load-more/uni-load-more.vue +172 -1
- package/uni-ui/lib/uni-nav-bar/uni-nav-bar.vue +205 -1
- package/uni-ui/lib/uni-nav-bar/uni-status-bar.vue +18 -1
- package/uni-ui/lib/uni-notice-bar/uni-notice-bar.vue +331 -1
- package/uni-ui/lib/uni-number-box/uni-number-box.vue +166 -1
- package/uni-ui/lib/uni-pagination/uni-pagination.vue +323 -1
- package/uni-ui/lib/uni-popup/uni-popup.vue +1 -1
- package/uni-ui/lib/uni-popup-dialog/uni-popup-dialog.vue +173 -1
- package/uni-ui/lib/uni-popup-message/uni-popup-message.vue +74 -1
- package/uni-ui/lib/uni-popup-share/uni-popup-share.vue +106 -1
- package/uni-ui/lib/uni-rate/uni-rate.vue +322 -1
- package/uni-ui/lib/uni-row/uni-row.vue +1 -1
- package/uni-ui/lib/uni-search-bar/uni-search-bar.vue +236 -1
- package/uni-ui/lib/uni-section/uni-section.vue +109 -1
- package/uni-ui/lib/uni-segmented-control/uni-segmented-control.vue +103 -1
- package/uni-ui/lib/uni-status-bar/uni-status-bar.vue +1 -1
- package/uni-ui/lib/uni-steps/uni-steps.vue +120 -1
- package/uni-ui/lib/uni-swipe-action-item/uni-swipe-action-item.vue +226 -3
- package/uni-ui/lib/uni-swiper-dot/uni-swiper-dot.vue +167 -1
- package/uni-ui/lib/uni-table/uni-table.vue +297 -1
- package/uni-ui/lib/uni-tag/uni-tag.vue +100 -1
- package/uni-ui/lib/uni-td/uni-td.vue +78 -1
- package/uni-ui/lib/uni-th/filter-dropdown.vue +1 -1
- package/uni-ui/lib/uni-th/uni-th.vue +224 -1
- package/uni-ui/lib/uni-thead/uni-thead.vue +77 -1
- package/uni-ui/lib/uni-tr/table-checkbox.vue +79 -1
- package/uni-ui/lib/uni-tr/uni-tr.vue +135 -1
|
@@ -1 +1,323 @@
|
|
|
1
|
-
<template>
|
|
2
1
|
<view class="uni-pagination">
|
|
3
2
|
<!-- #ifndef MP -->
|
|
4
3
|
<picker
|
|
5
4
|
v-if="showPageSize === true || showPageSize === 'true'"
|
|
6
5
|
class="select-picker"
|
|
7
6
|
mode="selector"
|
|
8
7
|
:value="pageSizeIndex"
|
|
9
8
|
:range="pageSizeRange"
|
|
10
9
|
@change="pickerChange"
|
|
11
10
|
@cancel="pickerClick"
|
|
12
11
|
@click.native="pickerClick"
|
|
13
12
|
>
|
|
14
13
|
<button type="default" size="mini" :plain="true">
|
|
15
14
|
<text>{{ pageSizeRange[pageSizeIndex] }} {{ piecePerPage }}</text>
|
|
16
15
|
<uni-icons class="select-picker-icon" type="arrowdown" size="12" color="#999"></uni-icons>
|
|
17
16
|
</button>
|
|
18
17
|
</picker>
|
|
19
18
|
<!-- #endif -->
|
|
20
19
|
<!-- #ifndef APP-NVUE -->
|
|
21
20
|
<view class="uni-pagination__total is-phone-hide">共 {{ total }} 条</view>
|
|
22
21
|
<!-- #endif -->
|
|
23
22
|
<view
|
|
24
23
|
class="uni-pagination__btn"
|
|
25
24
|
:class="currentIndex === 1 ? 'uni-pagination--disabled' : 'uni-pagination--enabled'"
|
|
26
25
|
:hover-class="currentIndex === 1 ? '' : 'uni-pagination--hover'"
|
|
27
26
|
:hover-start-time="20"
|
|
28
27
|
:hover-stay-time="70"
|
|
29
28
|
@click="clickLeft"
|
|
30
29
|
>
|
|
31
30
|
<template v-if="showIcon === true || showIcon === 'true'">
|
|
32
31
|
<uni-icons color="#666" size="16" type="left" />
|
|
33
32
|
</template>
|
|
34
33
|
<template v-else>
|
|
35
34
|
<text class="uni-pagination__child-btn">{{ prevPageText }}</text>
|
|
36
35
|
</template>
|
|
37
36
|
</view>
|
|
38
37
|
<view class="uni-pagination__num uni-pagination__num-flex-none">
|
|
39
38
|
<view class="uni-pagination__num-current">
|
|
40
39
|
<text class="uni-pagination__num-current-text is-pc-hide current-index-text">{{ currentIndex }}</text>
|
|
41
40
|
<text class="uni-pagination__num-current-text is-pc-hide">/{{ maxPage || 0 }}</text>
|
|
42
41
|
<!-- #ifndef APP-NVUE -->
|
|
43
42
|
<view
|
|
44
43
|
v-for="(item, index) in paper"
|
|
45
44
|
:key="index"
|
|
46
45
|
:class="{ 'page--active': item === currentIndex }"
|
|
47
46
|
class="uni-pagination__num-tag tag--active is-phone-hide"
|
|
48
47
|
@click.top="selectPage(item, index)"
|
|
49
48
|
>
|
|
50
49
|
<text>{{ item }}</text>
|
|
51
50
|
</view>
|
|
52
51
|
<!-- #endif -->
|
|
53
52
|
</view>
|
|
54
53
|
</view>
|
|
55
54
|
<view
|
|
56
55
|
class="uni-pagination__btn"
|
|
57
56
|
:class="currentIndex >= maxPage ? 'uni-pagination--disabled' : 'uni-pagination--enabled'"
|
|
58
57
|
:hover-class="currentIndex === maxPage ? '' : 'uni-pagination--hover'"
|
|
59
58
|
:hover-start-time="20"
|
|
60
59
|
:hover-stay-time="70"
|
|
61
60
|
@click="clickRight"
|
|
62
61
|
>
|
|
63
62
|
<template v-if="showIcon === true || showIcon === 'true'">
|
|
64
63
|
<uni-icons color="#666" size="16" type="right" />
|
|
65
64
|
</template>
|
|
66
65
|
<template v-else>
|
|
67
66
|
<text class="uni-pagination__child-btn">{{ nextPageText }}</text>
|
|
68
67
|
</template>
|
|
69
68
|
</view>
|
|
70
69
|
</view>
|
|
71
70
|
* Pagination 分页器
|
|
72
71
|
* @description 分页器组件,用于展示页码、请求数据等
|
|
73
72
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=32
|
|
74
73
|
* @property {String} prevText 左侧按钮文字
|
|
75
74
|
* @property {String} nextText 右侧按钮文字
|
|
76
75
|
* @property {String} piecePerPageText 条/页文字
|
|
77
76
|
* @property {Number} current 当前页
|
|
78
77
|
* @property {Number} total 数据总量
|
|
79
78
|
* @property {Number} pageSize 每页数据量
|
|
80
79
|
* @property {Boolean} showIcon = [true|false] 是否以 icon 形式展示按钮
|
|
81
80
|
* @property {Boolean} showPageSize = [true|false] 是否展示每页条数
|
|
82
81
|
* @property {Array} pageSizeRange = [20, 50, 100, 500] 每页条数选框
|
|
83
82
|
* @event {Function} change 点击页码按钮时触发 ,e={type,current} current为当前页,type值为:next/prev,表示点击的是上一页还是下一个
|
|
84
83
|
* * @event {Function} pageSizeChange 当前每页条数改变时触发 ,e={pageSize} pageSize 为当前所选的每页条数
|
|
85
84
|
*/
|
|
86
85
|
name: 'UniPagination',
|
|
87
86
|
emits: ['update:modelValue', 'input', 'change', 'pageSizeChange'],
|
|
88
87
|
props: {
|
|
89
88
|
value: {
|
|
90
89
|
type: [Number, String],
|
|
91
90
|
default: 1
|
|
92
91
|
},
|
|
93
92
|
modelValue: {
|
|
94
93
|
type: [Number, String],
|
|
95
94
|
default: 1
|
|
96
95
|
},
|
|
97
96
|
prevText: {
|
|
98
97
|
type: String
|
|
99
98
|
},
|
|
100
99
|
nextText: {
|
|
101
100
|
type: String
|
|
102
101
|
},
|
|
103
102
|
piecePerPageText: {
|
|
104
103
|
type: String
|
|
105
104
|
},
|
|
106
105
|
current: {
|
|
107
106
|
type: [Number, String],
|
|
108
107
|
default: 1
|
|
109
108
|
},
|
|
110
109
|
total: {
|
|
111
110
|
// 数据总量
|
|
112
111
|
type: [Number, String],
|
|
113
112
|
default: 0
|
|
114
113
|
},
|
|
115
114
|
pageSize: {
|
|
116
115
|
// 每页数据量
|
|
117
116
|
type: [Number, String],
|
|
118
117
|
default: 10
|
|
119
118
|
},
|
|
120
119
|
showIcon: {
|
|
121
120
|
// 是否以 icon 形式展示按钮
|
|
122
121
|
type: [Boolean, String],
|
|
123
122
|
default: false
|
|
124
123
|
},
|
|
125
124
|
showPageSize: {
|
|
126
125
|
// 是否以 icon 形式展示按钮
|
|
127
126
|
type: [Boolean, String],
|
|
128
127
|
default: false
|
|
129
128
|
},
|
|
130
129
|
pagerCount: {
|
|
131
130
|
type: Number,
|
|
132
131
|
default: 7
|
|
133
132
|
},
|
|
134
133
|
pageSizeRange: {
|
|
135
134
|
type: Array,
|
|
136
135
|
default: () => [20, 50, 100, 500]
|
|
137
136
|
}
|
|
138
137
|
},
|
|
139
138
|
data() {
|
|
140
139
|
return {
|
|
141
140
|
pageSizeIndex: 0,
|
|
142
141
|
currentIndex: 1,
|
|
143
142
|
paperData: [],
|
|
144
143
|
pickerShow: false
|
|
145
144
|
};
|
|
146
145
|
},
|
|
147
146
|
computed: {
|
|
148
147
|
piecePerPage() {
|
|
149
148
|
return this.piecePerPageText || t('uni-pagination.piecePerPage');
|
|
150
149
|
},
|
|
151
150
|
prevPageText() {
|
|
152
151
|
return this.prevText || t('uni-pagination.prevText');
|
|
153
152
|
},
|
|
154
153
|
nextPageText() {
|
|
155
154
|
return this.nextText || t('uni-pagination.nextText');
|
|
156
155
|
},
|
|
157
156
|
maxPage() {
|
|
158
157
|
let maxPage = 1;
|
|
159
158
|
let total = Number(this.total);
|
|
160
159
|
let pageSize = Number(this.pageSize);
|
|
161
160
|
if (total && pageSize) {
|
|
162
161
|
maxPage = Math.ceil(total / pageSize);
|
|
163
162
|
}
|
|
164
163
|
return maxPage;
|
|
165
164
|
},
|
|
166
165
|
paper() {
|
|
167
166
|
const num = this.currentIndex;
|
|
168
167
|
// TODO 最大页数
|
|
169
168
|
const pagerCount = this.pagerCount;
|
|
170
169
|
// const total = 181
|
|
171
170
|
const total = this.total;
|
|
172
171
|
const pageSize = this.pageSize;
|
|
173
172
|
let totalArr = [];
|
|
174
173
|
let showPagerArr = [];
|
|
175
174
|
let pagerNum = Math.ceil(total / pageSize);
|
|
176
175
|
for (let i = 0; i < pagerNum; i++) {
|
|
177
176
|
totalArr.push(i + 1);
|
|
178
177
|
}
|
|
179
178
|
showPagerArr.push(1);
|
|
180
179
|
const totalNum = totalArr[totalArr.length - (pagerCount + 1) / 2];
|
|
181
180
|
totalArr.forEach((item, index) => {
|
|
182
181
|
if ((pagerCount + 1) / 2 >= num) {
|
|
183
182
|
if (item < pagerCount + 1 && item > 1) {
|
|
184
183
|
showPagerArr.push(item);
|
|
185
184
|
}
|
|
186
185
|
} else if (num + 2 <= totalNum) {
|
|
187
186
|
if (item > num - (pagerCount + 1) / 2 && item < num + (pagerCount + 1) / 2) {
|
|
188
187
|
showPagerArr.push(item);
|
|
189
188
|
}
|
|
190
189
|
} else {
|
|
191
190
|
if ((item > num - (pagerCount + 1) / 2 || pagerNum - pagerCount < item) && item < totalArr[totalArr.length - 1]) {
|
|
192
191
|
showPagerArr.push(item);
|
|
193
192
|
}
|
|
194
193
|
}
|
|
195
194
|
});
|
|
196
195
|
if (pagerNum > pagerCount) {
|
|
197
196
|
if ((pagerCount + 1) / 2 >= num) {
|
|
198
197
|
showPagerArr[showPagerArr.length - 1] = '...';
|
|
199
198
|
} else if (num + 2 <= totalNum) {
|
|
200
199
|
showPagerArr[1] = '...';
|
|
201
200
|
showPagerArr[showPagerArr.length - 1] = '...';
|
|
202
201
|
} else {
|
|
203
202
|
showPagerArr[1] = '...';
|
|
204
203
|
}
|
|
205
204
|
showPagerArr.push(totalArr[totalArr.length - 1]);
|
|
206
205
|
} else {
|
|
207
206
|
if ((pagerCount + 1) / 2 >= num) {
|
|
208
207
|
} else if (num + 2 <= totalNum) {
|
|
209
208
|
} else {
|
|
210
209
|
showPagerArr.shift();
|
|
211
210
|
showPagerArr.push(totalArr[totalArr.length - 1]);
|
|
212
211
|
}
|
|
213
212
|
}
|
|
214
213
|
return showPagerArr;
|
|
215
214
|
}
|
|
216
215
|
},
|
|
217
216
|
watch: {
|
|
218
217
|
current: {
|
|
219
218
|
immediate: true,
|
|
220
219
|
handler(val, old) {
|
|
221
220
|
if (val < 1) {
|
|
222
221
|
this.currentIndex = 1;
|
|
223
222
|
} else {
|
|
224
223
|
this.currentIndex = val;
|
|
225
224
|
}
|
|
226
225
|
}
|
|
227
226
|
},
|
|
228
227
|
value: {
|
|
229
228
|
immediate: true,
|
|
230
229
|
handler(val) {
|
|
231
230
|
if (Number(this.current) !== 1) return;
|
|
232
231
|
if (val < 1) {
|
|
233
232
|
this.currentIndex = 1;
|
|
234
233
|
} else {
|
|
235
234
|
this.currentIndex = val;
|
|
236
235
|
}
|
|
237
236
|
}
|
|
238
237
|
},
|
|
239
238
|
pageSizeIndex(val) {
|
|
240
239
|
this.$emit('pageSizeChange', this.pageSizeRange[val]);
|
|
241
240
|
}
|
|
242
241
|
},
|
|
243
242
|
methods: {
|
|
244
243
|
pickerChange(e) {
|
|
245
244
|
this.pageSizeIndex = e.detail.value;
|
|
246
245
|
this.pickerClick();
|
|
247
246
|
},
|
|
248
247
|
pickerClick() {
|
|
249
248
|
// #ifdef H5
|
|
250
249
|
const body = document.querySelector('body');
|
|
251
250
|
if (!body) return;
|
|
252
251
|
const className = 'uni-pagination-picker-show';
|
|
253
252
|
this.pickerShow = !this.pickerShow;
|
|
254
253
|
if (this.pickerShow) {
|
|
255
254
|
body.classList.add(className);
|
|
256
255
|
} else {
|
|
257
256
|
setTimeout(() => body.classList.remove(className), 300);
|
|
258
257
|
}
|
|
259
258
|
// #endif
|
|
260
259
|
},
|
|
261
260
|
// 选择标签
|
|
262
261
|
selectPage(e, index) {
|
|
263
262
|
if (parseInt(e)) {
|
|
264
263
|
this.currentIndex = e;
|
|
265
264
|
this.change('current');
|
|
266
265
|
} else {
|
|
267
266
|
let pagerNum = Math.ceil(this.total / this.pageSize);
|
|
268
267
|
// let pagerNum = Math.ceil(181 / this.pageSize)
|
|
269
268
|
// 上一页
|
|
270
269
|
if (index <= 1) {
|
|
271
270
|
if (this.currentIndex - 5 > 1) {
|
|
272
271
|
this.currentIndex -= 5;
|
|
273
272
|
} else {
|
|
274
273
|
this.currentIndex = 1;
|
|
275
274
|
}
|
|
276
275
|
return;
|
|
277
276
|
}
|
|
278
277
|
// 下一页
|
|
279
278
|
if (index >= 6) {
|
|
280
279
|
if (this.currentIndex + 5 > pagerNum) {
|
|
281
280
|
this.currentIndex = pagerNum;
|
|
282
281
|
} else {
|
|
283
282
|
this.currentIndex += 5;
|
|
284
283
|
}
|
|
285
284
|
return;
|
|
286
285
|
}
|
|
287
286
|
}
|
|
288
287
|
},
|
|
289
288
|
clickLeft() {
|
|
290
289
|
if (Number(this.currentIndex) === 1) {
|
|
291
290
|
return;
|
|
292
291
|
}
|
|
293
292
|
this.currentIndex -= 1;
|
|
294
293
|
this.change('prev');
|
|
295
294
|
},
|
|
296
295
|
clickRight() {
|
|
297
296
|
if (Number(this.currentIndex) >= this.maxPage) {
|
|
298
297
|
return;
|
|
299
298
|
}
|
|
300
299
|
this.currentIndex += 1;
|
|
301
300
|
this.change('next');
|
|
302
301
|
},
|
|
303
302
|
change(e) {
|
|
304
303
|
this.$emit('input', this.currentIndex);
|
|
305
304
|
this.$emit('update:modelValue', this.currentIndex);
|
|
306
305
|
this.$emit('change', {
|
|
307
306
|
type: e,
|
|
308
307
|
current: this.currentIndex
|
|
309
308
|
});
|
|
310
309
|
}
|
|
311
310
|
}
|
|
311
|
+
<template>
|
|
312
|
+
<view class="uni-pagination">
|
|
313
|
+
<!-- #ifndef MP -->
|
|
314
|
+
<picker
|
|
315
|
+
v-if="showPageSize === true || showPageSize === 'true'"
|
|
316
|
+
class="select-picker"
|
|
317
|
+
mode="selector"
|
|
318
|
+
:value="pageSizeIndex"
|
|
319
|
+
:range="pageSizeRange"
|
|
320
|
+
@change="pickerChange"
|
|
321
|
+
@cancel="pickerClick"
|
|
322
|
+
@click.native="pickerClick"
|
|
323
|
+
>
|
|
324
|
+
<button type="default" size="mini" :plain="true">
|
|
325
|
+
<text>{{ pageSizeRange[pageSizeIndex] }} {{ piecePerPage }}</text>
|
|
326
|
+
<uni-icons class="select-picker-icon" type="arrowdown" size="12" color="#999"></uni-icons>
|
|
327
|
+
</button>
|
|
328
|
+
</picker>
|
|
329
|
+
<!-- #endif -->
|
|
330
|
+
<!-- #ifndef APP-NVUE -->
|
|
331
|
+
<view class="uni-pagination__total is-phone-hide">共 {{ total }} 条</view>
|
|
332
|
+
<!-- #endif -->
|
|
333
|
+
<view
|
|
334
|
+
class="uni-pagination__btn"
|
|
335
|
+
:class="currentIndex === 1 ? 'uni-pagination--disabled' : 'uni-pagination--enabled'"
|
|
336
|
+
:hover-class="currentIndex === 1 ? '' : 'uni-pagination--hover'"
|
|
337
|
+
:hover-start-time="20"
|
|
338
|
+
:hover-stay-time="70"
|
|
339
|
+
@click="clickLeft"
|
|
340
|
+
>
|
|
341
|
+
<template v-if="showIcon === true || showIcon === 'true'">
|
|
342
|
+
<uni-icons color="#666" size="16" type="left" />
|
|
343
|
+
</template>
|
|
344
|
+
<template v-else>
|
|
345
|
+
<text class="uni-pagination__child-btn">{{ prevPageText }}</text>
|
|
346
|
+
</template>
|
|
347
|
+
</view>
|
|
348
|
+
<view class="uni-pagination__num uni-pagination__num-flex-none">
|
|
349
|
+
<view class="uni-pagination__num-current">
|
|
350
|
+
<text class="uni-pagination__num-current-text is-pc-hide current-index-text">{{ currentIndex }}</text>
|
|
351
|
+
<text class="uni-pagination__num-current-text is-pc-hide">/{{ maxPage || 0 }}</text>
|
|
352
|
+
<!-- #ifndef APP-NVUE -->
|
|
353
|
+
<view
|
|
354
|
+
v-for="(item, index) in paper"
|
|
355
|
+
:key="index"
|
|
356
|
+
:class="{ 'page--active': item === currentIndex }"
|
|
357
|
+
class="uni-pagination__num-tag tag--active is-phone-hide"
|
|
358
|
+
@click.top="selectPage(item, index)"
|
|
359
|
+
>
|
|
360
|
+
<text>{{ item }}</text>
|
|
361
|
+
</view>
|
|
362
|
+
<!-- #endif -->
|
|
363
|
+
</view>
|
|
364
|
+
</view>
|
|
365
|
+
<view
|
|
366
|
+
class="uni-pagination__btn"
|
|
367
|
+
:class="currentIndex >= maxPage ? 'uni-pagination--disabled' : 'uni-pagination--enabled'"
|
|
368
|
+
:hover-class="currentIndex === maxPage ? '' : 'uni-pagination--hover'"
|
|
369
|
+
:hover-start-time="20"
|
|
370
|
+
:hover-stay-time="70"
|
|
371
|
+
@click="clickRight"
|
|
372
|
+
>
|
|
373
|
+
<template v-if="showIcon === true || showIcon === 'true'">
|
|
374
|
+
<uni-icons color="#666" size="16" type="right" />
|
|
375
|
+
</template>
|
|
376
|
+
<template v-else>
|
|
377
|
+
<text class="uni-pagination__child-btn">{{ nextPageText }}</text>
|
|
378
|
+
</template>
|
|
379
|
+
</view>
|
|
380
|
+
</view>
|
|
381
|
+
</template>
|
|
382
|
+
<script>
|
|
383
|
+
/**
|
|
384
|
+
* Pagination 分页器
|
|
385
|
+
* @description 分页器组件,用于展示页码、请求数据等
|
|
386
|
+
* @tutorial https://ext.dcloud.net.cn/plugin?id=32
|
|
387
|
+
* @property {String} prevText 左侧按钮文字
|
|
388
|
+
* @property {String} nextText 右侧按钮文字
|
|
389
|
+
* @property {String} piecePerPageText 条/页文字
|
|
390
|
+
* @property {Number} current 当前页
|
|
391
|
+
* @property {Number} total 数据总量
|
|
392
|
+
* @property {Number} pageSize 每页数据量
|
|
393
|
+
* @property {Boolean} showIcon = [true|false] 是否以 icon 形式展示按钮
|
|
394
|
+
* @property {Boolean} showPageSize = [true|false] 是否展示每页条数
|
|
395
|
+
* @property {Array} pageSizeRange = [20, 50, 100, 500] 每页条数选框
|
|
396
|
+
* @event {Function} change 点击页码按钮时触发 ,e={type,current} current为当前页,type值为:next/prev,表示点击的是上一页还是下一个
|
|
397
|
+
* * @event {Function} pageSizeChange 当前每页条数改变时触发 ,e={pageSize} pageSize 为当前所选的每页条数
|
|
398
|
+
*/
|
|
399
|
+
import { initVueI18n } from '@dcloudio/uni-i18n';
|
|
400
|
+
import messages from './i18n/index.js';
|
|
401
|
+
const { t } = initVueI18n(messages);
|
|
402
|
+
export default {
|
|
403
|
+
name: 'UniPagination',
|
|
404
|
+
emits: ['update:modelValue', 'input', 'change', 'pageSizeChange'],
|
|
405
|
+
props: {
|
|
406
|
+
value: {
|
|
407
|
+
type: [Number, String],
|
|
408
|
+
default: 1
|
|
409
|
+
},
|
|
410
|
+
modelValue: {
|
|
411
|
+
type: [Number, String],
|
|
412
|
+
default: 1
|
|
413
|
+
},
|
|
414
|
+
prevText: {
|
|
415
|
+
type: String
|
|
416
|
+
},
|
|
417
|
+
nextText: {
|
|
418
|
+
type: String
|
|
419
|
+
},
|
|
420
|
+
piecePerPageText: {
|
|
421
|
+
type: String
|
|
422
|
+
},
|
|
423
|
+
current: {
|
|
424
|
+
type: [Number, String],
|
|
425
|
+
default: 1
|
|
426
|
+
},
|
|
427
|
+
total: {
|
|
428
|
+
// 数据总量
|
|
429
|
+
type: [Number, String],
|
|
430
|
+
default: 0
|
|
431
|
+
},
|
|
432
|
+
pageSize: {
|
|
433
|
+
// 每页数据量
|
|
434
|
+
type: [Number, String],
|
|
435
|
+
default: 10
|
|
436
|
+
},
|
|
437
|
+
showIcon: {
|
|
438
|
+
// 是否以 icon 形式展示按钮
|
|
439
|
+
type: [Boolean, String],
|
|
440
|
+
default: false
|
|
441
|
+
},
|
|
442
|
+
showPageSize: {
|
|
443
|
+
// 是否以 icon 形式展示按钮
|
|
444
|
+
type: [Boolean, String],
|
|
445
|
+
default: false
|
|
446
|
+
},
|
|
447
|
+
pagerCount: {
|
|
448
|
+
type: Number,
|
|
449
|
+
default: 7
|
|
450
|
+
},
|
|
451
|
+
pageSizeRange: {
|
|
452
|
+
type: Array,
|
|
453
|
+
default: () => [20, 50, 100, 500]
|
|
454
|
+
}
|
|
455
|
+
},
|
|
456
|
+
data() {
|
|
457
|
+
return {
|
|
458
|
+
pageSizeIndex: 0,
|
|
459
|
+
currentIndex: 1,
|
|
460
|
+
paperData: [],
|
|
461
|
+
pickerShow: false
|
|
462
|
+
};
|
|
463
|
+
},
|
|
464
|
+
computed: {
|
|
465
|
+
piecePerPage() {
|
|
466
|
+
return this.piecePerPageText || t('uni-pagination.piecePerPage');
|
|
467
|
+
},
|
|
468
|
+
prevPageText() {
|
|
469
|
+
return this.prevText || t('uni-pagination.prevText');
|
|
470
|
+
},
|
|
471
|
+
nextPageText() {
|
|
472
|
+
return this.nextText || t('uni-pagination.nextText');
|
|
473
|
+
},
|
|
474
|
+
maxPage() {
|
|
475
|
+
let maxPage = 1;
|
|
476
|
+
let total = Number(this.total);
|
|
477
|
+
let pageSize = Number(this.pageSize);
|
|
478
|
+
if (total && pageSize) {
|
|
479
|
+
maxPage = Math.ceil(total / pageSize);
|
|
480
|
+
}
|
|
481
|
+
return maxPage;
|
|
482
|
+
},
|
|
483
|
+
paper() {
|
|
484
|
+
const num = this.currentIndex;
|
|
485
|
+
// TODO 最大页数
|
|
486
|
+
const pagerCount = this.pagerCount;
|
|
487
|
+
// const total = 181
|
|
488
|
+
const total = this.total;
|
|
489
|
+
const pageSize = this.pageSize;
|
|
490
|
+
let totalArr = [];
|
|
491
|
+
let showPagerArr = [];
|
|
492
|
+
let pagerNum = Math.ceil(total / pageSize);
|
|
493
|
+
for (let i = 0; i < pagerNum; i++) {
|
|
494
|
+
totalArr.push(i + 1);
|
|
495
|
+
}
|
|
496
|
+
showPagerArr.push(1);
|
|
497
|
+
const totalNum = totalArr[totalArr.length - (pagerCount + 1) / 2];
|
|
498
|
+
totalArr.forEach((item, index) => {
|
|
499
|
+
if ((pagerCount + 1) / 2 >= num) {
|
|
500
|
+
if (item < pagerCount + 1 && item > 1) {
|
|
501
|
+
showPagerArr.push(item);
|
|
502
|
+
}
|
|
503
|
+
} else if (num + 2 <= totalNum) {
|
|
504
|
+
if (item > num - (pagerCount + 1) / 2 && item < num + (pagerCount + 1) / 2) {
|
|
505
|
+
showPagerArr.push(item);
|
|
506
|
+
}
|
|
507
|
+
} else {
|
|
508
|
+
if ((item > num - (pagerCount + 1) / 2 || pagerNum - pagerCount < item) && item < totalArr[totalArr.length - 1]) {
|
|
509
|
+
showPagerArr.push(item);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
if (pagerNum > pagerCount) {
|
|
514
|
+
if ((pagerCount + 1) / 2 >= num) {
|
|
515
|
+
showPagerArr[showPagerArr.length - 1] = '...';
|
|
516
|
+
} else if (num + 2 <= totalNum) {
|
|
517
|
+
showPagerArr[1] = '...';
|
|
518
|
+
showPagerArr[showPagerArr.length - 1] = '...';
|
|
519
|
+
} else {
|
|
520
|
+
showPagerArr[1] = '...';
|
|
521
|
+
}
|
|
522
|
+
showPagerArr.push(totalArr[totalArr.length - 1]);
|
|
523
|
+
} else {
|
|
524
|
+
if ((pagerCount + 1) / 2 >= num) {
|
|
525
|
+
} else if (num + 2 <= totalNum) {
|
|
526
|
+
} else {
|
|
527
|
+
showPagerArr.shift();
|
|
528
|
+
showPagerArr.push(totalArr[totalArr.length - 1]);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return showPagerArr;
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
watch: {
|
|
535
|
+
current: {
|
|
536
|
+
immediate: true,
|
|
537
|
+
handler(val, old) {
|
|
538
|
+
if (val < 1) {
|
|
539
|
+
this.currentIndex = 1;
|
|
540
|
+
} else {
|
|
541
|
+
this.currentIndex = val;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
value: {
|
|
546
|
+
immediate: true,
|
|
547
|
+
handler(val) {
|
|
548
|
+
if (Number(this.current) !== 1) return;
|
|
549
|
+
if (val < 1) {
|
|
550
|
+
this.currentIndex = 1;
|
|
551
|
+
} else {
|
|
552
|
+
this.currentIndex = val;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
pageSizeIndex(val) {
|
|
557
|
+
this.$emit('pageSizeChange', this.pageSizeRange[val]);
|
|
558
|
+
}
|
|
559
|
+
},
|
|
560
|
+
methods: {
|
|
561
|
+
pickerChange(e) {
|
|
562
|
+
this.pageSizeIndex = e.detail.value;
|
|
563
|
+
this.pickerClick();
|
|
564
|
+
},
|
|
565
|
+
pickerClick() {
|
|
566
|
+
// #ifdef H5
|
|
567
|
+
const body = document.querySelector('body');
|
|
568
|
+
if (!body) return;
|
|
569
|
+
const className = 'uni-pagination-picker-show';
|
|
570
|
+
this.pickerShow = !this.pickerShow;
|
|
571
|
+
if (this.pickerShow) {
|
|
572
|
+
body.classList.add(className);
|
|
573
|
+
} else {
|
|
574
|
+
setTimeout(() => body.classList.remove(className), 300);
|
|
575
|
+
}
|
|
576
|
+
// #endif
|
|
577
|
+
},
|
|
578
|
+
// 选择标签
|
|
579
|
+
selectPage(e, index) {
|
|
580
|
+
if (parseInt(e)) {
|
|
581
|
+
this.currentIndex = e;
|
|
582
|
+
this.change('current');
|
|
583
|
+
} else {
|
|
584
|
+
let pagerNum = Math.ceil(this.total / this.pageSize);
|
|
585
|
+
// let pagerNum = Math.ceil(181 / this.pageSize)
|
|
586
|
+
// 上一页
|
|
587
|
+
if (index <= 1) {
|
|
588
|
+
if (this.currentIndex - 5 > 1) {
|
|
589
|
+
this.currentIndex -= 5;
|
|
590
|
+
} else {
|
|
591
|
+
this.currentIndex = 1;
|
|
592
|
+
}
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
// 下一页
|
|
596
|
+
if (index >= 6) {
|
|
597
|
+
if (this.currentIndex + 5 > pagerNum) {
|
|
598
|
+
this.currentIndex = pagerNum;
|
|
599
|
+
} else {
|
|
600
|
+
this.currentIndex += 5;
|
|
601
|
+
}
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
clickLeft() {
|
|
607
|
+
if (Number(this.currentIndex) === 1) {
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
this.currentIndex -= 1;
|
|
611
|
+
this.change('prev');
|
|
612
|
+
},
|
|
613
|
+
clickRight() {
|
|
614
|
+
if (Number(this.currentIndex) >= this.maxPage) {
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
this.currentIndex += 1;
|
|
618
|
+
this.change('next');
|
|
619
|
+
},
|
|
620
|
+
change(e) {
|
|
621
|
+
this.$emit('input', this.currentIndex);
|
|
622
|
+
this.$emit('update:modelValue', this.currentIndex);
|
|
623
|
+
this.$emit('change', {
|
|
624
|
+
type: e,
|
|
625
|
+
current: this.currentIndex
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
</script>
|
|
631
|
+
<style scoped>
|
|
632
|
+
@import 'style.css';
|
|
633
|
+
</style>
|