v-page 3.0.0-beta.4 → 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 +24 -15
- package/dist/v-page.js +127 -125
- package/dist/v-page.umd.cjs +2 -2
- package/package.json +18 -13
- package/types/index.d.ts +60 -47
package/README.md
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
# [v-page](https://terryz.github.io/vue/#/page) · [](https://dl.circleci.com/status-badge/redirect/gh/TerryZ/v-page/tree/master) [](https://codecov.io/gh/TerryZ/v-page) [](https://www.npmjs.com/package/v-page) [](https://mit-license.org/) [](https://www.npmjs.com/package/v-page) [](https://standardjs.com)
|
|
2
2
|
|
|
3
|
-
A simple pagination bar for vue3, including size Menu, i18n support
|
|
3
|
+
A simple pagination bar for vue3, including size Menu, i18n support features
|
|
4
4
|
|
|
5
5
|
<img src="https://terryz.github.io/image/v-page/v-page.png" alt="v-page" height="54px">
|
|
6
6
|
|
|
7
7
|
If you are using vue `2.x` version, please use [v-page 2.x](https://github.com/TerryZ/v-page/tree/dev-vue-2) version instead
|
|
8
8
|
|
|
9
|
+
<!-- ## Features
|
|
10
|
+
|
|
11
|
+
- Simple interface style
|
|
12
|
+
- I18n supported
|
|
13
|
+
- Modularization of Pagination bar features
|
|
14
|
+
- -->
|
|
15
|
+
|
|
9
16
|
## Examples and Documentation
|
|
10
17
|
|
|
11
18
|
Documentation and examples and please visit below sites
|
|
@@ -28,27 +35,27 @@ pnpm add v-page
|
|
|
28
35
|
Include and install plugin in your `main.js` file
|
|
29
36
|
|
|
30
37
|
```js
|
|
31
|
-
// add component in global scope as plugin
|
|
32
38
|
import { createApp } from 'vue'
|
|
33
39
|
import App from './app.vue'
|
|
34
|
-
import
|
|
40
|
+
import { PaginationBar } from 'v-page'
|
|
35
41
|
|
|
36
42
|
const app = createApp(App)
|
|
37
|
-
|
|
43
|
+
// install component globally
|
|
44
|
+
app.use(PaginationBar, {
|
|
38
45
|
// globally config options
|
|
39
46
|
})
|
|
40
47
|
app.mount('#app')
|
|
41
48
|
```
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
Use `v-page` as a locally component
|
|
44
51
|
|
|
45
52
|
```vue
|
|
46
53
|
<template>
|
|
47
|
-
<
|
|
54
|
+
<PaginationBar />
|
|
48
55
|
</template>
|
|
49
56
|
|
|
50
57
|
<script setup>
|
|
51
|
-
import {
|
|
58
|
+
import { PaginationBar } from 'v-page'
|
|
52
59
|
</script>
|
|
53
60
|
```
|
|
54
61
|
|
|
@@ -56,21 +63,23 @@ import { Page } from 'v-page'
|
|
|
56
63
|
|
|
57
64
|
```vue
|
|
58
65
|
<template>
|
|
59
|
-
<
|
|
66
|
+
<PaginationBar
|
|
60
67
|
v-model="pageNumber"
|
|
61
68
|
:total-row="totalRow"
|
|
62
|
-
@change="
|
|
69
|
+
@change="paginationChange"
|
|
63
70
|
/>
|
|
64
71
|
</template>
|
|
65
72
|
|
|
66
|
-
<script setup>
|
|
73
|
+
<script setup lang='ts'>
|
|
67
74
|
import { ref } from 'vue'
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
import { PaginationBar } from 'v-page'
|
|
76
|
+
import type { PageInfo } from 'v-page/types'
|
|
77
|
+
// set default page to 3
|
|
78
|
+
const pageNumber = ref<number>(3)
|
|
79
|
+
const totalRow = ref<number>(100)
|
|
71
80
|
// respond for pagination change
|
|
72
|
-
function
|
|
73
|
-
console.log(
|
|
81
|
+
function paginationChange (data: PageInfo): void {
|
|
82
|
+
console.log(data) // { pageNumber: 1, pageSize: 10, totalPage: 10 }
|
|
74
83
|
}
|
|
75
84
|
</script>
|
|
76
85
|
```
|
package/dist/v-page.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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 ul{margin:0;padding:0;display:flex}.v-pagination ul li{list-style:none;display:flex}.v-pagination ul li a{padding:.3rem .6rem;text-decoration:none;
|
|
2
|
-
import { defineComponent as
|
|
3
|
-
const [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 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
9
|
] = ["cn", "en", "de", "jp", "pt"], I = {
|
|
10
|
-
[
|
|
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
|
|
67
|
-
name: "
|
|
69
|
+
const A = U({
|
|
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,139 +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 ? B : n.value[0]
|
|
101
|
-
), N = P(J), g = P(I[e.language] || I[z]), b = P(-1), p = c(() => f.value === x ? r : Math.ceil(o.value / f.value)), C = c(() => 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 m(a = r, y = !0) {
|
|
119
|
-
if (e.disabled || typeof a != "number")
|
|
120
|
-
return;
|
|
121
|
-
let d = a < r ? r : a;
|
|
122
|
-
a > p.value && p.value > 0 && (d = p.value), !(d === l.value && f.value === b.value) && (l.value = d, y && s("update:modelValue", l.value), b.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);
|
|
129
130
|
}
|
|
130
|
-
function
|
|
131
|
-
|
|
131
|
+
function M(a) {
|
|
132
|
+
a < 0 || a !== p.value && (p.value = a, y());
|
|
133
|
+
}
|
|
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: m,
|
|
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
|
-
}, _ = 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
|
-
|
|
170
|
+
o("li", { class: "v-pagination__info" }, [
|
|
171
|
+
o("a", { href: "javascript:void(0)" }, O.value)
|
|
172
|
+
])
|
|
168
173
|
), "default" in t) {
|
|
169
|
-
const i =
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
isLast: L.value
|
|
179
|
-
})
|
|
180
|
-
)
|
|
174
|
+
const i = {
|
|
175
|
+
pageNumber: l.value,
|
|
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))
|
|
181
183
|
]);
|
|
182
|
-
a.push(
|
|
184
|
+
a.push(h);
|
|
183
185
|
}
|
|
184
186
|
if (e.first) {
|
|
185
|
-
const i = ["v-pagination__first", { disabled:
|
|
186
|
-
a.push(
|
|
187
|
+
const i = ["v-pagination__first", { disabled: E.value }];
|
|
188
|
+
a.push(_(i, g, f.first));
|
|
187
189
|
}
|
|
188
|
-
const
|
|
190
|
+
const d = ["v-pagination__previous", { disabled: E.value }];
|
|
189
191
|
a.push(
|
|
190
|
-
|
|
192
|
+
_(d, l.value - 1, f.previous)
|
|
191
193
|
), e.pageNumber && a.push(
|
|
192
|
-
...
|
|
193
|
-
const
|
|
194
|
-
return h
|
|
194
|
+
...B.value.map((i) => {
|
|
195
|
+
const h = { active: i === l.value };
|
|
196
|
+
return _(h, i, i);
|
|
195
197
|
})
|
|
196
198
|
);
|
|
197
|
-
const
|
|
199
|
+
const z = ["v-pagination__next", { disabled: R.value }];
|
|
198
200
|
if (a.push(
|
|
199
|
-
|
|
201
|
+
_(z, l.value + 1, f.next)
|
|
200
202
|
), e.last) {
|
|
201
|
-
const i = ["v-pagination__last", { disabled:
|
|
203
|
+
const i = ["v-pagination__last", { disabled: R.value }];
|
|
202
204
|
a.push(
|
|
203
|
-
|
|
205
|
+
_(i, r.value, f.last)
|
|
204
206
|
);
|
|
205
207
|
}
|
|
206
|
-
return
|
|
208
|
+
return o("div", { class: D.value }, [o("ul", a)]);
|
|
207
209
|
};
|
|
208
210
|
}
|
|
209
211
|
});
|
|
210
|
-
|
|
211
|
-
if (Object.keys(
|
|
212
|
-
const { props: t } =
|
|
213
|
-
language:
|
|
214
|
-
align:
|
|
215
|
-
info:
|
|
216
|
-
border:
|
|
217
|
-
pageNumber:
|
|
218
|
-
first:
|
|
219
|
-
last:
|
|
220
|
-
pageSizeMenu:
|
|
221
|
-
} =
|
|
222
|
-
|
|
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);
|
|
223
225
|
}
|
|
224
|
-
e.component(
|
|
226
|
+
e.component(A.name, A);
|
|
225
227
|
};
|
|
226
228
|
export {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
+
A as PaginationBar,
|
|
230
|
+
A as default
|
|
229
231
|
};
|
package/dist/v-page.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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 ul{margin:0;padding:0;display:flex}.v-pagination ul li{list-style:none;display:flex}.v-pagination ul li a{padding:.3rem .6rem;text-decoration:none;
|
|
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
|
|
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 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": [
|
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
"default": "./dist/v-page.js"
|
|
18
18
|
},
|
|
19
19
|
"require": "./dist/v-page.umd.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./types": {
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./types/index.d.ts"
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
},
|
|
22
27
|
"typings": "./types/index.d.ts",
|
|
@@ -42,27 +47,27 @@
|
|
|
42
47
|
"pagination"
|
|
43
48
|
],
|
|
44
49
|
"peerDependencies": {
|
|
45
|
-
"vue": "^3.
|
|
50
|
+
"vue": "^3.4.0"
|
|
46
51
|
},
|
|
47
52
|
"dependencies": {
|
|
48
|
-
"vue": "^3.
|
|
53
|
+
"vue": "^3.4.29"
|
|
49
54
|
},
|
|
50
55
|
"devDependencies": {
|
|
51
56
|
"@rushstack/eslint-patch": "^1.3.3",
|
|
52
|
-
"@vitejs/plugin-vue": "^
|
|
53
|
-
"@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",
|
|
54
60
|
"@vue/eslint-config-standard": "^8.0.1",
|
|
55
|
-
"@vue/test-utils": "^2.4.
|
|
56
|
-
"bootstrap": "^5.3.
|
|
57
|
-
"c8": "^8.0.1",
|
|
61
|
+
"@vue/test-utils": "^2.4.6",
|
|
62
|
+
"bootstrap": "^5.3.3",
|
|
58
63
|
"eslint": "^8.49.0",
|
|
59
64
|
"eslint-plugin-vue": "^9.17.0",
|
|
60
|
-
"jsdom": "^
|
|
65
|
+
"jsdom": "^24.1.0",
|
|
61
66
|
"sass": "^1.66.1",
|
|
62
67
|
"sass-loader": "^13.3.2",
|
|
63
|
-
"typescript": "^5.
|
|
64
|
-
"vite": "^
|
|
65
|
-
"vite-plugin-css-injected-by-js": "^3.
|
|
66
|
-
"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"
|
|
67
72
|
}
|
|
68
73
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
ObjectEmitsOptions,
|
|
7
|
-
SlotsType
|
|
2
|
+
AllowedComponentProps,
|
|
3
|
+
ComponentCustomProps,
|
|
4
|
+
VNodeProps,
|
|
5
|
+
VNode
|
|
8
6
|
} from 'vue'
|
|
9
7
|
|
|
10
8
|
export declare interface PageInfo {
|
|
11
9
|
pageNumber: number
|
|
12
10
|
pageSize: number
|
|
11
|
+
totalPage: number
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
declare interface
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
declare interface Slots extends SlotsType {
|
|
23
|
-
default: {
|
|
24
|
-
pageNumber: number
|
|
25
|
-
pageSize: number
|
|
26
|
-
totalPage: number
|
|
27
|
-
totalRow: number
|
|
28
|
-
isFirst: boolean
|
|
29
|
-
isLast: boolean
|
|
30
|
-
}
|
|
14
|
+
export declare interface PageSlotData {
|
|
15
|
+
pageNumber: number
|
|
16
|
+
pageSize: number
|
|
17
|
+
totalPage: number
|
|
18
|
+
totalRow: number
|
|
19
|
+
isFirst: boolean
|
|
20
|
+
isLast: boolean
|
|
31
21
|
}
|
|
32
22
|
|
|
33
23
|
/**
|
|
@@ -42,16 +32,26 @@ declare interface Props {
|
|
|
42
32
|
* The number of total record
|
|
43
33
|
*/
|
|
44
34
|
totalRow: number
|
|
35
|
+
/**
|
|
36
|
+
* The number of page size
|
|
37
|
+
* @default 10
|
|
38
|
+
*/
|
|
39
|
+
pageSize?: number
|
|
45
40
|
/**
|
|
46
41
|
* v-page language
|
|
47
|
-
* @default `
|
|
42
|
+
* @default `en`
|
|
48
43
|
*/
|
|
49
44
|
language?: string
|
|
50
45
|
/**
|
|
51
46
|
* Page size list
|
|
52
47
|
* @default [10, 20, 50, 100]
|
|
53
48
|
*/
|
|
54
|
-
pageSizeMenu?:
|
|
49
|
+
pageSizeMenu?: number[]
|
|
50
|
+
/**
|
|
51
|
+
* Whether to display page size list panel
|
|
52
|
+
* @default true
|
|
53
|
+
*/
|
|
54
|
+
pageSizeOptions?: boolean
|
|
55
55
|
/**
|
|
56
56
|
* Alignment direction
|
|
57
57
|
* @default `right`
|
|
@@ -92,31 +92,44 @@ declare interface Props {
|
|
|
92
92
|
* @default false
|
|
93
93
|
*/
|
|
94
94
|
displayAll?: boolean
|
|
95
|
+
/**
|
|
96
|
+
* Hide pagination when only have one page
|
|
97
|
+
* @default false
|
|
98
|
+
*/
|
|
99
|
+
hideOnSinglePage?: boolean
|
|
95
100
|
}
|
|
96
101
|
|
|
97
|
-
declare interface
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
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
|
+
// }
|
|
103
108
|
|
|
104
|
-
declare
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
109
|
+
// declare interface Methods extends MethodOptions {
|
|
110
|
+
// /** Go to the specified page */
|
|
111
|
+
// goPage: (pageNumber: number) => void
|
|
112
|
+
// /** Re-emit `change` event and output pagination states data */
|
|
113
|
+
// reload: () => void
|
|
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
|
|
121
|
+
|
|
122
|
+
declare interface PaginationBar {
|
|
123
|
+
new (): {
|
|
124
|
+
$props: AllowedComponentProps & ComponentCustomProps & VNodeProps & Props
|
|
125
|
+
$emit: EmitUpdateModelValue & EmitChange
|
|
126
|
+
$slots: {
|
|
127
|
+
default?: (defaultSlotData: PageSlotData) => VNode[]
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
declare const PaginationBar: PaginationBar
|
|
119
132
|
|
|
120
|
-
export {
|
|
133
|
+
export { PaginationBar }
|
|
121
134
|
|
|
122
|
-
export default
|
|
135
|
+
export default PaginationBar
|