@whitesev/data-paging 0.0.1 → 0.0.3
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/dist/index.amd.js +637 -642
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +345 -0
- package/dist/index.amd.min.js.map +1 -0
- package/dist/index.cjs.js +635 -640
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +341 -0
- package/dist/index.cjs.min.js.map +1 -0
- package/dist/index.esm.js +633 -638
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +340 -0
- package/dist/index.esm.min.js.map +1 -0
- package/dist/index.iife.js +637 -643
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +345 -0
- package/dist/index.iife.min.js.map +1 -0
- package/dist/index.system.js +640 -645
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +356 -0
- package/dist/index.system.min.js.map +1 -0
- package/dist/index.umd.js +643 -646
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +351 -0
- package/dist/index.umd.min.js.map +1 -0
- package/dist/types/src/index.d.ts +183 -183
- package/dist/types/src/utils.d.ts +4 -4
- package/package.json +2 -1
- package/src/index.ts +4 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,256 +1,261 @@
|
|
|
1
|
-
const PagingDefaultConfig = () => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const PagingUtils = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
1
|
+
const PagingDefaultConfig = () => {
|
|
2
|
+
return {
|
|
3
|
+
data: [],
|
|
4
|
+
pageShowDataMaxCount: 5,
|
|
5
|
+
pageMaxStep: 3,
|
|
6
|
+
currentPage: 1,
|
|
7
|
+
pageChangeCallBack: function () {},
|
|
8
|
+
prevBtn: {
|
|
9
|
+
enable: true,
|
|
10
|
+
callBack: function () {},
|
|
11
|
+
},
|
|
12
|
+
nextBtn: {
|
|
13
|
+
enable: true,
|
|
14
|
+
callBack: function () {},
|
|
15
|
+
},
|
|
16
|
+
firstBtn: {
|
|
17
|
+
enable: true,
|
|
18
|
+
callBack: function () {},
|
|
19
|
+
},
|
|
20
|
+
lastBtn: {
|
|
21
|
+
enable: true,
|
|
22
|
+
callBack: function () {},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const PagingUtils = {
|
|
28
|
+
/**
|
|
29
|
+
* 设置安全的html
|
|
30
|
+
*/
|
|
31
|
+
setSafeHTML($el, text) {
|
|
32
|
+
// 创建 TrustedHTML 策略(需 CSP 允许)
|
|
33
|
+
try {
|
|
34
|
+
$el.innerHTML = text;
|
|
35
|
+
} catch {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
if (globalThis.trustedTypes) {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
const policy = globalThis.trustedTypes.createPolicy("safe-innerHTML", {
|
|
40
|
+
createHTML: (html) => html,
|
|
41
|
+
});
|
|
42
|
+
$el.innerHTML = policy.createHTML(text);
|
|
43
|
+
} else {
|
|
44
|
+
throw new Error("PagingUtils trustedTypes is not defined");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const version = "0.0.3";
|
|
51
|
+
|
|
52
|
+
class Paging {
|
|
53
|
+
version = version;
|
|
54
|
+
CONFIG;
|
|
55
|
+
PAGE_CONFIG = {
|
|
56
|
+
/**
|
|
57
|
+
* 获取当前所在页
|
|
58
|
+
*/
|
|
59
|
+
currentPage: () => {
|
|
60
|
+
const $page = this.DOM_CONFIG.getAttributeWithCurrentPage();
|
|
61
|
+
const page = this.DOM_CONFIG.getAttributeWithPageId($page);
|
|
62
|
+
// 如果未获取到元素,那么固定页码为1
|
|
63
|
+
return page ?? 1;
|
|
64
|
+
},
|
|
65
|
+
/** 最大页码 */
|
|
66
|
+
maxPage: 1,
|
|
67
|
+
};
|
|
68
|
+
DOM_CONFIG = {
|
|
69
|
+
/* 整个分页元素 */
|
|
70
|
+
$pageWrapper: {
|
|
71
|
+
localName: "div",
|
|
72
|
+
id: "data-paging-wrapper",
|
|
73
|
+
dom: null,
|
|
74
|
+
},
|
|
75
|
+
/* 第一页按钮 */
|
|
76
|
+
firstBtnNode: {
|
|
77
|
+
localName: "a",
|
|
78
|
+
className: "pg-first",
|
|
79
|
+
svgHTML: `<svg t="1694497357294" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4758" width="20"><path d="M730.639277 211.376748l60.943177 60.943176-301.698894 301.698893L428.940384 513.075641z" p-id="4759"></path><path d="M730.496772 814.924547l60.943176-60.943176-301.698893-301.698893L428.797879 513.225654z" p-id="4760"></path><path d="M298.666667 213.333333h85.333333v597.333334H298.666667z" p-id="4761"></path></svg>`,
|
|
80
|
+
get: () => {
|
|
81
|
+
return this.DOM_CONFIG.$pageWrapper.dom.querySelector(
|
|
82
|
+
`${this.DOM_CONFIG.firstBtnNode.localName}.${this.DOM_CONFIG.firstBtnNode.className}`
|
|
83
|
+
);
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
/* 上一页按钮 */
|
|
87
|
+
prevBtnNode: {
|
|
88
|
+
localName: "a",
|
|
89
|
+
className: "pg-prev",
|
|
90
|
+
svgHTML: `<svg t="1694497840770" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5272" width="20"><path d="M620.322607 151.04875l60.943176 60.943176-362.038672 362.038672L258.283935 513.087422z" p-id="5273"></path><path d="M620.180101 875.252545l60.943177-60.943176-362.038672-362.038672L258.141429 513.213873z" p-id="5274"></path></svg>`,
|
|
91
|
+
get: () => {
|
|
92
|
+
return this.DOM_CONFIG.$pageWrapper.dom.querySelector(
|
|
93
|
+
`${this.DOM_CONFIG.prevBtnNode.localName}.${this.DOM_CONFIG.prevBtnNode.className}`
|
|
94
|
+
);
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
/* 下一页按钮 */
|
|
98
|
+
nextBtnNode: {
|
|
99
|
+
localName: "a",
|
|
100
|
+
className: "pg-next",
|
|
101
|
+
svgHTML: `<svg t="1694497949481" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5465" width="20"><path d="M403.399239 151.02258l-60.943177 60.943177 362.038672 362.038672L765.437911 513.061252z" p-id="5466"></path><path d="M403.576858 875.263008l-60.943176-60.943176 362.038672-362.038672L765.61553 513.224336z" p-id="5467"></path></svg>`,
|
|
102
|
+
get: () => {
|
|
103
|
+
return this.DOM_CONFIG.$pageWrapper.dom.querySelector(
|
|
104
|
+
`${this.DOM_CONFIG.nextBtnNode.localName}.${this.DOM_CONFIG.nextBtnNode.className}`
|
|
105
|
+
);
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
/* 最后一页按钮 */
|
|
109
|
+
lastBtnNode: {
|
|
110
|
+
localName: "a",
|
|
111
|
+
className: "pg-last",
|
|
112
|
+
svgHTML: `<svg t="1694498035538" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2299" width="20"><path d="M516.266667 490.666667L256 230.4 315.733333 170.666667l320 320L315.733333 810.666667 256 750.933333l260.266667-260.266666zM678.4 170.666667h85.333333v640h-85.333333V170.666667z" p-id="2300"></path></svg>`,
|
|
113
|
+
get: () => {
|
|
114
|
+
return this.DOM_CONFIG.$pageWrapper.dom.querySelector(
|
|
115
|
+
`${this.DOM_CONFIG.lastBtnNode.localName}.${this.DOM_CONFIG.lastBtnNode.className}`
|
|
116
|
+
);
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
/**
|
|
120
|
+
* 设置 元素的 页码 值
|
|
121
|
+
* @param $el
|
|
122
|
+
* @param page
|
|
123
|
+
*/
|
|
124
|
+
setAttributeWithPageId: ($el, page) => {
|
|
125
|
+
$el.setAttribute("page-id", String(page));
|
|
126
|
+
},
|
|
127
|
+
/**
|
|
128
|
+
* 获取 元素 的页码属性
|
|
129
|
+
* @param $el
|
|
130
|
+
*/
|
|
131
|
+
getAttributeWithPageId: ($el) => {
|
|
132
|
+
const pageId = $el?.getAttribute("page-id");
|
|
133
|
+
return pageId ? parseInt(pageId) : null;
|
|
134
|
+
},
|
|
135
|
+
/**
|
|
136
|
+
* 判断 元素 是否存在页码属性
|
|
137
|
+
* @param $el
|
|
138
|
+
*/
|
|
139
|
+
hasAttributeWithPageId: ($el) => {
|
|
140
|
+
return $el.hasAttribute("page-id");
|
|
141
|
+
},
|
|
142
|
+
/**
|
|
143
|
+
* 设置 元素的属性 为当前所在页码
|
|
144
|
+
* @param $el
|
|
145
|
+
*/
|
|
146
|
+
setAttributeWithCurrentPage: ($el) => {
|
|
147
|
+
$el.setAttribute("data-current-page", "");
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* 获取当前页码的元素
|
|
151
|
+
* @param $pageWrapper
|
|
152
|
+
*/
|
|
153
|
+
getAttributeWithCurrentPage: ($pageWrapper) => {
|
|
154
|
+
return ($pageWrapper || this.DOM_CONFIG.$pageWrapper.dom).querySelector("a[data-current-page]");
|
|
155
|
+
},
|
|
156
|
+
/**
|
|
157
|
+
* 判断 元素 是否存在 当前页的属性
|
|
158
|
+
* @param $el
|
|
159
|
+
*/
|
|
160
|
+
hasAttributeWithCurrentPage: ($el) => {
|
|
161
|
+
return $el.hasAttribute("data-current-page");
|
|
162
|
+
},
|
|
163
|
+
/**
|
|
164
|
+
* 移除 当前页码的属性
|
|
165
|
+
* @param $el
|
|
166
|
+
*/
|
|
167
|
+
removeAttributeWithCurrentPage: ($el) => {
|
|
168
|
+
$el.removeAttribute("data-current-page");
|
|
169
|
+
},
|
|
170
|
+
/**
|
|
171
|
+
* 设置 元素 禁用
|
|
172
|
+
* @param $el
|
|
173
|
+
*/
|
|
174
|
+
setAttributeWithDisabled: ($el) => {
|
|
175
|
+
$el.setAttribute("disabled", "true");
|
|
176
|
+
},
|
|
177
|
+
/**
|
|
178
|
+
* 移除当前页面的禁用的元素
|
|
179
|
+
* @param $pageWrapper
|
|
180
|
+
*/
|
|
181
|
+
removeAllAttributeWithDisabled: ($pageWrapper) => {
|
|
182
|
+
($pageWrapper || this.DOM_CONFIG.$pageWrapper.dom)?.querySelectorAll("a[class][disabled]").forEach((item) => {
|
|
183
|
+
item.removeAttribute("disabled");
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
/**
|
|
187
|
+
* 获取 第一页 元素节点
|
|
188
|
+
* @param $pageWrapper
|
|
189
|
+
*/
|
|
190
|
+
getFirstPageNode: ($pageWrapper) => {
|
|
191
|
+
return ($pageWrapper || this.DOM_CONFIG.$pageWrapper.dom).querySelector("a[page-id='1']");
|
|
192
|
+
},
|
|
193
|
+
/**
|
|
194
|
+
* 获取 最后一页 元素节点
|
|
195
|
+
* @param {$pageWrapper
|
|
196
|
+
*/
|
|
197
|
+
getLastPageNode: ($pageWrapper) => {
|
|
198
|
+
return ($pageWrapper || this.DOM_CONFIG.$pageWrapper.dom).querySelector(
|
|
199
|
+
`a[page-id='${this.PAGE_CONFIG.maxPage}']`
|
|
200
|
+
);
|
|
201
|
+
},
|
|
202
|
+
/**
|
|
203
|
+
* 获取当前所有的页码元素节点
|
|
204
|
+
* @param $pageWrapper
|
|
205
|
+
*/
|
|
206
|
+
getAllPageNode: ($pageWrapper) => {
|
|
207
|
+
return Array.from(($pageWrapper || this.DOM_CONFIG.$pageWrapper.dom).querySelectorAll("a[page-id]"));
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* @param config
|
|
212
|
+
*/
|
|
213
|
+
constructor(config) {
|
|
214
|
+
this.CONFIG = PagingDefaultConfig();
|
|
215
|
+
this.changeConfig(config);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* 隐藏分页容器
|
|
219
|
+
* @param $wrapper 分页容器
|
|
220
|
+
*/
|
|
221
|
+
hide($wrapper = this.DOM_CONFIG.$pageWrapper.dom) {
|
|
222
|
+
if (!$wrapper) return;
|
|
223
|
+
$wrapper.style.display = "none";
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 显示分页容器
|
|
227
|
+
* @param $wrapper 分页容器
|
|
228
|
+
*/
|
|
229
|
+
show($wrapper = this.DOM_CONFIG.$pageWrapper.dom) {
|
|
230
|
+
if (!$wrapper) return;
|
|
231
|
+
$wrapper.style.display = "";
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* 判断分页容器是否隐藏
|
|
235
|
+
* @param $wrapper 分页容器
|
|
236
|
+
*/
|
|
237
|
+
isHide($wrapper = this.DOM_CONFIG.$pageWrapper.dom) {
|
|
238
|
+
if (!$wrapper) return;
|
|
239
|
+
return $wrapper.style.display.includes("none");
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* 销毁分页容器
|
|
243
|
+
*/
|
|
244
|
+
destory() {
|
|
245
|
+
const $wrapper = this.DOM_CONFIG.$pageWrapper.dom;
|
|
246
|
+
if (!$wrapper) return;
|
|
247
|
+
const $parent = $wrapper.parentElement;
|
|
248
|
+
$parent?.removeChild?.($wrapper);
|
|
249
|
+
this.DOM_CONFIG.$pageWrapper.dom = null;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* 添加CSS
|
|
253
|
+
* @param $parent 添加到目标元素
|
|
254
|
+
*/
|
|
255
|
+
addCSS($parent = document.head) {
|
|
256
|
+
const $style = document.createElement("style");
|
|
257
|
+
$style.setAttribute("type", "text/css");
|
|
258
|
+
const cssText = /*css*/ `@charset "utf-8";
|
|
254
259
|
#${this.DOM_CONFIG.$pageWrapper.id} {
|
|
255
260
|
text-align: center;
|
|
256
261
|
display: inline-block;
|
|
@@ -308,388 +313,378 @@ class Paging {
|
|
|
308
313
|
border: 1px solid transparent;
|
|
309
314
|
color: #c9c9c9;
|
|
310
315
|
}
|
|
311
|
-
`;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
if ($pageWrapper) {
|
|
687
|
-
this.after($pageWrapper);
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
const DataPaging = Paging;
|
|
693
|
-
|
|
694
|
-
export { DataPaging as default };
|
|
695
|
-
//# sourceMappingURL=index.esm.js.map
|
|
316
|
+
`;
|
|
317
|
+
PagingUtils.setSafeHTML($style, cssText);
|
|
318
|
+
$parent.appendChild($style);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* 创建分页元素
|
|
322
|
+
*/
|
|
323
|
+
createDataPagingWrapper() {
|
|
324
|
+
const $pageWrapper = document.createElement(this.DOM_CONFIG.$pageWrapper.localName);
|
|
325
|
+
this.DOM_CONFIG.$pageWrapper.dom = $pageWrapper;
|
|
326
|
+
$pageWrapper.id = this.DOM_CONFIG.$pageWrapper.id;
|
|
327
|
+
/* 第一页 */
|
|
328
|
+
const $firstPage = document.createElement(this.DOM_CONFIG.firstBtnNode.localName);
|
|
329
|
+
PagingUtils.setSafeHTML($firstPage, this.DOM_CONFIG.firstBtnNode.svgHTML);
|
|
330
|
+
/* 上一页 */
|
|
331
|
+
const $prevPage = document.createElement(this.DOM_CONFIG.prevBtnNode.localName);
|
|
332
|
+
PagingUtils.setSafeHTML($prevPage, this.DOM_CONFIG.prevBtnNode.svgHTML);
|
|
333
|
+
/* 下一页 */
|
|
334
|
+
const $nextPage = document.createElement(this.DOM_CONFIG.nextBtnNode.localName);
|
|
335
|
+
PagingUtils.setSafeHTML($nextPage, this.DOM_CONFIG.nextBtnNode.svgHTML);
|
|
336
|
+
/* 最后一页 */
|
|
337
|
+
const $lastPage = document.createElement(this.DOM_CONFIG.lastBtnNode.localName);
|
|
338
|
+
PagingUtils.setSafeHTML($lastPage, this.DOM_CONFIG.lastBtnNode.svgHTML);
|
|
339
|
+
$firstPage.className = this.DOM_CONFIG.firstBtnNode.className;
|
|
340
|
+
$prevPage.className = this.DOM_CONFIG.prevBtnNode.className;
|
|
341
|
+
$nextPage.className = this.DOM_CONFIG.nextBtnNode.className;
|
|
342
|
+
$lastPage.className = this.DOM_CONFIG.lastBtnNode.className;
|
|
343
|
+
/* 计算总数据量除以显示的数据量 得出分页的数量 */
|
|
344
|
+
this.PAGE_CONFIG.maxPage = Math.ceil(this.CONFIG.data.length / this.CONFIG.pageShowDataMaxCount);
|
|
345
|
+
/* 校正超出或小于的当前页码 */
|
|
346
|
+
if (this.CONFIG.currentPage < 1) {
|
|
347
|
+
this.CONFIG.currentPage = 1;
|
|
348
|
+
} else if (this.CONFIG.currentPage > this.PAGE_CONFIG.maxPage) {
|
|
349
|
+
this.CONFIG.currentPage = this.PAGE_CONFIG.maxPage;
|
|
350
|
+
}
|
|
351
|
+
/* 超过1 才开启分页 */
|
|
352
|
+
if (this.PAGE_CONFIG.maxPage < 2) {
|
|
353
|
+
return $pageWrapper;
|
|
354
|
+
}
|
|
355
|
+
/* 判断第一页按钮 是否开启 */
|
|
356
|
+
if (this.CONFIG.firstBtn.enable) {
|
|
357
|
+
this.setFirstBtnClickEvent($firstPage, $pageWrapper);
|
|
358
|
+
$pageWrapper.appendChild($firstPage);
|
|
359
|
+
}
|
|
360
|
+
/* 判断上一页按钮 是否开启 */
|
|
361
|
+
if (this.CONFIG.prevBtn.enable) {
|
|
362
|
+
this.setPrevBtnClickEvent($prevPage, $pageWrapper);
|
|
363
|
+
$pageWrapper.appendChild($prevPage);
|
|
364
|
+
}
|
|
365
|
+
let currentPage = this.CONFIG.currentPage;
|
|
366
|
+
/* 计算出的最大页码在限制的显示页码数量内 */
|
|
367
|
+
/* 比如计算出的页码总共有5个,设置中当前能显示出的页码按钮元素为3个 */
|
|
368
|
+
if (this.CONFIG.pageMaxStep > this.PAGE_CONFIG.maxPage) {
|
|
369
|
+
for (let index = currentPage; index <= this.PAGE_CONFIG.maxPage; index++) {
|
|
370
|
+
const $page = document.createElement("a");
|
|
371
|
+
this.DOM_CONFIG.setAttributeWithPageId($page, index);
|
|
372
|
+
$page.innerText = String(index);
|
|
373
|
+
if (this.CONFIG.currentPage === index) {
|
|
374
|
+
this.DOM_CONFIG.setAttributeWithCurrentPage($page);
|
|
375
|
+
}
|
|
376
|
+
this.setPageBtnClickEvent($page, $pageWrapper);
|
|
377
|
+
$pageWrapper.appendChild($page);
|
|
378
|
+
}
|
|
379
|
+
} else {
|
|
380
|
+
/* 如果 当前页 + 限制显示的页码 大于等于 最大页,那么 从最后一页倒序着添加 */
|
|
381
|
+
if (currentPage + this.CONFIG.pageMaxStep > this.PAGE_CONFIG.maxPage) {
|
|
382
|
+
currentPage = this.PAGE_CONFIG.maxPage;
|
|
383
|
+
const needAppendNodeList = [];
|
|
384
|
+
for (let index = 0; index < this.CONFIG.pageMaxStep; index++) {
|
|
385
|
+
const $page = document.createElement("a");
|
|
386
|
+
this.DOM_CONFIG.setAttributeWithPageId($page, currentPage);
|
|
387
|
+
$page.innerText = String(currentPage);
|
|
388
|
+
if (this.CONFIG.currentPage === currentPage) {
|
|
389
|
+
this.DOM_CONFIG.setAttributeWithCurrentPage($page);
|
|
390
|
+
}
|
|
391
|
+
this.setPageBtnClickEvent($page, $pageWrapper);
|
|
392
|
+
needAppendNodeList.push($page);
|
|
393
|
+
currentPage--;
|
|
394
|
+
}
|
|
395
|
+
needAppendNodeList.reverse();
|
|
396
|
+
needAppendNodeList.forEach((item) => {
|
|
397
|
+
$pageWrapper.appendChild(item);
|
|
398
|
+
});
|
|
399
|
+
} else {
|
|
400
|
+
/* 当前页 在计算出的页码内 */
|
|
401
|
+
for (let index = 0; index < this.CONFIG.pageMaxStep; index++) {
|
|
402
|
+
const $page = document.createElement("a");
|
|
403
|
+
this.DOM_CONFIG.setAttributeWithPageId($page, currentPage);
|
|
404
|
+
$page.innerText = String(currentPage);
|
|
405
|
+
if (this.CONFIG.currentPage === currentPage) {
|
|
406
|
+
this.DOM_CONFIG.setAttributeWithCurrentPage($page);
|
|
407
|
+
}
|
|
408
|
+
this.setPageBtnClickEvent($page, $pageWrapper);
|
|
409
|
+
$pageWrapper.appendChild($page);
|
|
410
|
+
currentPage++;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/* 判断下一页按钮 是否开启 */
|
|
415
|
+
if (this.CONFIG.nextBtn.enable) {
|
|
416
|
+
this.setNextBtnClickEvent($nextPage, $pageWrapper);
|
|
417
|
+
$pageWrapper.appendChild($nextPage);
|
|
418
|
+
}
|
|
419
|
+
/* 判断最后一页按钮 是否开启 */
|
|
420
|
+
if (this.CONFIG.lastBtn.enable) {
|
|
421
|
+
this.setLastBtnClickEvent($lastPage, $pageWrapper);
|
|
422
|
+
$pageWrapper.appendChild($lastPage);
|
|
423
|
+
}
|
|
424
|
+
/* 配置中的当前页码为1时 设置 第一页、上一页按钮禁用 */
|
|
425
|
+
if (this.CONFIG.currentPage === 1) {
|
|
426
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.firstBtnNode.get());
|
|
427
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.prevBtnNode.get());
|
|
428
|
+
} else if (this.CONFIG.currentPage === this.PAGE_CONFIG.maxPage) {
|
|
429
|
+
/* 如果为最大的页码 下一页、最后一页禁用 */
|
|
430
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.nextBtnNode.get());
|
|
431
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.lastBtnNode.get());
|
|
432
|
+
}
|
|
433
|
+
return $pageWrapper;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* 设置 第一页 点击事件
|
|
437
|
+
* @param $page 分页元素
|
|
438
|
+
* @param $pageWrapper 分页按钮的容器元素
|
|
439
|
+
*/
|
|
440
|
+
setFirstBtnClickEvent($page, $pageWrapper) {
|
|
441
|
+
$page.addEventListener("click", async (event) => {
|
|
442
|
+
const $currentPage = this.DOM_CONFIG.getAttributeWithCurrentPage();
|
|
443
|
+
/* 当前页为第一页时无效 */
|
|
444
|
+
if (this.DOM_CONFIG.getAttributeWithPageId($currentPage) === 1) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
await this.CONFIG.firstBtn?.callBack?.(event);
|
|
448
|
+
const $allPage = this.DOM_CONFIG.getAllPageNode($pageWrapper);
|
|
449
|
+
for (let index = 0; index < this.CONFIG.pageMaxStep; index++) {
|
|
450
|
+
const $page = $allPage[index];
|
|
451
|
+
if ($page == null) {
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
/* 设置当前页码为第一页 */
|
|
455
|
+
if (index === 0) {
|
|
456
|
+
this.DOM_CONFIG.setAttributeWithCurrentPage($page);
|
|
457
|
+
} else {
|
|
458
|
+
/* 移除其它设置的第一页 */
|
|
459
|
+
this.DOM_CONFIG.removeAttributeWithCurrentPage($page);
|
|
460
|
+
}
|
|
461
|
+
this.DOM_CONFIG.setAttributeWithPageId($page, index + 1);
|
|
462
|
+
$page.innerText = String(index + 1);
|
|
463
|
+
}
|
|
464
|
+
this.DOM_CONFIG.removeAllAttributeWithDisabled($pageWrapper);
|
|
465
|
+
/* 可视区域存在第一页的页码时,禁用第一页、上一页按钮 */
|
|
466
|
+
if (this.DOM_CONFIG.getFirstPageNode($pageWrapper)) {
|
|
467
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.firstBtnNode.get());
|
|
468
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.prevBtnNode.get());
|
|
469
|
+
}
|
|
470
|
+
this.CONFIG.pageChangeCallBack(1);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* 设置 上一页 点击事件
|
|
475
|
+
* @param $page 分页元素
|
|
476
|
+
* @param $pageWrapper 分页按钮的容器元素
|
|
477
|
+
*/
|
|
478
|
+
setPrevBtnClickEvent($page, $pageWrapper) {
|
|
479
|
+
$page.addEventListener("click", async (event) => {
|
|
480
|
+
const $currentPage = this.DOM_CONFIG.getAttributeWithCurrentPage();
|
|
481
|
+
/* 当前页为第一页时无效 */
|
|
482
|
+
if (this.DOM_CONFIG.getAttributeWithPageId($currentPage) === 1) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
await this.CONFIG.prevBtn?.callBack?.(event);
|
|
486
|
+
const $prev = $currentPage.previousElementSibling;
|
|
487
|
+
if ($prev && this.DOM_CONFIG.hasAttributeWithPageId($prev)) {
|
|
488
|
+
$prev.click();
|
|
489
|
+
} else {
|
|
490
|
+
const $allPage = this.DOM_CONFIG.getAllPageNode($pageWrapper);
|
|
491
|
+
$allPage.forEach((item) => {
|
|
492
|
+
let page = this.DOM_CONFIG.getAttributeWithPageId(item);
|
|
493
|
+
page--;
|
|
494
|
+
this.DOM_CONFIG.setAttributeWithPageId(item, page);
|
|
495
|
+
item.innerText = String(page);
|
|
496
|
+
});
|
|
497
|
+
this.CONFIG.pageChangeCallBack(this.PAGE_CONFIG.currentPage());
|
|
498
|
+
}
|
|
499
|
+
this.DOM_CONFIG.removeAllAttributeWithDisabled($pageWrapper);
|
|
500
|
+
/* 如果当前第1页可见,且当前所在页不是第1页,则禁用上一页按钮和第一页按钮 */
|
|
501
|
+
if (this.DOM_CONFIG.getFirstPageNode($pageWrapper) && this.PAGE_CONFIG.currentPage() == 1) {
|
|
502
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.firstBtnNode.get());
|
|
503
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.prevBtnNode.get());
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* 设置 下一页 点击事件
|
|
509
|
+
* @param $page 分页元素
|
|
510
|
+
* @param $pageWrapper 分页按钮的容器元素
|
|
511
|
+
*/
|
|
512
|
+
setNextBtnClickEvent($page, $pageWrapper) {
|
|
513
|
+
$page.addEventListener("click", async (event) => {
|
|
514
|
+
const $currentPage = this.DOM_CONFIG.getAttributeWithCurrentPage();
|
|
515
|
+
/* 当前页出于最后一页时 无效点击 */
|
|
516
|
+
if (this.DOM_CONFIG.getAttributeWithPageId($currentPage) === this.PAGE_CONFIG.maxPage) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
await this.CONFIG.nextBtn?.callBack?.(event);
|
|
520
|
+
/* 如果后面的按钮存在页码属性 点击 */
|
|
521
|
+
const $next = $currentPage.nextElementSibling;
|
|
522
|
+
if ($next && this.DOM_CONFIG.hasAttributeWithPageId($next)) {
|
|
523
|
+
$next.click();
|
|
524
|
+
} else {
|
|
525
|
+
const allPageNode = this.DOM_CONFIG.getAllPageNode($pageWrapper);
|
|
526
|
+
allPageNode.forEach((item) => {
|
|
527
|
+
let page = this.DOM_CONFIG.getAttributeWithPageId(item);
|
|
528
|
+
page++;
|
|
529
|
+
if (page > this.PAGE_CONFIG.maxPage) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
this.DOM_CONFIG.setAttributeWithPageId(item, page);
|
|
533
|
+
item.innerText = String(page);
|
|
534
|
+
});
|
|
535
|
+
this.CONFIG.pageChangeCallBack(this.PAGE_CONFIG.currentPage());
|
|
536
|
+
}
|
|
537
|
+
this.DOM_CONFIG.removeAllAttributeWithDisabled($pageWrapper);
|
|
538
|
+
if (this.DOM_CONFIG.getLastPageNode() && this.PAGE_CONFIG.currentPage() == this.PAGE_CONFIG.maxPage) {
|
|
539
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.nextBtnNode.get());
|
|
540
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.lastBtnNode.get());
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* 设置 最后一页 点击事件
|
|
546
|
+
* @param $page 分页元素
|
|
547
|
+
* @param $pageWrapper 分页按钮的容器元素
|
|
548
|
+
*/
|
|
549
|
+
setLastBtnClickEvent($page, $pageWrapper) {
|
|
550
|
+
$page.addEventListener("click", async (event) => {
|
|
551
|
+
const $currentPage = this.DOM_CONFIG.getAttributeWithCurrentPage();
|
|
552
|
+
if (this.DOM_CONFIG.getAttributeWithPageId($currentPage) === this.PAGE_CONFIG.maxPage) {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
await this.CONFIG.lastBtn?.callBack?.(event);
|
|
556
|
+
const $allPage = Array.from(this.DOM_CONFIG.getAllPageNode($pageWrapper));
|
|
557
|
+
$allPage.reverse();
|
|
558
|
+
let pageCount = this.PAGE_CONFIG.maxPage;
|
|
559
|
+
let index = 0;
|
|
560
|
+
while (true) {
|
|
561
|
+
if (this.PAGE_CONFIG.maxPage - pageCount > 3) {
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
const $page = $allPage[index];
|
|
565
|
+
if ($page == null) {
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
if (index === 0) {
|
|
569
|
+
this.DOM_CONFIG.setAttributeWithCurrentPage($page);
|
|
570
|
+
} else {
|
|
571
|
+
this.DOM_CONFIG.removeAttributeWithCurrentPage($page);
|
|
572
|
+
}
|
|
573
|
+
this.DOM_CONFIG.setAttributeWithPageId($page, pageCount);
|
|
574
|
+
$page.innerText = String(pageCount);
|
|
575
|
+
pageCount--;
|
|
576
|
+
index++;
|
|
577
|
+
}
|
|
578
|
+
this.DOM_CONFIG.removeAllAttributeWithDisabled($pageWrapper);
|
|
579
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.nextBtnNode.get());
|
|
580
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.lastBtnNode.get());
|
|
581
|
+
this.CONFIG.pageChangeCallBack(this.PAGE_CONFIG.maxPage);
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* 设置 页 点击事件
|
|
586
|
+
* @param $page 分页元素
|
|
587
|
+
* @param $pageWrapper 分页按钮的容器元素
|
|
588
|
+
*/
|
|
589
|
+
setPageBtnClickEvent($page, $pageWrapper) {
|
|
590
|
+
$page.addEventListener("click", async () => {
|
|
591
|
+
const $clickButton = $page;
|
|
592
|
+
const $allPageList = this.DOM_CONFIG.getAllPageNode($pageWrapper);
|
|
593
|
+
for (const item of $allPageList) {
|
|
594
|
+
/* 是当前点击的页码 */
|
|
595
|
+
if (item == $clickButton) {
|
|
596
|
+
/* 如果 当前点击的页码不是current */
|
|
597
|
+
if (!this.DOM_CONFIG.hasAttributeWithCurrentPage($clickButton)) {
|
|
598
|
+
this.DOM_CONFIG.setAttributeWithCurrentPage($clickButton);
|
|
599
|
+
const currentPage = this.PAGE_CONFIG.currentPage();
|
|
600
|
+
await this.CONFIG?.pageChangeCallBack?.(currentPage);
|
|
601
|
+
}
|
|
602
|
+
} else {
|
|
603
|
+
this.DOM_CONFIG.removeAttributeWithCurrentPage(item);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
this.DOM_CONFIG.removeAllAttributeWithDisabled($pageWrapper);
|
|
607
|
+
/* 如果当前第1页可见,且当前所在页不是第1页,则禁用上一页按钮和第一页按钮 */
|
|
608
|
+
if (this.DOM_CONFIG.getFirstPageNode($pageWrapper) && this.PAGE_CONFIG.currentPage() == 1) {
|
|
609
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.firstBtnNode.get());
|
|
610
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.prevBtnNode.get());
|
|
611
|
+
}
|
|
612
|
+
/* 如果当前最后一页可见,且当前所在页不是最后一页,则禁用下一页按钮和最后一页按钮 */
|
|
613
|
+
if (this.DOM_CONFIG.getLastPageNode() && this.PAGE_CONFIG.currentPage() == this.PAGE_CONFIG.maxPage) {
|
|
614
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.nextBtnNode.get());
|
|
615
|
+
this.DOM_CONFIG.setAttributeWithDisabled(this.DOM_CONFIG.lastBtnNode.get());
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* 把分页添加到某个父元素下
|
|
621
|
+
* @param $parent
|
|
622
|
+
*/
|
|
623
|
+
append($parent) {
|
|
624
|
+
const isHide = this.isHide();
|
|
625
|
+
// 销毁旧的
|
|
626
|
+
this.destory();
|
|
627
|
+
const $pageWrapper = this.createDataPagingWrapper();
|
|
628
|
+
if (isHide) {
|
|
629
|
+
// 旧的是隐藏状态
|
|
630
|
+
// 继承该状态
|
|
631
|
+
this.hide($pageWrapper);
|
|
632
|
+
}
|
|
633
|
+
$parent.appendChild($pageWrapper);
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* 把分页添加到某个元素之后
|
|
637
|
+
*/
|
|
638
|
+
after($el) {
|
|
639
|
+
const isHide = this.isHide();
|
|
640
|
+
const $parent = $el.parentElement;
|
|
641
|
+
const $nextSlibling = $el.nextSibling;
|
|
642
|
+
// 销毁旧的
|
|
643
|
+
this.destory();
|
|
644
|
+
const $pageWrapper = this.createDataPagingWrapper();
|
|
645
|
+
if (isHide) {
|
|
646
|
+
// 旧的是隐藏状态
|
|
647
|
+
// 继承该状态
|
|
648
|
+
this.hide($pageWrapper);
|
|
649
|
+
}
|
|
650
|
+
if (!$parent || $nextSlibling) {
|
|
651
|
+
// 任意一个不行
|
|
652
|
+
$el.after($pageWrapper);
|
|
653
|
+
} else {
|
|
654
|
+
$parent.insertBefore($pageWrapper, $nextSlibling);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* 动态修改配置,注意,修改后需要.append修改原来的元素
|
|
659
|
+
* @param config 配置
|
|
660
|
+
*/
|
|
661
|
+
changeConfig(config) {
|
|
662
|
+
Object.assign(this.CONFIG, config);
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* 刷新页面,重新渲染分页元素
|
|
666
|
+
* @param data 新的数据
|
|
667
|
+
* @example
|
|
668
|
+
* 当总页数5页,当前在第3页,把第3页的数据删完,后面2页的数据会自动往前,需要重新计算数据
|
|
669
|
+
* 且重新计算的数据的页数大于当前页(第3页)时,当前页不变,若小于当前页(第3页),则当前页为计算好的最大页
|
|
670
|
+
*/
|
|
671
|
+
refresh(data) {
|
|
672
|
+
this.CONFIG.data = [];
|
|
673
|
+
this.CONFIG.data = data;
|
|
674
|
+
let currentPage = this.PAGE_CONFIG.currentPage();
|
|
675
|
+
const maxPage = Math.ceil(data.length / this.CONFIG.pageShowDataMaxCount);
|
|
676
|
+
if (currentPage > maxPage) {
|
|
677
|
+
currentPage = maxPage;
|
|
678
|
+
}
|
|
679
|
+
this.CONFIG.currentPage = currentPage;
|
|
680
|
+
const $pageWrapper = this.DOM_CONFIG.$pageWrapper.dom;
|
|
681
|
+
if ($pageWrapper) {
|
|
682
|
+
this.after($pageWrapper);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const DataPaging = Paging;
|
|
688
|
+
|
|
689
|
+
export { DataPaging as default };
|
|
690
|
+
//# sourceMappingURL=index.esm.js.map
|