v-page 3.0.0 → 3.1.0
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/README.md +7 -6
- package/dist/v-page.js +123 -120
- package/dist/v-page.umd.cjs +1 -1
- package/package.json +13 -13
- package/types/index.d.ts +31 -8
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ app.use(PaginationBar, {
|
|
|
47
47
|
app.mount('#app')
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
Use `v-page` as a locally component
|
|
51
51
|
|
|
52
52
|
```vue
|
|
53
53
|
<template>
|
|
@@ -70,15 +70,16 @@ import { PaginationBar } from 'v-page'
|
|
|
70
70
|
/>
|
|
71
71
|
</template>
|
|
72
72
|
|
|
73
|
-
<script setup>
|
|
73
|
+
<script setup lang='ts'>
|
|
74
74
|
import { ref } from 'vue'
|
|
75
75
|
import { PaginationBar } from 'v-page'
|
|
76
|
+
import type { PageInfo } from 'v-page/types'
|
|
76
77
|
// set default page to 3
|
|
77
|
-
const pageNumber = ref(3)
|
|
78
|
-
const totalRow = ref(100)
|
|
78
|
+
const pageNumber = ref<number>(3)
|
|
79
|
+
const totalRow = ref<number>(100)
|
|
79
80
|
// respond for pagination change
|
|
80
|
-
function paginationChange (data) {
|
|
81
|
-
console.log(data) // { pageNumber: 1, pageSize: 10 }
|
|
81
|
+
function paginationChange (data: PageInfo): void {
|
|
82
|
+
console.log(data) // { pageNumber: 1, pageSize: 10, totalPage: 10 }
|
|
82
83
|
}
|
|
83
84
|
</script>
|
|
84
85
|
```
|
package/dist/v-page.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
(function(){"use strict";try{if(typeof document<"u"){var i=document.createElement("style");i.appendChild(document.createTextNode(".v-pagination{display:flex;justify-content:flex-start;box-sizing:border-box}.v-pagination--right{justify-content:flex-end}.v-pagination--center{justify-content:center}.v-pagination.v-pagination--disabled a,.v-pagination.v-pagination--disabled select{color:#999!important}.v-pagination.v-pagination--disabled.v-pagination--border a,.v-pagination.v-pagination--disabled.v-pagination--border a:hover{background-color:#fafafa}.v-pagination ul{margin:0;padding:0;display:flex}.v-pagination ul li{list-style:none;display:flex}.v-pagination ul li.v-pagination__info a,.v-pagination ul li.v-pagination__list a{cursor:default;color:#333}.v-pagination ul li a{padding:.3rem .6rem;text-decoration:none;line-height:1.3;font-size:14px;margin:0;outline:0;color:#333;border-radius:.25rem;display:inline-flex;align-items:center}.v-pagination ul li:not(.active):not(.disabled):not(.v-pagination__list):not(.v-pagination__info):not(.v-pagination__slot) a:hover{background-color:#fafafa}.v-pagination ul li.active a{background-color:#eee;color:#aaa}.v-pagination ul li.disabled a{color:#999!important;cursor:default}.v-pagination ul li select{width:auto!important;font-size:12px;padding:0;outline:0;margin:0 0 0 5px;border:1px solid #ccc;color:#333;border-radius:.3rem}.v-pagination.v-pagination--border ul{box-shadow:0 1px 2px #0000000d;border-radius:.25rem}.v-pagination.v-pagination--border ul li:not(:first-child) a{margin-left:-1px}.v-pagination.v-pagination--border ul li a{border:1px solid #DEE2E6;border-radius:0}.v-pagination.v-pagination--border ul li:first-child>a{border-bottom-left-radius:.25rem;border-top-left-radius:.25rem}.v-pagination.v-pagination--border ul li:last-child>a{border-top-right-radius:.25rem;border-bottom-right-radius:.25rem}.v-pagination.v-pagination--border ul li.active a{color:#999;background-color:#eee}")),document.head.appendChild(i)}}catch(a){console.error("vite-plugin-css-injected-by-js",a)}})();
|
|
2
|
-
import { defineComponent as
|
|
3
|
-
const [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
] = ["cn", "en", "de", "jp", "pt"],
|
|
10
|
-
[
|
|
2
|
+
import { defineComponent as U, toRefs as V, ref as P, computed as v, watch as x, onMounted as Z, h as o } from "vue";
|
|
3
|
+
const g = 1, k = 5, C = 10, F = [C, 20, 50, 100], G = 0, [ee, ae, H] = ["left", "center", "right"], [
|
|
4
|
+
J,
|
|
5
|
+
L,
|
|
6
|
+
q,
|
|
7
|
+
K,
|
|
8
|
+
Q
|
|
9
|
+
] = ["cn", "en", "de", "jp", "pt"], I = {
|
|
10
|
+
[J]: {
|
|
11
11
|
pageLength: "每页记录数 ",
|
|
12
12
|
pageInfo: "当前显示第 #pageNumber# / #totalPage# 页(共#totalRow#条记录)",
|
|
13
13
|
first: "首页",
|
|
@@ -16,7 +16,7 @@ const [
|
|
|
16
16
|
last: "尾页",
|
|
17
17
|
all: "全部"
|
|
18
18
|
},
|
|
19
|
-
[
|
|
19
|
+
[L]: {
|
|
20
20
|
pageLength: "Page length ",
|
|
21
21
|
pageInfo: "Current #pageNumber# / #totalPage# (total #totalRow# records)",
|
|
22
22
|
first: "First",
|
|
@@ -25,7 +25,7 @@ const [
|
|
|
25
25
|
last: "Last",
|
|
26
26
|
all: "All"
|
|
27
27
|
},
|
|
28
|
-
[
|
|
28
|
+
[q]: {
|
|
29
29
|
pageLength: "Seitenlänge ",
|
|
30
30
|
pageInfo: "Aktuell #pageNumber# / #totalPage# (gesamt #totalRow# Aufzeichnungen)",
|
|
31
31
|
first: "Zuerst",
|
|
@@ -34,7 +34,7 @@ const [
|
|
|
34
34
|
last: "Letzte",
|
|
35
35
|
all: "Alle"
|
|
36
36
|
},
|
|
37
|
-
[
|
|
37
|
+
[K]: {
|
|
38
38
|
pageLength: "ページごとの記録数",
|
|
39
39
|
pageInfo: "現在の第 #pageNumber# / #totalPage# ページ(全部で #totalRow# 条の記録)",
|
|
40
40
|
first: "トップページ",
|
|
@@ -43,7 +43,7 @@ const [
|
|
|
43
43
|
last: "尾のページ",
|
|
44
44
|
all: "すべて"
|
|
45
45
|
},
|
|
46
|
-
[
|
|
46
|
+
[Q]: {
|
|
47
47
|
pageLength: "Resultados por página ",
|
|
48
48
|
pageInfo: "#pageNumber# / #totalPage# (total de #totalRow#)",
|
|
49
49
|
first: "Início",
|
|
@@ -52,37 +52,36 @@ const [
|
|
|
52
52
|
last: "Fim",
|
|
53
53
|
all: "Todos"
|
|
54
54
|
}
|
|
55
|
-
}
|
|
56
|
-
function
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
};
|
|
56
|
+
function W(e, n, t) {
|
|
57
|
+
if (n <= t) return g;
|
|
58
|
+
const c = Math.floor(t / 2), s = n - t + 1, u = e - c;
|
|
59
|
+
return u < g ? g : u > s ? s : u;
|
|
60
|
+
}
|
|
61
|
+
function X(e, n, t) {
|
|
62
|
+
const c = W(e, n, t);
|
|
63
|
+
return Array.from({ length: t }).map((s, u) => c + u).filter((s) => s >= g && s <= n);
|
|
61
64
|
}
|
|
62
|
-
function
|
|
63
|
-
const
|
|
64
|
-
return
|
|
65
|
+
function Y(e = L) {
|
|
66
|
+
const n = String(e).toLowerCase();
|
|
67
|
+
return n in I ? I[n] : I[L];
|
|
65
68
|
}
|
|
66
|
-
const
|
|
69
|
+
const A = U({
|
|
67
70
|
name: "PaginationBar",
|
|
68
71
|
props: {
|
|
69
72
|
modelValue: { type: Number, default: 0 },
|
|
70
73
|
totalRow: { type: Number, default: 0 },
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* Page size list
|
|
74
|
-
* false: close page size list
|
|
75
|
-
* array: custom page sizes list
|
|
76
|
-
*/
|
|
77
|
-
pageSizeMenu: {
|
|
78
|
-
type: [Boolean, Array],
|
|
79
|
-
default: () => q
|
|
80
|
-
},
|
|
74
|
+
pageSize: { type: Number, default: C },
|
|
75
|
+
language: { type: String, default: L },
|
|
81
76
|
/**
|
|
82
77
|
* Pagination alignment direction
|
|
83
78
|
* `left`, `center` and `right`(default)
|
|
84
79
|
*/
|
|
85
|
-
align: { type: String, default:
|
|
80
|
+
align: { type: String, default: H },
|
|
81
|
+
/** Page size list */
|
|
82
|
+
pageSizeMenu: { type: [Array], default: () => F },
|
|
83
|
+
/** Display page size menu panel */
|
|
84
|
+
pageSizeOptions: { type: Boolean, default: !0 },
|
|
86
85
|
disabled: { type: Boolean, default: !1 },
|
|
87
86
|
border: { type: Boolean, default: !1 },
|
|
88
87
|
info: { type: Boolean, default: !0 },
|
|
@@ -91,138 +90,142 @@ const R = F({
|
|
|
91
90
|
first: { type: Boolean, default: !0 },
|
|
92
91
|
/** last page button */
|
|
93
92
|
last: { type: Boolean, default: !0 },
|
|
94
|
-
/**
|
|
95
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Display all records
|
|
95
|
+
*
|
|
96
|
+
* will add `all` option in page size list
|
|
97
|
+
* and the page size will be 0
|
|
98
|
+
*/
|
|
99
|
+
displayAll: { type: Boolean, default: !1 },
|
|
100
|
+
/** Hide pagination when only have one page */
|
|
101
|
+
hideOnSinglePage: { type: Boolean, default: !1 }
|
|
96
102
|
},
|
|
97
|
-
emits: ["update:modelValue", "change"],
|
|
98
|
-
setup(e, { emit:
|
|
99
|
-
const { pageSizeMenu:
|
|
100
|
-
n.value === !1 ? x : n.value[0]
|
|
101
|
-
), _ = N(J), g = N(B[e.language] || B[z]), m = N(-1), p = b(() => f.value === I ? r : Math.ceil(o.value / f.value)), C = b(() => K(
|
|
103
|
+
emits: ["update:modelValue", "update:pageSize", "change"],
|
|
104
|
+
setup(e, { emit: n, slots: t, expose: c }) {
|
|
105
|
+
const { pageSizeOptions: s, pageSizeMenu: u, totalRow: b } = V(e), l = P(0), m = P(-1), S = P(k), f = Y(e.language), T = v(() => Array.isArray(u.value) && u.value.length > 0 ? u.value : F), p = P(e.pageSize || C), r = v(() => p.value === G ? g : Math.ceil(b.value / p.value)), B = v(() => X(
|
|
102
106
|
l.value,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
)),
|
|
107
|
+
r.value,
|
|
108
|
+
S.value
|
|
109
|
+
)), O = v(
|
|
110
|
+
() => f.pageInfo.replace("#pageNumber#", l.value).replace("#totalPage#", r.value).replace("#totalRow#", b.value)
|
|
111
|
+
), D = v(() => ({
|
|
106
112
|
"v-pagination": !0,
|
|
107
113
|
"v-pagination--border": e.border,
|
|
108
114
|
"v-pagination--right": e.align === "right",
|
|
109
115
|
"v-pagination--center": e.align === "center",
|
|
110
116
|
"v-pagination--disabled": e.disabled
|
|
111
|
-
})),
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
(a)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
);
|
|
118
|
-
function h(a = r, P = !0) {
|
|
119
|
-
if (e.disabled || typeof a != "number")
|
|
120
|
-
return;
|
|
121
|
-
let c = a < r ? r : a;
|
|
122
|
-
a > p.value && p.value > 0 && (c = p.value), !(c === l.value && f.value === m.value) && (l.value = c, P && s("update:modelValue", l.value), m.value = f.value, w());
|
|
117
|
+
})), E = v(() => l.value === g), R = v(() => l.value === r.value);
|
|
118
|
+
x(() => e.modelValue, (a) => y(a)), x(() => e.pageSize, M);
|
|
119
|
+
function y(a = g) {
|
|
120
|
+
if (e.disabled || typeof a != "number") return;
|
|
121
|
+
let d = a < g ? g : a;
|
|
122
|
+
a > r.value && r.value > 0 && (d = r.value), !(d === l.value && p.value === m.value) && (l.value = d, m.value = p.value, w());
|
|
123
123
|
}
|
|
124
124
|
function w() {
|
|
125
|
-
|
|
125
|
+
n("change", {
|
|
126
126
|
pageNumber: l.value,
|
|
127
|
-
pageSize: Number(
|
|
128
|
-
|
|
127
|
+
pageSize: Number(p.value),
|
|
128
|
+
totalPage: r.value
|
|
129
|
+
}), n("update:modelValue", l.value), n("update:pageSize", p.value);
|
|
130
|
+
}
|
|
131
|
+
function M(a) {
|
|
132
|
+
a < 0 || a !== p.value && (p.value = a, y());
|
|
129
133
|
}
|
|
130
|
-
function
|
|
131
|
-
return
|
|
134
|
+
function _(a, d, z) {
|
|
135
|
+
return o("li", { class: a }, [o("a", {
|
|
132
136
|
href: "javascript:void(0)",
|
|
133
|
-
onClick: () =>
|
|
134
|
-
},
|
|
137
|
+
onClick: () => y(d)
|
|
138
|
+
}, z)]);
|
|
135
139
|
}
|
|
136
|
-
return
|
|
137
|
-
|
|
138
|
-
}),
|
|
140
|
+
return Z(() => {
|
|
141
|
+
y(e.modelValue || g);
|
|
142
|
+
}), c({
|
|
143
|
+
goPage: y,
|
|
139
144
|
current: l,
|
|
140
|
-
totalPage:
|
|
141
|
-
pageNumbers:
|
|
142
|
-
goPage: h,
|
|
145
|
+
totalPage: r,
|
|
146
|
+
pageNumbers: B,
|
|
143
147
|
reload: w
|
|
144
148
|
}), () => {
|
|
149
|
+
if (e.hideOnSinglePage && r.value <= 1) return;
|
|
145
150
|
const a = [];
|
|
146
|
-
if (
|
|
151
|
+
if (s.value) {
|
|
147
152
|
const i = {
|
|
148
153
|
disabled: e.disabled,
|
|
149
|
-
onChange: (
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
}, d = n.value.map(
|
|
153
|
-
(S) => u("option", { value: S }, S)
|
|
154
|
+
onChange: (N) => M(Number(N.target.value))
|
|
155
|
+
}, h = T.value.map(
|
|
156
|
+
(N) => o("option", { value: N }, N)
|
|
154
157
|
);
|
|
155
|
-
e.displayAll &&
|
|
156
|
-
|
|
158
|
+
e.displayAll && h.push(
|
|
159
|
+
o("option", { value: G }, f.all)
|
|
157
160
|
);
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
const j = o("li", { class: "v-pagination__list" }, [
|
|
162
|
+
o("a", { href: "javascript:void(0)" }, [
|
|
163
|
+
o("span", f.pageLength),
|
|
164
|
+
o("select", i, h)
|
|
162
165
|
])
|
|
163
166
|
]);
|
|
164
|
-
a.push(
|
|
167
|
+
a.push(j);
|
|
165
168
|
}
|
|
166
169
|
if (e.info && a.push(
|
|
167
|
-
|
|
168
|
-
|
|
170
|
+
o("li", { class: "v-pagination__info" }, [
|
|
171
|
+
o("a", { href: "javascript:void(0)" }, O.value)
|
|
169
172
|
])
|
|
170
173
|
), "default" in t) {
|
|
171
174
|
const i = {
|
|
172
175
|
pageNumber: l.value,
|
|
173
|
-
pageSize:
|
|
174
|
-
totalPage:
|
|
175
|
-
totalRow:
|
|
176
|
-
isFirst:
|
|
177
|
-
isLast:
|
|
178
|
-
},
|
|
179
|
-
|
|
176
|
+
pageSize: p.value,
|
|
177
|
+
totalPage: r.value,
|
|
178
|
+
totalRow: b.value,
|
|
179
|
+
isFirst: E.value,
|
|
180
|
+
isLast: R.value
|
|
181
|
+
}, h = o("li", { class: "v-pagination__slot" }, [
|
|
182
|
+
o("a", t.default(i))
|
|
180
183
|
]);
|
|
181
|
-
a.push(
|
|
184
|
+
a.push(h);
|
|
182
185
|
}
|
|
183
186
|
if (e.first) {
|
|
184
|
-
const i = ["v-pagination__first", { disabled:
|
|
185
|
-
a.push(
|
|
187
|
+
const i = ["v-pagination__first", { disabled: E.value }];
|
|
188
|
+
a.push(_(i, g, f.first));
|
|
186
189
|
}
|
|
187
|
-
const
|
|
190
|
+
const d = ["v-pagination__previous", { disabled: E.value }];
|
|
188
191
|
a.push(
|
|
189
|
-
|
|
192
|
+
_(d, l.value - 1, f.previous)
|
|
190
193
|
), e.pageNumber && a.push(
|
|
191
|
-
...
|
|
192
|
-
const
|
|
193
|
-
return
|
|
194
|
+
...B.value.map((i) => {
|
|
195
|
+
const h = { active: i === l.value };
|
|
196
|
+
return _(h, i, i);
|
|
194
197
|
})
|
|
195
198
|
);
|
|
196
|
-
const
|
|
199
|
+
const z = ["v-pagination__next", { disabled: R.value }];
|
|
197
200
|
if (a.push(
|
|
198
|
-
|
|
201
|
+
_(z, l.value + 1, f.next)
|
|
199
202
|
), e.last) {
|
|
200
|
-
const i = ["v-pagination__last", { disabled:
|
|
203
|
+
const i = ["v-pagination__last", { disabled: R.value }];
|
|
201
204
|
a.push(
|
|
202
|
-
|
|
205
|
+
_(i, r.value, f.last)
|
|
203
206
|
);
|
|
204
207
|
}
|
|
205
|
-
return
|
|
208
|
+
return o("div", { class: D.value }, [o("ul", a)]);
|
|
206
209
|
};
|
|
207
210
|
}
|
|
208
211
|
});
|
|
209
|
-
|
|
210
|
-
if (Object.keys(
|
|
211
|
-
const { props: t } =
|
|
212
|
-
language:
|
|
213
|
-
align:
|
|
214
|
-
info:
|
|
215
|
-
border:
|
|
216
|
-
pageNumber:
|
|
217
|
-
first:
|
|
218
|
-
last:
|
|
219
|
-
pageSizeMenu:
|
|
220
|
-
} =
|
|
221
|
-
|
|
212
|
+
A.install = (e, n = {}) => {
|
|
213
|
+
if (Object.keys(n).length) {
|
|
214
|
+
const { props: t } = A, {
|
|
215
|
+
language: c,
|
|
216
|
+
align: s,
|
|
217
|
+
info: u,
|
|
218
|
+
border: b,
|
|
219
|
+
pageNumber: l,
|
|
220
|
+
first: m,
|
|
221
|
+
last: S,
|
|
222
|
+
pageSizeMenu: f
|
|
223
|
+
} = n;
|
|
224
|
+
c && (t.language.default = c), s && (t.align.default = s), typeof u == "boolean" && (t.info.default = u), typeof b == "boolean" && (t.border.default = b), typeof l == "boolean" && (t.pageNumber.default = l), typeof m == "boolean" && (t.first.default = m), typeof S == "boolean" && (t.last.default = S), typeof f < "u" && (t.pageSizeMenu.default = f);
|
|
222
225
|
}
|
|
223
|
-
e.component(
|
|
226
|
+
e.component(A.name, A);
|
|
224
227
|
};
|
|
225
228
|
export {
|
|
226
|
-
|
|
227
|
-
|
|
229
|
+
A as PaginationBar,
|
|
230
|
+
A as default
|
|
228
231
|
};
|
package/dist/v-page.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
(function(){"use strict";try{if(typeof document<"u"){var i=document.createElement("style");i.appendChild(document.createTextNode(".v-pagination{display:flex;justify-content:flex-start;box-sizing:border-box}.v-pagination--right{justify-content:flex-end}.v-pagination--center{justify-content:center}.v-pagination.v-pagination--disabled a,.v-pagination.v-pagination--disabled select{color:#999!important}.v-pagination.v-pagination--disabled.v-pagination--border a,.v-pagination.v-pagination--disabled.v-pagination--border a:hover{background-color:#fafafa}.v-pagination ul{margin:0;padding:0;display:flex}.v-pagination ul li{list-style:none;display:flex}.v-pagination ul li.v-pagination__info a,.v-pagination ul li.v-pagination__list a{cursor:default;color:#333}.v-pagination ul li a{padding:.3rem .6rem;text-decoration:none;line-height:1.3;font-size:14px;margin:0;outline:0;color:#333;border-radius:.25rem;display:inline-flex;align-items:center}.v-pagination ul li:not(.active):not(.disabled):not(.v-pagination__list):not(.v-pagination__info):not(.v-pagination__slot) a:hover{background-color:#fafafa}.v-pagination ul li.active a{background-color:#eee;color:#aaa}.v-pagination ul li.disabled a{color:#999!important;cursor:default}.v-pagination ul li select{width:auto!important;font-size:12px;padding:0;outline:0;margin:0 0 0 5px;border:1px solid #ccc;color:#333;border-radius:.3rem}.v-pagination.v-pagination--border ul{box-shadow:0 1px 2px #0000000d;border-radius:.25rem}.v-pagination.v-pagination--border ul li:not(:first-child) a{margin-left:-1px}.v-pagination.v-pagination--border ul li a{border:1px solid #DEE2E6;border-radius:0}.v-pagination.v-pagination--border ul li:first-child>a{border-bottom-left-radius:.25rem;border-top-left-radius:.25rem}.v-pagination.v-pagination--border ul li:last-child>a{border-top-right-radius:.25rem;border-bottom-right-radius:.25rem}.v-pagination.v-pagination--border ul li.active a{color:#999;background-color:#eee}")),document.head.appendChild(i)}}catch(a){console.error("vite-plugin-css-injected-by-js",a)}})();
|
|
2
|
-
(function(p,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(p=typeof globalThis<"u"?globalThis:p||self,e(p.VPage={},p.Vue))})(this,function(p,e){"use strict";const
|
|
2
|
+
(function(p,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(p=typeof globalThis<"u"?globalThis:p||self,e(p.VPage={},p.Vue))})(this,function(p,e){"use strict";const L=[10,20,50,100],N=0,[K,Q,C]=["left","center","right"],[G,y,M,w,D]=["cn","en","de","jp","pt"],P={[G]:{pageLength:"每页记录数 ",pageInfo:"当前显示第 #pageNumber# / #totalPage# 页(共#totalRow#条记录)",first:"首页",previous:"«",next:"»",last:"尾页",all:"全部"},[y]:{pageLength:"Page length ",pageInfo:"Current #pageNumber# / #totalPage# (total #totalRow# records)",first:"First",previous:"«",next:"»",last:"Last",all:"All"},[M]:{pageLength:"Seitenlänge ",pageInfo:"Aktuell #pageNumber# / #totalPage# (gesamt #totalRow# Aufzeichnungen)",first:"Zuerst",previous:"«",next:"»",last:"Letzte",all:"Alle"},[w]:{pageLength:"ページごとの記録数",pageInfo:"現在の第 #pageNumber# / #totalPage# ページ(全部で #totalRow# 条の記録)",first:"トップページ",previous:"«",next:"»",last:"尾のページ",all:"すべて"},[D]:{pageLength:"Resultados por página ",pageInfo:"#pageNumber# / #totalPage# (total de #totalRow#)",first:"Início",previous:"<",next:">",last:"Fim",all:"Todos"}};function U(a,o,n){if(o<=n)return 1;const d=Math.floor(n/2),s=o-n+1,u=a-d;return u<1?1:u>s?s:u}function x(a,o,n){const d=U(a,o,n);return Array.from({length:n}).map((s,u)=>d+u).filter(s=>s>=1&&s<=o)}function Z(a=y){const o=String(a).toLowerCase();return o in P?P[o]:P[y]}const h=e.defineComponent({name:"PaginationBar",props:{modelValue:{type:Number,default:0},totalRow:{type:Number,default:0},pageSize:{type:Number,default:10},language:{type:String,default:y},align:{type:String,default:C},pageSizeMenu:{type:[Array],default:()=>L},pageSizeOptions:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},border:{type:Boolean,default:!1},info:{type:Boolean,default:!0},pageNumber:{type:Boolean,default:!0},first:{type:Boolean,default:!0},last:{type:Boolean,default:!0},displayAll:{type:Boolean,default:!1},hideOnSinglePage:{type:Boolean,default:!1}},emits:["update:modelValue","update:pageSize","change"],setup(a,{emit:o,slots:n,expose:d}){const{pageSizeOptions:s,pageSizeMenu:u,totalRow:v}=e.toRefs(a),l=e.ref(0),S=e.ref(-1),E=e.ref(5),f=Z(a.language),O=e.computed(()=>Array.isArray(u.value)&&u.value.length>0?u.value:L),g=e.ref(a.pageSize||10),r=e.computed(()=>g.value===N?1:Math.ceil(v.value/g.value)),F=e.computed(()=>x(l.value,r.value,E.value)),j=e.computed(()=>f.pageInfo.replace("#pageNumber#",l.value).replace("#totalPage#",r.value).replace("#totalRow#",v.value)),V=e.computed(()=>({"v-pagination":!0,"v-pagination--border":a.border,"v-pagination--right":a.align==="right","v-pagination--center":a.align==="center","v-pagination--disabled":a.disabled})),R=e.computed(()=>l.value===1),A=e.computed(()=>l.value===r.value);e.watch(()=>a.modelValue,t=>b(t)),e.watch(()=>a.pageSize,B);function b(t=1){if(a.disabled||typeof t!="number")return;let c=t<1?1:t;t>r.value&&r.value>0&&(c=r.value),!(c===l.value&&g.value===S.value)&&(l.value=c,S.value=g.value,z())}function z(){o("change",{pageNumber:l.value,pageSize:Number(g.value),totalPage:r.value}),o("update:modelValue",l.value),o("update:pageSize",g.value)}function B(t){t<0||t!==g.value&&(g.value=t,b())}function _(t,c,T){const i={href:"javascript:void(0)",onClick:()=>b(c)};return e.h("li",{class:t},[e.h("a",i,T)])}return e.onMounted(()=>{b(a.modelValue||1)}),d({goPage:b,current:l,totalPage:r,pageNumbers:F,reload:z}),()=>{if(a.hideOnSinglePage&&r.value<=1)return;const t=[];if(s.value){const i={disabled:a.disabled,onChange:I=>B(Number(I.target.value))},m=O.value.map(I=>e.h("option",{value:I},I));a.displayAll&&m.push(e.h("option",{value:N},f.all));const k=e.h("li",{class:"v-pagination__list"},[e.h("a",{href:"javascript:void(0)"},[e.h("span",f.pageLength),e.h("select",i,m)])]);t.push(k)}if(a.info&&t.push(e.h("li",{class:"v-pagination__info"},[e.h("a",{href:"javascript:void(0)"},j.value)])),"default"in n){const i={pageNumber:l.value,pageSize:g.value,totalPage:r.value,totalRow:v.value,isFirst:R.value,isLast:A.value},m=e.h("li",{class:"v-pagination__slot"},[e.h("a",n.default(i))]);t.push(m)}if(a.first){const i=["v-pagination__first",{disabled:R.value}];t.push(_(i,1,f.first))}const c=["v-pagination__previous",{disabled:R.value}];t.push(_(c,l.value-1,f.previous)),a.pageNumber&&t.push(...F.value.map(i=>{const m={active:i===l.value};return _(m,i,i)}));const T=["v-pagination__next",{disabled:A.value}];if(t.push(_(T,l.value+1,f.next)),a.last){const i=["v-pagination__last",{disabled:A.value}];t.push(_(i,r.value,f.last))}return e.h("div",{class:V.value},[e.h("ul",t)])}}});h.install=(a,o={})=>{if(Object.keys(o).length){const{props:n}=h,{language:d,align:s,info:u,border:v,pageNumber:l,first:S,last:E,pageSizeMenu:f}=o;d&&(n.language.default=d),s&&(n.align.default=s),typeof u=="boolean"&&(n.info.default=u),typeof v=="boolean"&&(n.border.default=v),typeof l=="boolean"&&(n.pageNumber.default=l),typeof S=="boolean"&&(n.first.default=S),typeof E=="boolean"&&(n.last.default=E),typeof f<"u"&&(n.pageSizeMenu.default=f)}a.component(h.name,h)},p.PaginationBar=h,p.default=h,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "v-page",
|
|
3
3
|
"description": "A simple pagination bar",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"author": "TerryZ <terry5@foxmail.com>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
@@ -47,27 +47,27 @@
|
|
|
47
47
|
"pagination"
|
|
48
48
|
],
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"vue": "^3.
|
|
50
|
+
"vue": "^3.4.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"vue": "^3.
|
|
53
|
+
"vue": "^3.4.29"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@rushstack/eslint-patch": "^1.3.3",
|
|
57
|
-
"@vitejs/plugin-vue": "^
|
|
58
|
-
"@vitejs/plugin-vue-jsx": "^
|
|
57
|
+
"@vitejs/plugin-vue": "^5.0.5",
|
|
58
|
+
"@vitejs/plugin-vue-jsx": "^4.0.0",
|
|
59
|
+
"@vitest/coverage-v8": "^1.6.0",
|
|
59
60
|
"@vue/eslint-config-standard": "^8.0.1",
|
|
60
|
-
"@vue/test-utils": "^2.4.
|
|
61
|
-
"bootstrap": "^5.3.
|
|
62
|
-
"c8": "^8.0.1",
|
|
61
|
+
"@vue/test-utils": "^2.4.6",
|
|
62
|
+
"bootstrap": "^5.3.3",
|
|
63
63
|
"eslint": "^8.49.0",
|
|
64
64
|
"eslint-plugin-vue": "^9.17.0",
|
|
65
|
-
"jsdom": "^
|
|
65
|
+
"jsdom": "^24.1.0",
|
|
66
66
|
"sass": "^1.66.1",
|
|
67
67
|
"sass-loader": "^13.3.2",
|
|
68
|
-
"typescript": "^5.
|
|
69
|
-
"vite": "^
|
|
70
|
-
"vite-plugin-css-injected-by-js": "^3.
|
|
71
|
-
"vitest": "^
|
|
68
|
+
"typescript": "^5.5.2",
|
|
69
|
+
"vite": "^5.3.1",
|
|
70
|
+
"vite-plugin-css-injected-by-js": "^3.5.1",
|
|
71
|
+
"vitest": "^1.6.0"
|
|
72
72
|
}
|
|
73
73
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
export declare interface PageInfo {
|
|
9
9
|
pageNumber: number
|
|
10
10
|
pageSize: number
|
|
11
|
+
totalPage: number
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export declare interface PageSlotData {
|
|
@@ -31,6 +32,11 @@ declare interface Props {
|
|
|
31
32
|
* The number of total record
|
|
32
33
|
*/
|
|
33
34
|
totalRow: number
|
|
35
|
+
/**
|
|
36
|
+
* The number of page size
|
|
37
|
+
* @default 10
|
|
38
|
+
*/
|
|
39
|
+
pageSize?: number
|
|
34
40
|
/**
|
|
35
41
|
* v-page language
|
|
36
42
|
* @default `en`
|
|
@@ -40,7 +46,12 @@ declare interface Props {
|
|
|
40
46
|
* Page size list
|
|
41
47
|
* @default [10, 20, 50, 100]
|
|
42
48
|
*/
|
|
43
|
-
pageSizeMenu?:
|
|
49
|
+
pageSizeMenu?: number[]
|
|
50
|
+
/**
|
|
51
|
+
* Whether to display page size list panel
|
|
52
|
+
* @default true
|
|
53
|
+
*/
|
|
54
|
+
pageSizeOptions?: boolean
|
|
44
55
|
/**
|
|
45
56
|
* Alignment direction
|
|
46
57
|
* @default `right`
|
|
@@ -81,14 +92,19 @@ declare interface Props {
|
|
|
81
92
|
* @default false
|
|
82
93
|
*/
|
|
83
94
|
displayAll?: boolean
|
|
95
|
+
/**
|
|
96
|
+
* Hide pagination when only have one page
|
|
97
|
+
* @default false
|
|
98
|
+
*/
|
|
99
|
+
hideOnSinglePage?: boolean
|
|
84
100
|
}
|
|
85
101
|
|
|
86
|
-
declare interface Emits {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
102
|
+
// declare interface Emits {
|
|
103
|
+
// /** Update pageNumber value */
|
|
104
|
+
// 'onUpdate:modelValue'?: (pageNumber: number) => void
|
|
105
|
+
// /** The event respond pageNumber or pageSize change */
|
|
106
|
+
// onChange?: (data: PageInfo) => void
|
|
107
|
+
// }
|
|
92
108
|
|
|
93
109
|
// declare interface Methods extends MethodOptions {
|
|
94
110
|
// /** Go to the specified page */
|
|
@@ -96,10 +112,17 @@ declare interface Emits {
|
|
|
96
112
|
// /** Re-emit `change` event and output pagination states data */
|
|
97
113
|
// reload: () => void
|
|
98
114
|
// }
|
|
115
|
+
// $emit: ((event: "update:modelValue", value: boolean) => void) & ((event: "click:close", e: MouseEvent) => void)
|
|
116
|
+
|
|
117
|
+
/** Update pageNumber value */
|
|
118
|
+
type EmitUpdateModelValue = (event: "update:modelValue", value: number) => void
|
|
119
|
+
/** The event respond pageNumber or pageSize change */
|
|
120
|
+
type EmitChange = (event: "change", value: PageInfo) => void
|
|
99
121
|
|
|
100
122
|
declare interface PaginationBar {
|
|
101
123
|
new (): {
|
|
102
|
-
$props: AllowedComponentProps & ComponentCustomProps & VNodeProps & Props
|
|
124
|
+
$props: AllowedComponentProps & ComponentCustomProps & VNodeProps & Props
|
|
125
|
+
$emit: EmitUpdateModelValue & EmitChange
|
|
103
126
|
$slots: {
|
|
104
127
|
default?: (defaultSlotData: PageSlotData) => VNode[]
|
|
105
128
|
}
|