y-design-ssr 0.2.1 → 0.2.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/libs/button/index.css +579 -1
- package/libs/button/index.mjs +111 -66
- package/libs/button/index.umd.js +203 -2
- package/libs/button/package.json +12 -0
- package/libs/cell/index.css +1077 -1
- package/libs/cell/index.mjs +167 -104
- package/libs/cell/index.umd.js +300 -2
- package/libs/cell/package.json +12 -0
- package/libs/checkbox/index.css +1053 -1
- package/libs/checkbox/index.mjs +242 -127
- package/libs/checkbox/index.umd.js +369 -2
- package/libs/checkbox/package.json +12 -0
- package/libs/checkboxGroup/index.css +422 -1
- package/libs/checkboxGroup/index.mjs +173 -87
- package/libs/checkboxGroup/index.umd.js +265 -2
- package/libs/checkboxGroup/package.json +12 -0
- package/libs/col/index.css +615 -1
- package/libs/col/index.mjs +246 -81
- package/libs/col/index.umd.js +305 -2
- package/libs/col/package.json +12 -0
- package/libs/countdown/index.css +417 -1
- package/libs/countdown/index.mjs +179 -71
- package/libs/countdown/index.umd.js +231 -2
- package/libs/countdown/package.json +12 -0
- package/libs/dialog/index.css +1405 -1
- package/libs/dialog/index.mjs +646 -476
- package/libs/dialog/index.umd.js +1128 -2
- package/libs/dialog/package.json +12 -0
- package/libs/empty/index.css +457 -1
- package/libs/empty/index.mjs +91 -44
- package/libs/empty/index.umd.js +139 -2
- package/libs/empty/package.json +12 -0
- package/libs/form/index.css +477 -1
- package/libs/form/index.mjs +226 -126
- package/libs/form/index.umd.js +319 -2
- package/libs/form/package.json +12 -0
- package/libs/formItem/index.css +477 -1
- package/libs/formItem/index.mjs +276 -126
- package/libs/formItem/index.umd.js +372 -2
- package/libs/formItem/package.json +12 -0
- package/libs/icon/index.css +982 -1
- package/libs/icon/index.mjs +107 -58
- package/libs/icon/index.umd.js +186 -2
- package/libs/icon/package.json +12 -0
- package/libs/index.css +2902 -1
- package/libs/index.mjs +3785 -2344
- package/libs/index.umd.js +5509 -2
- package/libs/input/index.css +483 -1
- package/libs/input/index.mjs +183 -92
- package/libs/input/index.umd.js +274 -2
- package/libs/input/package.json +12 -0
- package/libs/layout/index.css +684 -1
- package/libs/layout/index.mjs +230 -130
- package/libs/layout/index.umd.js +318 -2
- package/libs/layout/package.json +12 -0
- package/libs/list/index.css +440 -1
- package/libs/list/index.mjs +388 -207
- package/libs/list/index.umd.js +571 -2
- package/libs/list/package.json +12 -0
- package/libs/loading/index.css +548 -1
- package/libs/loading/index.mjs +196 -118
- package/libs/loading/index.umd.js +321 -2
- package/libs/loading/package.json +12 -0
- package/libs/mask/index.css +426 -1
- package/libs/mask/index.mjs +131 -70
- package/libs/mask/index.umd.js +201 -2
- package/libs/mask/package.json +12 -0
- package/libs/popup/index.css +465 -1
- package/libs/popup/index.mjs +210 -134
- package/libs/popup/index.umd.js +358 -2
- package/libs/popup/package.json +12 -0
- package/libs/progress/index.css +488 -1
- package/libs/progress/index.mjs +200 -128
- package/libs/progress/index.umd.js +322 -2
- package/libs/progress/package.json +12 -0
- package/libs/pullrefresh/index.css +441 -1
- package/libs/pullrefresh/index.mjs +241 -111
- package/libs/pullrefresh/index.umd.js +302 -2
- package/libs/pullrefresh/package.json +12 -0
- package/libs/row/index.css +485 -1
- package/libs/row/index.mjs +181 -89
- package/libs/row/index.umd.js +237 -2
- package/libs/row/package.json +12 -0
- package/libs/slider/index.css +558 -1
- package/libs/slider/index.mjs +356 -160
- package/libs/slider/index.umd.js +453 -2
- package/libs/slider/package.json +12 -0
- package/libs/stepper/index.css +489 -1
- package/libs/stepper/index.mjs +181 -101
- package/libs/stepper/index.umd.js +269 -2
- package/libs/stepper/package.json +12 -0
- package/libs/swipe/index.css +506 -1
- package/libs/swipe/index.mjs +542 -259
- package/libs/swipe/index.umd.js +703 -2
- package/libs/swipe/package.json +12 -0
- package/libs/swipeItem/index.css +424 -1
- package/libs/swipeItem/index.mjs +111 -52
- package/libs/swipeItem/index.umd.js +154 -2
- package/libs/swipeItem/package.json +12 -0
- package/libs/switch/index.css +472 -1
- package/libs/switch/index.mjs +121 -62
- package/libs/switch/index.umd.js +200 -2
- package/libs/switch/package.json +12 -0
- package/libs/tab/index.mjs +131 -68
- package/libs/tab/index.umd.js +190 -1
- package/libs/tab/package.json +12 -0
- package/libs/tabs/index.css +514 -1
- package/libs/tabs/index.mjs +751 -410
- package/libs/tabs/index.umd.js +1020 -2
- package/libs/tabs/package.json +12 -0
- package/libs/toast/index.css +1050 -1
- package/libs/toast/index.mjs +183 -114
- package/libs/toast/index.umd.js +306 -2
- package/libs/toast/package.json +12 -0
- package/libs/tooltip/index.css +514 -1
- package/libs/tooltip/index.mjs +293 -155
- package/libs/tooltip/index.umd.js +416 -2
- package/libs/tooltip/package.json +12 -0
- package/package.json +3 -3
package/libs/list/index.mjs
CHANGED
|
@@ -1,11 +1,46 @@
|
|
|
1
|
-
import { ref
|
|
2
|
-
const
|
|
3
|
-
(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ref, reactive, defineComponent, createVNode, computed, onMounted, onUpdated, nextTick, onUnmounted, createTextVNode } from "vue";
|
|
2
|
+
const tagTester = (name2) => {
|
|
3
|
+
return (obj) => {
|
|
4
|
+
return Object.prototype.toString.call(obj) === `[object ${name2}]`;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
const isNumber = tagTester("Number");
|
|
8
|
+
const getMods = (el, mods) => {
|
|
9
|
+
if (!mods) {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
if (typeof mods === "string") {
|
|
13
|
+
return ` ${el}--${mods}`;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(mods)) {
|
|
16
|
+
return mods.reduce((acc, cur) => acc + getMods(el, cur), "");
|
|
17
|
+
}
|
|
18
|
+
return Object.keys(mods).reduce(
|
|
19
|
+
(acc, cur) => acc + (mods[cur] ? getMods(el, cur) : ""),
|
|
20
|
+
""
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
const createBEM = (block) => {
|
|
24
|
+
return (el, mods) => {
|
|
25
|
+
let _el = el;
|
|
26
|
+
let _mods = mods;
|
|
27
|
+
if (_el && typeof _el !== "string") {
|
|
28
|
+
_mods = _el;
|
|
29
|
+
_el = "";
|
|
30
|
+
}
|
|
31
|
+
_el = _el ? `${block}__${_el}` : block;
|
|
32
|
+
return `${_el}${getMods(_el, _mods)}`;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const createGlobalBem = () => {
|
|
36
|
+
return (el, mods) => {
|
|
37
|
+
if (!mods) {
|
|
38
|
+
return `y-${el}`;
|
|
39
|
+
}
|
|
40
|
+
return `${getMods(`y-${el}`, mods)}`;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const defaultLang = {
|
|
9
44
|
"pull-refresh": {
|
|
10
45
|
pulling: "下拉刷新...",
|
|
11
46
|
loosing: "释放刷新...",
|
|
@@ -17,15 +52,22 @@ const ne = (e) => (n) => Object.prototype.toString.call(n) === `[object ${e}]`,
|
|
|
17
52
|
validateMessage: "请输入正确内容"
|
|
18
53
|
}
|
|
19
54
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"zh-CN":
|
|
55
|
+
ref("zh-CN");
|
|
56
|
+
reactive({
|
|
57
|
+
"zh-CN": defaultLang
|
|
23
58
|
});
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
return [
|
|
27
|
-
}
|
|
28
|
-
|
|
59
|
+
const createNamespace = (name2) => {
|
|
60
|
+
const prefixedName = `y-${name2}`;
|
|
61
|
+
return [prefixedName, createBEM(prefixedName), createGlobalBem()];
|
|
62
|
+
};
|
|
63
|
+
const parseUnit = (val) => {
|
|
64
|
+
if (isNaN(Number(val)) && typeof val === "string") {
|
|
65
|
+
return val;
|
|
66
|
+
}
|
|
67
|
+
return `${val}px`;
|
|
68
|
+
};
|
|
69
|
+
const parseFlexDirection = (location) => {
|
|
70
|
+
switch (location) {
|
|
29
71
|
case "top":
|
|
30
72
|
return "column-reverse";
|
|
31
73
|
case "bottom":
|
|
@@ -37,7 +79,9 @@ const G = (e) => {
|
|
|
37
79
|
default:
|
|
38
80
|
return "column";
|
|
39
81
|
}
|
|
40
|
-
}
|
|
82
|
+
};
|
|
83
|
+
const [name, bem$1] = createNamespace("loading");
|
|
84
|
+
const _props = {
|
|
41
85
|
// Loading icon 的颜色
|
|
42
86
|
color: {
|
|
43
87
|
type: String,
|
|
@@ -96,76 +140,80 @@ const G = (e) => {
|
|
|
96
140
|
type: String,
|
|
97
141
|
default: "relative"
|
|
98
142
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
143
|
+
};
|
|
144
|
+
const YLoading = /* @__PURE__ */ defineComponent({
|
|
145
|
+
name,
|
|
146
|
+
props: _props,
|
|
147
|
+
setup(props, {
|
|
148
|
+
slots
|
|
104
149
|
}) {
|
|
105
150
|
return () => {
|
|
106
|
-
var
|
|
151
|
+
var _a, _b;
|
|
107
152
|
const {
|
|
108
|
-
position
|
|
109
|
-
textLocation
|
|
110
|
-
bgColor
|
|
111
|
-
bgBorderRadius
|
|
112
|
-
size
|
|
113
|
-
padding
|
|
114
|
-
color
|
|
115
|
-
thick
|
|
116
|
-
direction
|
|
117
|
-
text
|
|
118
|
-
textColor
|
|
119
|
-
textSize
|
|
120
|
-
} =
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
153
|
+
position,
|
|
154
|
+
textLocation,
|
|
155
|
+
bgColor,
|
|
156
|
+
bgBorderRadius,
|
|
157
|
+
size,
|
|
158
|
+
padding,
|
|
159
|
+
color,
|
|
160
|
+
thick,
|
|
161
|
+
direction,
|
|
162
|
+
text,
|
|
163
|
+
textColor,
|
|
164
|
+
textSize
|
|
165
|
+
} = props;
|
|
166
|
+
const showText = ((_a = slots.default) == null ? void 0 : _a.call(slots)) || text;
|
|
167
|
+
return createVNode("div", {
|
|
168
|
+
"class": bem$1({
|
|
169
|
+
[position]: position !== "relative"
|
|
124
170
|
})
|
|
125
|
-
}, [
|
|
126
|
-
class:
|
|
127
|
-
[
|
|
171
|
+
}, [createVNode("div", {
|
|
172
|
+
"class": bem$1("bg", {
|
|
173
|
+
[position]: position !== "relative"
|
|
128
174
|
}),
|
|
129
|
-
style: {
|
|
130
|
-
flexDirection:
|
|
131
|
-
backgroundColor:
|
|
132
|
-
borderRadius:
|
|
133
|
-
padding:
|
|
175
|
+
"style": {
|
|
176
|
+
flexDirection: parseFlexDirection(textLocation),
|
|
177
|
+
backgroundColor: bgColor,
|
|
178
|
+
borderRadius: parseUnit(bgBorderRadius),
|
|
179
|
+
padding: parseUnit(padding)
|
|
134
180
|
}
|
|
135
|
-
}, [
|
|
136
|
-
class:
|
|
137
|
-
style: {
|
|
138
|
-
width:
|
|
139
|
-
height:
|
|
181
|
+
}, [createVNode("span", {
|
|
182
|
+
"class": bem$1("icon-wrapper"),
|
|
183
|
+
"style": {
|
|
184
|
+
width: parseUnit(size),
|
|
185
|
+
height: parseUnit(size)
|
|
140
186
|
}
|
|
141
|
-
}, [((
|
|
142
|
-
class:
|
|
143
|
-
[
|
|
187
|
+
}, [((_b = slots.icon) == null ? void 0 : _b.call(slots)) || createVNode("svg", {
|
|
188
|
+
"class": bem$1("icon", {
|
|
189
|
+
[direction]: direction
|
|
144
190
|
}),
|
|
145
|
-
viewBox: "25 25 50 50"
|
|
146
|
-
}, [
|
|
147
|
-
class:
|
|
148
|
-
style: {
|
|
149
|
-
stroke:
|
|
150
|
-
strokeWidth:
|
|
191
|
+
"viewBox": "25 25 50 50"
|
|
192
|
+
}, [createVNode("circle", {
|
|
193
|
+
"class": bem$1("icon-circle"),
|
|
194
|
+
"style": {
|
|
195
|
+
stroke: color,
|
|
196
|
+
strokeWidth: parseUnit(thick)
|
|
151
197
|
},
|
|
152
|
-
cx: "50",
|
|
153
|
-
cy: "50",
|
|
154
|
-
r: "20",
|
|
155
|
-
fill: "none"
|
|
156
|
-
}, null)])]),
|
|
157
|
-
class:
|
|
158
|
-
[
|
|
198
|
+
"cx": "50",
|
|
199
|
+
"cy": "50",
|
|
200
|
+
"r": "20",
|
|
201
|
+
"fill": "none"
|
|
202
|
+
}, null)])]), showText && createVNode("span", {
|
|
203
|
+
"class": bem$1("text", {
|
|
204
|
+
[textLocation]: textLocation
|
|
159
205
|
}),
|
|
160
|
-
style: {
|
|
161
|
-
color:
|
|
162
|
-
fontSize:
|
|
206
|
+
"style": {
|
|
207
|
+
color: textColor,
|
|
208
|
+
fontSize: parseUnit(textSize)
|
|
163
209
|
}
|
|
164
|
-
}, [
|
|
210
|
+
}, [showText])])]);
|
|
165
211
|
};
|
|
166
212
|
}
|
|
167
|
-
})
|
|
168
|
-
|
|
213
|
+
});
|
|
214
|
+
const [cname, bem] = createNamespace("list");
|
|
215
|
+
const List = /* @__PURE__ */ defineComponent({
|
|
216
|
+
name: cname,
|
|
169
217
|
props: {
|
|
170
218
|
// 加载中 文案
|
|
171
219
|
loadingText: {
|
|
@@ -200,7 +248,7 @@ const G = (e) => {
|
|
|
200
248
|
// 是否在初始化时立即执行滚动位置检查
|
|
201
249
|
immediateCheck: {
|
|
202
250
|
type: Boolean,
|
|
203
|
-
default:
|
|
251
|
+
default: true
|
|
204
252
|
},
|
|
205
253
|
// 滚动条与底部距离小于多少时触发加载
|
|
206
254
|
loadOffset: {
|
|
@@ -210,7 +258,7 @@ const G = (e) => {
|
|
|
210
258
|
// 是否使用虚拟列表
|
|
211
259
|
virtual: {
|
|
212
260
|
type: Boolean,
|
|
213
|
-
default:
|
|
261
|
+
default: false
|
|
214
262
|
},
|
|
215
263
|
// 缓冲区比例
|
|
216
264
|
bufferScale: {
|
|
@@ -225,160 +273,293 @@ const G = (e) => {
|
|
|
225
273
|
// 是否是不定高度子项
|
|
226
274
|
dynamicItemHeight: {
|
|
227
275
|
type: Boolean,
|
|
228
|
-
default:
|
|
276
|
+
default: false
|
|
229
277
|
}
|
|
230
278
|
},
|
|
231
279
|
emits: ["load"],
|
|
232
|
-
setup(
|
|
233
|
-
slots
|
|
234
|
-
emit
|
|
235
|
-
expose
|
|
280
|
+
setup(props, {
|
|
281
|
+
slots,
|
|
282
|
+
emit,
|
|
283
|
+
expose
|
|
236
284
|
}) {
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
285
|
+
const visibleHeightRef = ref(0);
|
|
286
|
+
const pageModeRef = ref(false);
|
|
287
|
+
const stateRef = ref("normal");
|
|
288
|
+
const listRef = ref();
|
|
289
|
+
const contentRef = ref();
|
|
290
|
+
const scrollBarRef = ref();
|
|
291
|
+
const itemsRef = ref([]);
|
|
292
|
+
const startIndexRef = ref(0);
|
|
293
|
+
const endIndexRef = ref(0);
|
|
294
|
+
const positionsRef = ref([]);
|
|
295
|
+
const listContainerRef = computed(() => {
|
|
296
|
+
return isNumber(props.height) ? `${props.height}px` : props.height;
|
|
297
|
+
});
|
|
298
|
+
const listHeightRef = computed(() => {
|
|
299
|
+
const listHeight = positionsRef.value.length ? positionsRef.value[positionsRef.value.length - 1].bottom : 0;
|
|
300
|
+
return listHeight;
|
|
301
|
+
});
|
|
302
|
+
const realRenderListRef = computed(() => {
|
|
303
|
+
if (props.virtual) {
|
|
304
|
+
const start = startIndexRef.value - aboveCountRef.value;
|
|
305
|
+
const end = endIndexRef.value + belowCountRef.value;
|
|
306
|
+
return _dataSourceRef.value.slice(start, end);
|
|
241
307
|
}
|
|
242
|
-
return
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
308
|
+
return _dataSourceRef.value;
|
|
309
|
+
});
|
|
310
|
+
const aboveCountRef = computed(() => {
|
|
311
|
+
const above = Math.min(startIndexRef.value, props.bufferScale * visibleCountRef.value);
|
|
312
|
+
return above;
|
|
313
|
+
});
|
|
314
|
+
const belowCountRef = computed(() => {
|
|
315
|
+
const below = Math.min(props.dataSource.length - endIndexRef.value, props.bufferScale * visibleCountRef.value);
|
|
316
|
+
return below;
|
|
317
|
+
});
|
|
318
|
+
const visibleCountRef = computed(() => {
|
|
319
|
+
const count = Math.ceil(visibleHeightRef.value / parseInt(String(props.itemHeight)));
|
|
320
|
+
return count;
|
|
321
|
+
});
|
|
322
|
+
const _dataSourceRef = computed(() => {
|
|
323
|
+
return props.dataSource.map((item, index) => {
|
|
324
|
+
item[props.keyName] = index;
|
|
325
|
+
return item;
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
const getScrollTop = () => {
|
|
329
|
+
if (pageModeRef.value) {
|
|
330
|
+
return document.documentElement.scrollTop || document.body.scrollTop;
|
|
331
|
+
}
|
|
332
|
+
return listRef.value.scrollTop;
|
|
333
|
+
};
|
|
334
|
+
const getScrollHeight = () => {
|
|
335
|
+
if (pageModeRef.value) {
|
|
336
|
+
return document.documentElement.scrollHeight;
|
|
337
|
+
}
|
|
338
|
+
return listRef.value.scrollHeight;
|
|
339
|
+
};
|
|
340
|
+
const loadData = () => {
|
|
341
|
+
if (stateRef.value === "loading")
|
|
342
|
+
return;
|
|
343
|
+
stateRef.value = "loading";
|
|
344
|
+
emit("load", (state) => {
|
|
345
|
+
if (stateRef.value !== "loading")
|
|
346
|
+
return;
|
|
347
|
+
switch (state) {
|
|
348
|
+
case "error":
|
|
349
|
+
stateRef.value = "error";
|
|
350
|
+
break;
|
|
351
|
+
case "finished":
|
|
352
|
+
stateRef.value = "finished";
|
|
353
|
+
if (props.virtual) {
|
|
354
|
+
initPositions();
|
|
355
|
+
}
|
|
356
|
+
if (props.virtual && props.dynamicItemHeight) {
|
|
357
|
+
updatePositions();
|
|
358
|
+
}
|
|
359
|
+
break;
|
|
360
|
+
default:
|
|
361
|
+
stateRef.value = "normal";
|
|
362
|
+
if (props.virtual) {
|
|
363
|
+
updatePositions();
|
|
364
|
+
if (props.dataSource.length < visibleCountRef.value + belowCountRef.value) {
|
|
365
|
+
loadData();
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
const checkIsScrollToBottom = () => {
|
|
372
|
+
if (stateRef.value !== "normal")
|
|
373
|
+
return;
|
|
374
|
+
if (getScrollHeight() - getScrollTop() - visibleHeightRef.value <= props.loadOffset) {
|
|
375
|
+
loadData();
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
const initPositions = () => {
|
|
379
|
+
positionsRef.value = _dataSourceRef.value.map((_, index) => {
|
|
380
|
+
const height = parseInt(String(props.itemHeight));
|
|
262
381
|
return {
|
|
263
|
-
index
|
|
264
|
-
height
|
|
265
|
-
top:
|
|
266
|
-
bottom: (
|
|
382
|
+
index,
|
|
383
|
+
height,
|
|
384
|
+
top: index * height,
|
|
385
|
+
bottom: (index + 1) * height
|
|
267
386
|
};
|
|
268
387
|
});
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
388
|
+
};
|
|
389
|
+
const updatePositions = () => {
|
|
390
|
+
initPositions();
|
|
391
|
+
for (let i = 1; i < positionsRef.value.length; i++) {
|
|
392
|
+
positionsRef.value[i].top = positionsRef.value[i - 1].bottom;
|
|
393
|
+
positionsRef.value[i].bottom = positionsRef.value[i].top + positionsRef.value[i].height;
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
const binarySearch = (list, value) => {
|
|
397
|
+
let start = 0;
|
|
398
|
+
let end = list.length - 1;
|
|
399
|
+
let tempIndex = -1;
|
|
400
|
+
while (start <= end) {
|
|
401
|
+
const midIndex = Math.floor((start + end) / 2);
|
|
402
|
+
const midValue = list[midIndex].bottom;
|
|
403
|
+
if (midValue === value) {
|
|
404
|
+
return midIndex + 1;
|
|
405
|
+
} else if (midValue < value) {
|
|
406
|
+
start = midIndex + 1;
|
|
407
|
+
} else if (midValue > value) {
|
|
408
|
+
if (tempIndex === -1 || tempIndex > midIndex) {
|
|
409
|
+
tempIndex = midIndex;
|
|
410
|
+
}
|
|
411
|
+
end = midIndex - 1;
|
|
412
|
+
}
|
|
280
413
|
}
|
|
281
|
-
return
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
414
|
+
return tempIndex;
|
|
415
|
+
};
|
|
416
|
+
const getStartIndex = (scrollTop) => {
|
|
417
|
+
return binarySearch(positionsRef.value, scrollTop);
|
|
418
|
+
};
|
|
419
|
+
const handleScroll = () => {
|
|
420
|
+
checkIsScrollToBottom();
|
|
421
|
+
if (props.virtual) {
|
|
422
|
+
const scrollTop = getScrollTop();
|
|
423
|
+
updateVisibleData(scrollTop);
|
|
286
424
|
}
|
|
287
|
-
}
|
|
288
|
-
|
|
425
|
+
};
|
|
426
|
+
const updateVisibleData = (scrollTopParam) => {
|
|
427
|
+
if (!contentRef.value)
|
|
289
428
|
return;
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
429
|
+
const scrollTop = scrollTopParam || 0;
|
|
430
|
+
if (props.dynamicItemHeight) {
|
|
431
|
+
startIndexRef.value = getStartIndex(scrollTop);
|
|
432
|
+
endIndexRef.value = startIndexRef.value + visibleCountRef.value;
|
|
433
|
+
const startOffset = positionsRef.value[startIndexRef.value - aboveCountRef.value].top ? positionsRef.value[startIndexRef.value - aboveCountRef.value].top : 0;
|
|
434
|
+
contentRef.value.style.transform = `translate3d(0, ${startOffset}px, 0)`;
|
|
295
435
|
} else {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
436
|
+
startIndexRef.value = Math.floor(scrollTop / parseInt(String(props.itemHeight)));
|
|
437
|
+
endIndexRef.value = startIndexRef.value + visibleCountRef.value;
|
|
438
|
+
const startOffset = startIndexRef.value * parseInt(String(props.itemHeight)) - aboveCountRef.value * parseInt(String(props.itemHeight));
|
|
439
|
+
contentRef.value.style.transform = `translate3d(0, ${startOffset}px, 0)`;
|
|
299
440
|
}
|
|
300
|
-
}
|
|
301
|
-
|
|
441
|
+
};
|
|
442
|
+
const updateItemSize = () => {
|
|
443
|
+
if (!contentRef.value || !scrollBarRef.value)
|
|
444
|
+
return;
|
|
445
|
+
const nodes = contentRef.value.children;
|
|
446
|
+
if (!(nodes && nodes.length > 0))
|
|
302
447
|
return;
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
const
|
|
307
|
-
height
|
|
308
|
-
} =
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
448
|
+
[...nodes].forEach((node) => {
|
|
449
|
+
if (node instanceof HTMLDivElement) {
|
|
450
|
+
const rect = node.getBoundingClientRect();
|
|
451
|
+
const {
|
|
452
|
+
height
|
|
453
|
+
} = rect;
|
|
454
|
+
const index = Number(node.dataset.index);
|
|
455
|
+
const oldHeight = positionsRef.value[index].height;
|
|
456
|
+
const dValue = oldHeight - height;
|
|
457
|
+
if (dValue) {
|
|
458
|
+
positionsRef.value[index].bottom -= dValue;
|
|
459
|
+
positionsRef.value[index].height = height;
|
|
460
|
+
for (let k = index + 1; k < positionsRef.value.length; k++) {
|
|
461
|
+
positionsRef.value[k].top = positionsRef.value[k - 1].bottom;
|
|
462
|
+
positionsRef.value[k].bottom -= dValue;
|
|
463
|
+
}
|
|
313
464
|
}
|
|
314
465
|
}
|
|
315
466
|
});
|
|
316
467
|
};
|
|
317
|
-
|
|
318
|
-
...
|
|
319
|
-
checkIsScrollToBottom
|
|
320
|
-
loadData
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
468
|
+
expose({
|
|
469
|
+
...props,
|
|
470
|
+
checkIsScrollToBottom,
|
|
471
|
+
loadData
|
|
472
|
+
});
|
|
473
|
+
onMounted(() => {
|
|
474
|
+
if (props.height !== "auto") {
|
|
475
|
+
pageModeRef.value = false;
|
|
476
|
+
visibleHeightRef.value = listRef.value.clientHeight;
|
|
477
|
+
} else if (props.height === "auto") {
|
|
478
|
+
pageModeRef.value = true;
|
|
479
|
+
visibleHeightRef.value = document.documentElement.clientHeight;
|
|
480
|
+
document.addEventListener("scroll", handleScroll);
|
|
481
|
+
}
|
|
482
|
+
if (props.virtual) {
|
|
483
|
+
initPositions();
|
|
484
|
+
updateVisibleData();
|
|
485
|
+
}
|
|
486
|
+
if (props.immediateCheck) {
|
|
487
|
+
checkIsScrollToBottom();
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
onUpdated(async () => {
|
|
491
|
+
var _a, _b;
|
|
492
|
+
if (props.virtual && props.dynamicItemHeight) {
|
|
493
|
+
await nextTick();
|
|
494
|
+
if (!((_b = (_a = contentRef.value) == null ? void 0 : _a.children) == null ? void 0 : _b.length)) {
|
|
327
495
|
return;
|
|
328
|
-
|
|
496
|
+
}
|
|
497
|
+
updateItemSize();
|
|
329
498
|
}
|
|
330
|
-
})
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
class: `${h()} ${e.virtual ? h({
|
|
335
|
-
virtual: !0
|
|
336
|
-
}) : ""}`,
|
|
337
|
-
style: {
|
|
338
|
-
height: k.value
|
|
339
|
-
},
|
|
340
|
-
onScroll: O
|
|
341
|
-
}, [e.virtual && i("div", {
|
|
342
|
-
ref: C,
|
|
343
|
-
class: h("phantom"),
|
|
344
|
-
style: {
|
|
345
|
-
height: `${w.value}px`
|
|
499
|
+
});
|
|
500
|
+
onUnmounted(() => {
|
|
501
|
+
if (pageModeRef.value) {
|
|
502
|
+
document.removeEventListener("scroll", handleScroll);
|
|
346
503
|
}
|
|
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
|
-
|
|
504
|
+
});
|
|
505
|
+
return () => {
|
|
506
|
+
return createVNode("div", {
|
|
507
|
+
"ref": listRef,
|
|
508
|
+
"class": `${bem()} ${props.virtual ? bem({
|
|
509
|
+
virtual: true
|
|
510
|
+
}) : ""}`,
|
|
511
|
+
"style": {
|
|
512
|
+
height: listContainerRef.value
|
|
513
|
+
},
|
|
514
|
+
"onScroll": handleScroll
|
|
515
|
+
}, [props.virtual && createVNode("div", {
|
|
516
|
+
"ref": scrollBarRef,
|
|
517
|
+
"class": bem("phantom"),
|
|
518
|
+
"style": {
|
|
519
|
+
height: `${listHeightRef.value}px`
|
|
520
|
+
}
|
|
521
|
+
}, null), createVNode("div", {
|
|
522
|
+
"ref": contentRef,
|
|
523
|
+
"class": bem("content")
|
|
524
|
+
}, [realRenderListRef.value.map((item) => {
|
|
525
|
+
var _a;
|
|
526
|
+
return createVNode("div", {
|
|
527
|
+
"ref": itemsRef,
|
|
528
|
+
"class": bem("item"),
|
|
529
|
+
"data-index": item._index
|
|
530
|
+
}, [(_a = slots.default) == null ? void 0 : _a.call(slots, {
|
|
531
|
+
item
|
|
532
|
+
})]);
|
|
533
|
+
})]), stateRef.value === "loading" && createVNode("div", {
|
|
534
|
+
"class": bem({
|
|
535
|
+
loading: true
|
|
536
|
+
})
|
|
537
|
+
}, [slots.loading ? slots.loading() : createVNode(YLoading, {
|
|
538
|
+
"text-location": "right"
|
|
539
|
+
}, {
|
|
540
|
+
default: () => [createTextVNode("加载中...")]
|
|
541
|
+
})]), stateRef.value === "finished" && createVNode("div", {
|
|
542
|
+
"class": bem({
|
|
543
|
+
finished: true
|
|
544
|
+
})
|
|
545
|
+
}, [props.finishedText]), stateRef.value === "error" && createVNode("div", {
|
|
546
|
+
"class": bem("error"),
|
|
547
|
+
"role": "presentation",
|
|
548
|
+
"onClick": loadData
|
|
549
|
+
}, [props.errorText])]);
|
|
550
|
+
};
|
|
376
551
|
}
|
|
377
552
|
});
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
553
|
+
const reset = "";
|
|
554
|
+
const libs = "";
|
|
555
|
+
const font = "";
|
|
556
|
+
const animation = "";
|
|
557
|
+
const theme = "";
|
|
558
|
+
const style = "";
|
|
559
|
+
List.install = (Vue) => {
|
|
560
|
+
const { name: name2 } = List;
|
|
561
|
+
Vue.component(name2, List);
|
|
381
562
|
};
|
|
382
563
|
export {
|
|
383
|
-
|
|
564
|
+
List as default
|
|
384
565
|
};
|