y-design-ssr 0.2.0 → 0.2.2
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/cell/index.css +1077 -1
- package/libs/cell/index.mjs +167 -104
- package/libs/cell/index.umd.js +300 -2
- package/libs/checkbox/index.css +1053 -1
- package/libs/checkbox/index.mjs +242 -127
- package/libs/checkbox/index.umd.js +369 -2
- package/libs/checkboxGroup/index.css +422 -1
- package/libs/checkboxGroup/index.mjs +173 -87
- package/libs/checkboxGroup/index.umd.js +265 -2
- package/libs/col/index.css +615 -1
- package/libs/col/index.mjs +246 -81
- package/libs/col/index.umd.js +305 -2
- package/libs/countdown/index.css +417 -1
- package/libs/countdown/index.mjs +179 -71
- package/libs/countdown/index.umd.js +231 -2
- package/libs/dialog/index.css +1405 -1
- package/libs/dialog/index.mjs +646 -476
- package/libs/dialog/index.umd.js +1128 -2
- package/libs/empty/index.css +457 -1
- package/libs/empty/index.mjs +91 -44
- package/libs/empty/index.umd.js +139 -2
- package/libs/form/index.css +477 -1
- package/libs/form/index.mjs +226 -126
- package/libs/form/index.umd.js +319 -2
- package/libs/formItem/index.css +477 -1
- package/libs/formItem/index.mjs +276 -126
- package/libs/formItem/index.umd.js +372 -2
- package/libs/icon/index.css +982 -1
- package/libs/icon/index.mjs +107 -58
- package/libs/icon/index.umd.js +186 -2
- 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/layout/index.css +684 -1
- package/libs/layout/index.mjs +230 -130
- package/libs/layout/index.umd.js +318 -2
- package/libs/list/index.css +440 -1
- package/libs/list/index.mjs +388 -207
- package/libs/list/index.umd.js +571 -2
- package/libs/loading/index.css +548 -1
- package/libs/loading/index.mjs +196 -118
- package/libs/loading/index.umd.js +321 -2
- package/libs/mask/index.css +426 -1
- package/libs/mask/index.mjs +131 -70
- package/libs/mask/index.umd.js +201 -2
- package/libs/popup/index.css +465 -1
- package/libs/popup/index.mjs +210 -134
- package/libs/popup/index.umd.js +358 -2
- package/libs/progress/index.css +488 -1
- package/libs/progress/index.mjs +200 -128
- package/libs/progress/index.umd.js +322 -2
- package/libs/pullrefresh/index.css +441 -1
- package/libs/pullrefresh/index.mjs +241 -111
- package/libs/pullrefresh/index.umd.js +302 -2
- package/libs/row/index.css +485 -1
- package/libs/row/index.mjs +181 -89
- package/libs/row/index.umd.js +237 -2
- package/libs/slider/index.css +558 -1
- package/libs/slider/index.mjs +356 -160
- package/libs/slider/index.umd.js +453 -2
- package/libs/stepper/index.css +489 -1
- package/libs/stepper/index.mjs +181 -101
- package/libs/stepper/index.umd.js +269 -2
- package/libs/swipe/index.css +506 -1
- package/libs/swipe/index.mjs +542 -259
- package/libs/swipe/index.umd.js +703 -2
- package/libs/swipeItem/index.css +424 -1
- package/libs/swipeItem/index.mjs +111 -52
- package/libs/swipeItem/index.umd.js +154 -2
- package/libs/switch/index.css +472 -1
- package/libs/switch/index.mjs +121 -62
- package/libs/switch/index.umd.js +200 -2
- package/libs/tab/index.mjs +131 -68
- package/libs/tab/index.umd.js +190 -1
- package/libs/tabs/index.css +514 -1
- package/libs/tabs/index.mjs +751 -410
- package/libs/tabs/index.umd.js +1020 -2
- package/libs/toast/index.css +1050 -1
- package/libs/toast/index.mjs +183 -114
- package/libs/toast/index.umd.js +306 -2
- package/libs/tooltip/index.css +514 -1
- package/libs/tooltip/index.mjs +293 -155
- package/libs/tooltip/index.umd.js +416 -2
- package/package.json +5 -4
- package/libs/button/package.json +0 -5
- package/libs/cell/package.json +0 -5
- package/libs/checkbox/package.json +0 -5
- package/libs/checkboxGroup/package.json +0 -5
- package/libs/col/package.json +0 -5
- package/libs/countdown/package.json +0 -5
- package/libs/dialog/package.json +0 -5
- package/libs/empty/package.json +0 -5
- package/libs/form/package.json +0 -5
- package/libs/formItem/package.json +0 -5
- package/libs/icon/package.json +0 -5
- package/libs/input/package.json +0 -5
- package/libs/layout/package.json +0 -5
- package/libs/list/package.json +0 -5
- package/libs/loading/package.json +0 -5
- package/libs/mask/package.json +0 -5
- package/libs/popup/package.json +0 -5
- package/libs/progress/package.json +0 -5
- package/libs/pullrefresh/package.json +0 -5
- package/libs/row/package.json +0 -5
- package/libs/slider/package.json +0 -5
- package/libs/stepper/package.json +0 -5
- package/libs/swipe/package.json +0 -5
- package/libs/swipeItem/package.json +0 -5
- package/libs/switch/package.json +0 -5
- package/libs/tab/package.json +0 -5
- package/libs/tabs/package.json +0 -5
- package/libs/toast/package.json +0 -5
- package/libs/tooltip/package.json +0 -5
package/libs/tabs/index.mjs
CHANGED
|
@@ -1,11 +1,40 @@
|
|
|
1
|
-
import { ref
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
1
|
+
import { ref, reactive, getCurrentInstance, provide, isVNode, inject, onUnmounted, computed, defineComponent, createVNode, watch, onMounted, nextTick, onBeforeUnmount, onBeforeUpdate } from "vue";
|
|
2
|
+
const getMods = (el, mods) => {
|
|
3
|
+
if (!mods) {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
if (typeof mods === "string") {
|
|
7
|
+
return ` ${el}--${mods}`;
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(mods)) {
|
|
10
|
+
return mods.reduce((acc, cur) => acc + getMods(el, cur), "");
|
|
11
|
+
}
|
|
12
|
+
return Object.keys(mods).reduce(
|
|
13
|
+
(acc, cur) => acc + (mods[cur] ? getMods(el, cur) : ""),
|
|
14
|
+
""
|
|
15
|
+
);
|
|
16
|
+
};
|
|
17
|
+
const createBEM = (block) => {
|
|
18
|
+
return (el, mods) => {
|
|
19
|
+
let _el = el;
|
|
20
|
+
let _mods = mods;
|
|
21
|
+
if (_el && typeof _el !== "string") {
|
|
22
|
+
_mods = _el;
|
|
23
|
+
_el = "";
|
|
24
|
+
}
|
|
25
|
+
_el = _el ? `${block}__${_el}` : block;
|
|
26
|
+
return `${_el}${getMods(_el, _mods)}`;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const createGlobalBem = () => {
|
|
30
|
+
return (el, mods) => {
|
|
31
|
+
if (!mods) {
|
|
32
|
+
return `y-${el}`;
|
|
33
|
+
}
|
|
34
|
+
return `${getMods(`y-${el}`, mods)}`;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const defaultLang = {
|
|
9
38
|
"pull-refresh": {
|
|
10
39
|
pulling: "下拉刷新...",
|
|
11
40
|
loosing: "释放刷新...",
|
|
@@ -17,57 +46,94 @@ const V = (e, n) => n ? typeof n == "string" ? ` ${e}--${n}` : Array.isArray(n)
|
|
|
17
46
|
validateMessage: "请输入正确内容"
|
|
18
47
|
}
|
|
19
48
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"zh-CN":
|
|
49
|
+
ref("zh-CN");
|
|
50
|
+
reactive({
|
|
51
|
+
"zh-CN": defaultLang
|
|
23
52
|
});
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
return [
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
53
|
+
const createNamespace = (name2) => {
|
|
54
|
+
const prefixedName = `y-${name2}`;
|
|
55
|
+
return [prefixedName, createBEM(prefixedName), createGlobalBem()];
|
|
56
|
+
};
|
|
57
|
+
const parsePercent = (val, baseNumber) => {
|
|
58
|
+
if (typeof val === "string" && val.includes("%")) {
|
|
59
|
+
if (!val.includes("%"))
|
|
60
|
+
return Number(val);
|
|
61
|
+
return baseNumber * Number(val.replace(/%/g, "")) / 100;
|
|
62
|
+
}
|
|
63
|
+
return Number(val);
|
|
64
|
+
};
|
|
65
|
+
const filterChildren = (children) => {
|
|
66
|
+
const vnodes = [];
|
|
67
|
+
const _filterChildren = (childrens) => {
|
|
68
|
+
if (Array.isArray(childrens)) {
|
|
69
|
+
childrens.forEach((child) => {
|
|
70
|
+
var _a;
|
|
71
|
+
if (isVNode(child)) {
|
|
72
|
+
vnodes.push(child);
|
|
73
|
+
if ((_a = child.component) == null ? void 0 : _a.subTree) {
|
|
74
|
+
_filterChildren(child.component.subTree.children);
|
|
75
|
+
}
|
|
76
|
+
if (child.children) {
|
|
77
|
+
_filterChildren(child.children);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
_filterChildren(children);
|
|
84
|
+
return vnodes;
|
|
85
|
+
};
|
|
86
|
+
const sortChildren = (childrens, instance) => {
|
|
87
|
+
const vnodes = filterChildren(instance.subTree.children);
|
|
88
|
+
childrens.sort((a, b) => vnodes.indexOf(a.vnode) - vnodes.indexOf(b.vnode));
|
|
89
|
+
};
|
|
90
|
+
const setRelation = (key) => {
|
|
91
|
+
const instance = getCurrentInstance();
|
|
92
|
+
const childrens = reactive([]);
|
|
93
|
+
const initProvide = (value) => {
|
|
94
|
+
const addChild = (child) => {
|
|
95
|
+
if (child.proxy) {
|
|
96
|
+
childrens.push(child);
|
|
97
|
+
instance && sortChildren(childrens, instance);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const removeChild = (child) => {
|
|
101
|
+
const index = childrens.indexOf(child);
|
|
102
|
+
childrens.splice(index, 1);
|
|
103
|
+
};
|
|
104
|
+
provide(key, {
|
|
105
|
+
addChild,
|
|
106
|
+
removeChild,
|
|
107
|
+
childrens,
|
|
108
|
+
...value
|
|
32
109
|
});
|
|
33
110
|
};
|
|
34
|
-
return o(e), n;
|
|
35
|
-
}, Ie = (e, n) => {
|
|
36
|
-
const o = xe(n.subTree.children);
|
|
37
|
-
e.sort((l, v) => o.indexOf(l.vnode) - o.indexOf(v.vnode));
|
|
38
|
-
}, ue = (e) => {
|
|
39
|
-
const n = ie(), o = N([]);
|
|
40
111
|
return {
|
|
41
|
-
childrens
|
|
42
|
-
initProvide
|
|
43
|
-
Se(e, {
|
|
44
|
-
addChild: (s) => {
|
|
45
|
-
s.proxy && (o.push(s), n && Ie(o, n));
|
|
46
|
-
},
|
|
47
|
-
removeChild: (s) => {
|
|
48
|
-
const f = o.indexOf(s);
|
|
49
|
-
o.splice(f, 1);
|
|
50
|
-
},
|
|
51
|
-
childrens: o,
|
|
52
|
-
...v
|
|
53
|
-
});
|
|
54
|
-
}
|
|
112
|
+
childrens,
|
|
113
|
+
initProvide
|
|
55
114
|
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
115
|
+
};
|
|
116
|
+
const useRelation = (key) => {
|
|
117
|
+
const parent = inject(key, null);
|
|
118
|
+
const currentInstance = getCurrentInstance();
|
|
119
|
+
if (parent && currentInstance) {
|
|
120
|
+
const { childrens, addChild, removeChild } = parent;
|
|
121
|
+
addChild(currentInstance);
|
|
122
|
+
onUnmounted(() => removeChild(currentInstance));
|
|
123
|
+
const index = computed(() => childrens.indexOf(currentInstance));
|
|
124
|
+
return {
|
|
125
|
+
index,
|
|
126
|
+
parent
|
|
63
127
|
};
|
|
64
128
|
}
|
|
65
129
|
return {
|
|
66
130
|
parent: null,
|
|
67
|
-
index:
|
|
131
|
+
index: ref(-1)
|
|
68
132
|
};
|
|
69
|
-
}
|
|
70
|
-
|
|
133
|
+
};
|
|
134
|
+
const [name$3, bem$3] = createNamespace("swipe-item");
|
|
135
|
+
const YSwipeItem = /* @__PURE__ */ defineComponent({
|
|
136
|
+
name: name$3,
|
|
71
137
|
props: {
|
|
72
138
|
clonenNode: {
|
|
73
139
|
type: Object,
|
|
@@ -78,39 +144,66 @@ const U = (e) => {
|
|
|
78
144
|
default: -1
|
|
79
145
|
}
|
|
80
146
|
},
|
|
81
|
-
setup(
|
|
82
|
-
slots
|
|
147
|
+
setup(props, {
|
|
148
|
+
slots
|
|
83
149
|
}) {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
150
|
+
const instance = getCurrentInstance();
|
|
151
|
+
const {
|
|
152
|
+
parent
|
|
153
|
+
} = useRelation(SWIPE_PROVIDE_KEY);
|
|
154
|
+
if (!props.clonenNode && instance) {
|
|
155
|
+
parent == null ? void 0 : parent.children.push(instance);
|
|
156
|
+
}
|
|
157
|
+
const index = computed(() => {
|
|
158
|
+
if (props.clonenNode) {
|
|
159
|
+
return props.index;
|
|
160
|
+
}
|
|
161
|
+
return parent == null ? void 0 : parent.children.findIndex((item) => item.proxy === (instance == null ? void 0 : instance.proxy));
|
|
162
|
+
});
|
|
163
|
+
const style2 = computed(() => {
|
|
164
|
+
const width = `${(parent == null ? void 0 : parent.itemDetail.size) || 0}px`;
|
|
165
|
+
let height = "auto";
|
|
166
|
+
const spacing = `${(parent == null ? void 0 : parent.itemDetail.space) || 0}px`;
|
|
167
|
+
if ((parent == null ? void 0 : parent.props.autoHeight) && (parent == null ? void 0 : parent.activeIndex) !== index.value) {
|
|
168
|
+
height = "0";
|
|
169
|
+
}
|
|
170
|
+
if (parent == null ? void 0 : parent.props.vertical) {
|
|
171
|
+
return {
|
|
172
|
+
height: width,
|
|
173
|
+
width: height,
|
|
174
|
+
marginBottom: spacing
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
width,
|
|
179
|
+
height,
|
|
180
|
+
marginRight: spacing
|
|
100
181
|
};
|
|
101
182
|
});
|
|
102
183
|
return () => {
|
|
103
|
-
var
|
|
104
|
-
const
|
|
105
|
-
return
|
|
106
|
-
class:
|
|
107
|
-
style:
|
|
108
|
-
}, [
|
|
184
|
+
var _a, _b;
|
|
185
|
+
const isShow = ((_a = parent == null ? void 0 : parent.itemShowedList) == null ? void 0 : _a.list[index.value || 0]) || false;
|
|
186
|
+
return createVNode("div", {
|
|
187
|
+
"class": bem$3(),
|
|
188
|
+
"style": style2.value
|
|
189
|
+
}, [isShow ? props.clonenNode || ((_b = slots.default) == null ? void 0 : _b.call(slots)) : null]);
|
|
109
190
|
};
|
|
110
191
|
}
|
|
111
192
|
});
|
|
112
|
-
var
|
|
113
|
-
|
|
193
|
+
var Position = /* @__PURE__ */ ((Position2) => {
|
|
194
|
+
Position2["left"] = "left";
|
|
195
|
+
Position2["top"] = "top";
|
|
196
|
+
Position2["bottom"] = "bottom";
|
|
197
|
+
Position2["right"] = "right";
|
|
198
|
+
return Position2;
|
|
199
|
+
})(Position || {});
|
|
200
|
+
var Align = /* @__PURE__ */ ((Align2) => {
|
|
201
|
+
Align2["start"] = "start";
|
|
202
|
+
Align2["center"] = "center";
|
|
203
|
+
Align2["end"] = "end";
|
|
204
|
+
return Align2;
|
|
205
|
+
})(Align || {});
|
|
206
|
+
const swipeProps = {
|
|
114
207
|
autoplayTime: {
|
|
115
208
|
type: Number,
|
|
116
209
|
default: 0
|
|
@@ -125,11 +218,11 @@ const ke = {
|
|
|
125
218
|
},
|
|
126
219
|
loop: {
|
|
127
220
|
type: Boolean,
|
|
128
|
-
default:
|
|
221
|
+
default: true
|
|
129
222
|
},
|
|
130
223
|
dots: {
|
|
131
224
|
type: Boolean,
|
|
132
|
-
default:
|
|
225
|
+
default: true
|
|
133
226
|
},
|
|
134
227
|
dotsPosition: {
|
|
135
228
|
type: String,
|
|
@@ -141,15 +234,15 @@ const ke = {
|
|
|
141
234
|
},
|
|
142
235
|
lazy: {
|
|
143
236
|
type: Boolean,
|
|
144
|
-
default:
|
|
237
|
+
default: false
|
|
145
238
|
},
|
|
146
239
|
vertical: {
|
|
147
240
|
type: Boolean,
|
|
148
|
-
default:
|
|
241
|
+
default: false
|
|
149
242
|
},
|
|
150
243
|
autoHeight: {
|
|
151
244
|
type: Boolean,
|
|
152
|
-
default:
|
|
245
|
+
default: false
|
|
153
246
|
},
|
|
154
247
|
itemSize: {
|
|
155
248
|
type: [Number, String],
|
|
@@ -165,144 +258,253 @@ const ke = {
|
|
|
165
258
|
},
|
|
166
259
|
touchable: {
|
|
167
260
|
type: Boolean,
|
|
168
|
-
default:
|
|
261
|
+
default: true
|
|
169
262
|
},
|
|
170
263
|
isFollowHand: {
|
|
171
264
|
type: Boolean,
|
|
172
|
-
default:
|
|
265
|
+
default: true
|
|
173
266
|
},
|
|
174
267
|
align: {
|
|
175
268
|
type: String,
|
|
176
269
|
default: "center"
|
|
177
270
|
}
|
|
178
|
-
}
|
|
179
|
-
|
|
271
|
+
};
|
|
272
|
+
const [name$2, bem$2] = createNamespace("swipe");
|
|
273
|
+
const SWIPE_PROVIDE_KEY = name$2;
|
|
274
|
+
const Swipe = /* @__PURE__ */ defineComponent({
|
|
275
|
+
name: name$2,
|
|
180
276
|
components: {
|
|
181
|
-
YSwipeItem
|
|
277
|
+
YSwipeItem
|
|
182
278
|
},
|
|
183
|
-
props:
|
|
184
|
-
setup(
|
|
185
|
-
slots
|
|
186
|
-
emit
|
|
187
|
-
expose
|
|
279
|
+
props: swipeProps,
|
|
280
|
+
setup(props, {
|
|
281
|
+
slots,
|
|
282
|
+
emit,
|
|
283
|
+
expose
|
|
188
284
|
}) {
|
|
189
285
|
const {
|
|
190
|
-
initProvide
|
|
191
|
-
} =
|
|
286
|
+
initProvide
|
|
287
|
+
} = setRelation(SWIPE_PROVIDE_KEY);
|
|
288
|
+
const itemList = reactive([]);
|
|
289
|
+
const activeIndex = ref(Number(props.initIndex));
|
|
290
|
+
const itemDetail = reactive({
|
|
192
291
|
// 元素尺寸
|
|
193
292
|
size: 0,
|
|
194
293
|
// 间距
|
|
195
294
|
space: 0,
|
|
196
295
|
// 元素宽度比swipe小,占满整个视窗
|
|
197
|
-
isFillViewport:
|
|
198
|
-
})
|
|
296
|
+
isFillViewport: false
|
|
297
|
+
});
|
|
298
|
+
const trackDetail = reactive({
|
|
199
299
|
// 偏移量
|
|
200
300
|
offset: 0,
|
|
201
301
|
// 视窗大小
|
|
202
302
|
viewportSize: 0,
|
|
203
303
|
// 重复节点个数
|
|
204
304
|
cloneNodeCount: 0
|
|
205
|
-
})
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
305
|
+
});
|
|
306
|
+
const swipeRef = ref();
|
|
307
|
+
const swipeTrackRef = ref();
|
|
308
|
+
const getBooleanList = () => {
|
|
309
|
+
const l = itemList.length;
|
|
310
|
+
const result = [];
|
|
311
|
+
for (let i = 0; i < l; i++) {
|
|
312
|
+
result.push(!props.lazy);
|
|
313
|
+
}
|
|
314
|
+
return result;
|
|
315
|
+
};
|
|
316
|
+
const checkItemShowed = () => {
|
|
317
|
+
if (!props.lazy)
|
|
212
318
|
return;
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
319
|
+
const itemSizeSpace = itemDetail.size + itemDetail.space;
|
|
320
|
+
const trackSize = itemList.length * itemSizeSpace;
|
|
321
|
+
let viewportLeft = -(trackDetail.offset + dragDetail.offset) - trackDetail.cloneNodeCount * itemSizeSpace;
|
|
322
|
+
if (viewportLeft < 0) {
|
|
323
|
+
viewportLeft += trackSize;
|
|
324
|
+
}
|
|
325
|
+
const viewportRight = viewportLeft + trackDetail.viewportSize;
|
|
326
|
+
for (let i = 0; i < itemList.length; i++) {
|
|
327
|
+
if (!itemShowedList.list[i]) {
|
|
328
|
+
const left = itemSizeSpace * i;
|
|
329
|
+
const right = left + itemDetail.size;
|
|
330
|
+
if (left >= viewportLeft && left < viewportRight || right > viewportLeft && right < viewportRight || left < viewportLeft && right > viewportRight) {
|
|
331
|
+
itemShowedList.list[i] = true;
|
|
332
|
+
}
|
|
221
333
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
const itemShowedList = reactive({
|
|
337
|
+
list: getBooleanList()
|
|
338
|
+
});
|
|
339
|
+
const initItemShowList = () => {
|
|
340
|
+
itemShowedList.list = getBooleanList();
|
|
341
|
+
checkItemShowed();
|
|
342
|
+
};
|
|
343
|
+
watch(() => [...itemList], initItemShowList);
|
|
344
|
+
const setItemSize = (itemSize, viewportSize) => {
|
|
345
|
+
if (itemSize) {
|
|
346
|
+
itemDetail.size = parsePercent(itemSize, viewportSize);
|
|
347
|
+
} else {
|
|
348
|
+
itemDetail.size = viewportSize;
|
|
349
|
+
}
|
|
350
|
+
itemDetail.space = Number(props.itemSpace) || 0;
|
|
351
|
+
itemDetail.isFillViewport = itemDetail.size >= viewportSize;
|
|
352
|
+
trackDetail.viewportSize = viewportSize;
|
|
353
|
+
trackDetail.cloneNodeCount = getCloneNodeCount();
|
|
354
|
+
};
|
|
355
|
+
const getCloneNodeCount = () => {
|
|
356
|
+
if (needLoop.value) {
|
|
357
|
+
const sizeSpace = itemDetail.size + itemDetail.space;
|
|
358
|
+
if (sizeSpace === 0)
|
|
234
359
|
return 0;
|
|
235
|
-
const
|
|
236
|
-
|
|
360
|
+
const freeSize = trackDetail.viewportSize * 2 - sizeSpace;
|
|
361
|
+
const count = Math.ceil(freeSize / sizeSpace);
|
|
362
|
+
return Math.min(count, itemList.length - 1);
|
|
237
363
|
}
|
|
238
364
|
return 0;
|
|
239
|
-
}
|
|
240
|
-
|
|
365
|
+
};
|
|
366
|
+
const resize = () => {
|
|
367
|
+
if (!swipeRef.value)
|
|
241
368
|
return;
|
|
242
369
|
const {
|
|
243
|
-
width
|
|
244
|
-
height
|
|
245
|
-
} =
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}), e.touchable && T.value) {
|
|
251
|
-
const t = T.value;
|
|
252
|
-
t.addEventListener("touchstart", M, !1), t.addEventListener("mousedown", M, !1), t.addEventListener("touchmove", P, !1), t.addEventListener("mousemove", P, !1), t.addEventListener("touchend", $, !1), t.addEventListener("mouseup", $, !1), t.addEventListener("mouseleave", $, !1), t.addEventListener("touchcancel", $, !1);
|
|
370
|
+
width,
|
|
371
|
+
height
|
|
372
|
+
} = swipeRef.value.getBoundingClientRect();
|
|
373
|
+
if (props.vertical) {
|
|
374
|
+
setItemSize(props.itemSize, height);
|
|
375
|
+
} else {
|
|
376
|
+
setItemSize(props.itemSize, width);
|
|
253
377
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const t = T.value;
|
|
258
|
-
t.removeEventListener("touchstart", M, !1), t.removeEventListener("mousedown", M, !1), t.removeEventListener("mousemove", P, !1), t.removeEventListener("touchmove", P, !1), t.removeEventListener("mouseup", $, !1), t.removeEventListener("touchend", $, !1), t.removeEventListener("mouseleave", $, !1), t.removeEventListener("touchcancel", $, !1);
|
|
378
|
+
activeIndex.value = activeIndex.value >= itemList.length ? itemList.length - 1 : activeIndex.value;
|
|
379
|
+
if (activeIndex.value < 0) {
|
|
380
|
+
activeIndex.value = 0;
|
|
259
381
|
}
|
|
260
|
-
|
|
382
|
+
updateTransform(activeIndex.value);
|
|
383
|
+
initItemShowList();
|
|
384
|
+
startAutoplay();
|
|
385
|
+
};
|
|
386
|
+
onMounted(() => {
|
|
387
|
+
nextTick(resize).catch(() => {
|
|
388
|
+
});
|
|
389
|
+
if (props.touchable && swipeRef.value) {
|
|
390
|
+
const swipeEl = swipeRef.value;
|
|
391
|
+
swipeEl.addEventListener("touchstart", onTouchStart, false);
|
|
392
|
+
swipeEl.addEventListener("mousedown", onTouchStart, false);
|
|
393
|
+
swipeEl.addEventListener("touchmove", onTouch, false);
|
|
394
|
+
swipeEl.addEventListener("mousemove", onTouch, false);
|
|
395
|
+
swipeEl.addEventListener("touchend", onTouchEnd, false);
|
|
396
|
+
swipeEl.addEventListener("mouseup", onTouchEnd, false);
|
|
397
|
+
swipeEl.addEventListener("mouseleave", onTouchEnd, false);
|
|
398
|
+
swipeEl.addEventListener("touchcancel", onTouchEnd, false);
|
|
399
|
+
}
|
|
400
|
+
window.addEventListener("resize", resize, false);
|
|
401
|
+
window.addEventListener("orientationchange", resize, false);
|
|
261
402
|
});
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
403
|
+
onBeforeUnmount(() => {
|
|
404
|
+
stopAutoPlay();
|
|
405
|
+
if (props.touchable && swipeRef.value) {
|
|
406
|
+
const swipeEl = swipeRef.value;
|
|
407
|
+
swipeEl.removeEventListener("touchstart", onTouchStart, false);
|
|
408
|
+
swipeEl.removeEventListener("mousedown", onTouchStart, false);
|
|
409
|
+
swipeEl.removeEventListener("mousemove", onTouch, false);
|
|
410
|
+
swipeEl.removeEventListener("touchmove", onTouch, false);
|
|
411
|
+
swipeEl.removeEventListener("mouseup", onTouchEnd, false);
|
|
412
|
+
swipeEl.removeEventListener("touchend", onTouchEnd, false);
|
|
413
|
+
swipeEl.removeEventListener("mouseleave", onTouchEnd, false);
|
|
414
|
+
swipeEl.removeEventListener("touchcancel", onTouchEnd, false);
|
|
415
|
+
}
|
|
416
|
+
window.removeEventListener("resize", resize, false);
|
|
417
|
+
window.removeEventListener("orientationchange", resize, false);
|
|
418
|
+
});
|
|
419
|
+
const positionOffset = computed(() => {
|
|
420
|
+
let offset = 0;
|
|
421
|
+
switch (props.align) {
|
|
422
|
+
case Align.start:
|
|
423
|
+
offset = 0;
|
|
267
424
|
break;
|
|
268
|
-
case
|
|
269
|
-
|
|
425
|
+
case Align.center:
|
|
426
|
+
offset = (trackDetail.viewportSize - itemDetail.size) / 2;
|
|
270
427
|
break;
|
|
271
|
-
case
|
|
272
|
-
|
|
428
|
+
case Align.end:
|
|
429
|
+
offset = trackDetail.viewportSize - itemDetail.size;
|
|
273
430
|
break;
|
|
274
431
|
default:
|
|
275
|
-
|
|
432
|
+
offset = 0;
|
|
433
|
+
}
|
|
434
|
+
return offset;
|
|
435
|
+
});
|
|
436
|
+
const needLoop = computed(() => {
|
|
437
|
+
return props.loop && itemList.length > 1;
|
|
438
|
+
});
|
|
439
|
+
const updateTransform = (index) => {
|
|
440
|
+
const itemSizeSpace = itemDetail.size + itemDetail.space;
|
|
441
|
+
if (needLoop.value) {
|
|
442
|
+
trackDetail.offset = -itemSizeSpace * (index + trackDetail.cloneNodeCount) + positionOffset.value;
|
|
443
|
+
} else {
|
|
444
|
+
trackDetail.offset = -itemSizeSpace * index + positionOffset.value;
|
|
445
|
+
if (props.align !== "center") {
|
|
446
|
+
if (index === 0) {
|
|
447
|
+
trackDetail.offset = 0;
|
|
448
|
+
}
|
|
449
|
+
if (index === itemList.length - 1) {
|
|
450
|
+
trackDetail.offset = -itemSizeSpace * index + trackDetail.viewportSize - itemDetail.size;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
const afterChange = () => {
|
|
456
|
+
updateTransform(activeIndex.value);
|
|
457
|
+
emit("afterChange", activeIndex.value);
|
|
458
|
+
};
|
|
459
|
+
const getIndex = (index) => {
|
|
460
|
+
return (itemList.length + index) % itemList.length;
|
|
461
|
+
};
|
|
462
|
+
const moveTo = (index, withAnimation = true) => {
|
|
463
|
+
activeIndex.value = getIndex(index);
|
|
464
|
+
updateTransform(index);
|
|
465
|
+
checkItemShowed();
|
|
466
|
+
emit("change", activeIndex.value);
|
|
467
|
+
if (withAnimation) {
|
|
468
|
+
dragDetail.transitionEnabled = true;
|
|
469
|
+
if (swipeTrackRef.value) {
|
|
470
|
+
swipeTrackRef.value.addEventListener("transitionend", () => {
|
|
471
|
+
dragDetail.transitionEnabled = false;
|
|
472
|
+
afterChange();
|
|
473
|
+
}, {
|
|
474
|
+
once: true
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
} else {
|
|
478
|
+
afterChange();
|
|
276
479
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}, r = N({
|
|
480
|
+
};
|
|
481
|
+
const prev = (withAnimation = true) => {
|
|
482
|
+
moveTo(activeIndex.value - 1, withAnimation);
|
|
483
|
+
};
|
|
484
|
+
const next = (withAnimation = true) => {
|
|
485
|
+
moveTo(activeIndex.value + 1, withAnimation);
|
|
486
|
+
};
|
|
487
|
+
let timer = null;
|
|
488
|
+
const stopAutoPlay = () => {
|
|
489
|
+
if (props.autoplayTime && timer) {
|
|
490
|
+
clearInterval(timer);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
const startAutoplay = () => {
|
|
494
|
+
if (props.autoplayTime && itemList.length > 1) {
|
|
495
|
+
if (timer) {
|
|
496
|
+
clearInterval(timer);
|
|
497
|
+
}
|
|
498
|
+
timer = setInterval(() => {
|
|
499
|
+
next();
|
|
500
|
+
}, Number(props.autoplayTime));
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
const dragDetail = reactive({
|
|
302
504
|
// 拖拽中
|
|
303
|
-
isDragging:
|
|
505
|
+
isDragging: false,
|
|
304
506
|
// 是否首次拖动
|
|
305
|
-
isFirstTouch:
|
|
507
|
+
isFirstTouch: true,
|
|
306
508
|
// 拖拽起始位置X
|
|
307
509
|
startX: 0,
|
|
308
510
|
// 拖拽起始位置Y
|
|
@@ -312,105 +514,182 @@ const ke = {
|
|
|
312
514
|
// 开始拖动时间
|
|
313
515
|
startTime: /* @__PURE__ */ new Date(),
|
|
314
516
|
// 是否在执行动画
|
|
315
|
-
transitionEnabled:
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
let a = 0, m = 0;
|
|
320
|
-
"touches" in t ? (a = t.touches[0].clientX, m = t.touches[0].clientY) : (a = t.clientX, m = t.clientY), r.startX = a, r.startY = m, r.isDragging = !0, r.isFirstTouch = !0, r.startTime = /* @__PURE__ */ new Date();
|
|
321
|
-
}, P = (t) => {
|
|
322
|
-
if (!r.isDragging)
|
|
517
|
+
transitionEnabled: false
|
|
518
|
+
});
|
|
519
|
+
const onTouchStart = (e) => {
|
|
520
|
+
if (dragDetail.transitionEnabled) {
|
|
323
521
|
return;
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (
|
|
328
|
-
|
|
522
|
+
}
|
|
523
|
+
let clientX = 0;
|
|
524
|
+
let clientY = 0;
|
|
525
|
+
if ("touches" in e) {
|
|
526
|
+
clientX = e.touches[0].clientX;
|
|
527
|
+
clientY = e.touches[0].clientY;
|
|
528
|
+
} else {
|
|
529
|
+
clientX = e.clientX;
|
|
530
|
+
clientY = e.clientY;
|
|
531
|
+
}
|
|
532
|
+
dragDetail.startX = clientX;
|
|
533
|
+
dragDetail.startY = clientY;
|
|
534
|
+
dragDetail.isDragging = true;
|
|
535
|
+
dragDetail.isFirstTouch = true;
|
|
536
|
+
dragDetail.startTime = /* @__PURE__ */ new Date();
|
|
537
|
+
};
|
|
538
|
+
const onTouch = (e) => {
|
|
539
|
+
if (!dragDetail.isDragging) {
|
|
329
540
|
return;
|
|
330
541
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
542
|
+
let clientX = 0;
|
|
543
|
+
let clientY = 0;
|
|
544
|
+
if ("touches" in e) {
|
|
545
|
+
clientX = e.touches[0].clientX;
|
|
546
|
+
clientY = e.touches[0].clientY;
|
|
547
|
+
} else {
|
|
548
|
+
clientX = e.clientX;
|
|
549
|
+
clientY = e.clientY;
|
|
550
|
+
}
|
|
551
|
+
const offsetX = clientX - dragDetail.startX;
|
|
552
|
+
const offsetY = clientY - dragDetail.startY;
|
|
553
|
+
if (dragDetail.isFirstTouch) {
|
|
554
|
+
dragDetail.isFirstTouch = false;
|
|
555
|
+
const isVerticalTouch = Math.abs(offsetX) < Math.abs(offsetY);
|
|
556
|
+
if (isVerticalTouch !== props.vertical) {
|
|
557
|
+
dragDetail.isDragging = false;
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
e.preventDefault();
|
|
562
|
+
dragDetail.offset = props.vertical ? offsetY : offsetX;
|
|
563
|
+
checkItemShowed();
|
|
564
|
+
emit("dragging", {
|
|
565
|
+
percent: dragDetail.offset / (itemDetail.size + itemDetail.space),
|
|
566
|
+
offset: dragDetail.offset
|
|
334
567
|
});
|
|
335
|
-
}
|
|
336
|
-
|
|
568
|
+
};
|
|
569
|
+
const onTouchEnd = () => {
|
|
570
|
+
if (!dragDetail.isDragging) {
|
|
337
571
|
return;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
if (
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
572
|
+
}
|
|
573
|
+
dragDetail.isDragging = false;
|
|
574
|
+
const now = /* @__PURE__ */ new Date();
|
|
575
|
+
const dragTime = now.getTime() - dragDetail.startTime.getTime();
|
|
576
|
+
if (canGoForward() && (Math.abs(dragDetail.offset) > minSwipeDistance.value || Math.abs(dragDetail.offset) / dragTime > 0.5)) {
|
|
577
|
+
dragDetail.offset > 0 ? prev() : next();
|
|
578
|
+
dragDetail.offset = 0;
|
|
579
|
+
} else {
|
|
580
|
+
dragDetail.offset = 0;
|
|
581
|
+
}
|
|
582
|
+
startAutoplay();
|
|
583
|
+
};
|
|
584
|
+
const minSwipeDistance = computed(() => {
|
|
585
|
+
return parsePercent(props.minSwipeDistance, itemDetail.size + itemDetail.space);
|
|
586
|
+
});
|
|
587
|
+
const canGoForward = () => {
|
|
588
|
+
if (needLoop.value) {
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
591
|
+
const nextIndex = dragDetail.offset > 0 ? activeIndex.value - 1 : activeIndex.value + 1;
|
|
592
|
+
return nextIndex >= 0 && nextIndex < itemList.length;
|
|
593
|
+
};
|
|
594
|
+
const trackStyle = computed(() => {
|
|
595
|
+
const offset = dragDetail.isDragging && !props.isFollowHand ? trackDetail.offset : trackDetail.offset + dragDetail.offset;
|
|
596
|
+
const style2 = {};
|
|
597
|
+
if (props.vertical) {
|
|
598
|
+
style2.transform = `translate3d(0, ${offset}px, 0)`;
|
|
599
|
+
style2.transitionDuration = dragDetail.transitionEnabled ? `${props.duration}ms` : "0ms";
|
|
600
|
+
} else {
|
|
601
|
+
style2.transform = `translate3d(${offset}px, 0, 0)`;
|
|
602
|
+
style2.transitionDuration = dragDetail.transitionEnabled ? `${props.duration}ms` : "0ms";
|
|
603
|
+
}
|
|
604
|
+
if (dragDetail.isDragging) {
|
|
605
|
+
style2.transition = "none";
|
|
606
|
+
}
|
|
607
|
+
if (props.vertical) {
|
|
608
|
+
style2.flexDirection = "column";
|
|
609
|
+
}
|
|
610
|
+
if (props.autoHeight) {
|
|
611
|
+
style2.display = "block";
|
|
612
|
+
style2.whiteSpace = "nowrap";
|
|
613
|
+
}
|
|
614
|
+
return style2;
|
|
355
615
|
});
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
props: e,
|
|
360
|
-
itemDetail: s,
|
|
361
|
-
itemShowedList: k
|
|
616
|
+
const dotsClass = computed(() => {
|
|
617
|
+
const position = props.dotsPosition || (props.vertical ? Position.left : Position.bottom);
|
|
618
|
+
return ["y-swipe__dots", `y-swipe__dots--${position}`];
|
|
362
619
|
});
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
620
|
+
expose({
|
|
621
|
+
moveTo,
|
|
622
|
+
next,
|
|
623
|
+
prev,
|
|
624
|
+
resize
|
|
625
|
+
});
|
|
626
|
+
const tabs = reactive({
|
|
627
|
+
children: itemList,
|
|
628
|
+
activeIndex,
|
|
629
|
+
props,
|
|
630
|
+
itemDetail,
|
|
631
|
+
itemShowedList
|
|
632
|
+
});
|
|
633
|
+
initProvide(tabs);
|
|
634
|
+
const renderDots = () => {
|
|
635
|
+
if (props.dots) {
|
|
636
|
+
return createVNode("div", {
|
|
637
|
+
"class": dotsClass.value
|
|
638
|
+
}, [itemList.map((_, index) => {
|
|
639
|
+
const className = bem$2("dot", {
|
|
640
|
+
active: index === activeIndex.value
|
|
641
|
+
});
|
|
642
|
+
return createVNode("div", {
|
|
643
|
+
"class": className,
|
|
644
|
+
"style": {
|
|
645
|
+
backgroundColor: props.dotsColor
|
|
646
|
+
},
|
|
647
|
+
"key": index
|
|
648
|
+
}, null);
|
|
649
|
+
})]);
|
|
650
|
+
}
|
|
651
|
+
return null;
|
|
652
|
+
};
|
|
378
653
|
return () => {
|
|
379
|
-
var
|
|
380
|
-
return
|
|
381
|
-
class:
|
|
382
|
-
ref:
|
|
383
|
-
}, [
|
|
384
|
-
class:
|
|
385
|
-
style:
|
|
386
|
-
ref:
|
|
387
|
-
}, [Array(
|
|
388
|
-
var
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
654
|
+
var _a;
|
|
655
|
+
return createVNode("div", {
|
|
656
|
+
"class": bem$2(),
|
|
657
|
+
"ref": swipeRef
|
|
658
|
+
}, [createVNode("div", {
|
|
659
|
+
"class": bem$2("track"),
|
|
660
|
+
"style": trackStyle.value,
|
|
661
|
+
"ref": swipeTrackRef
|
|
662
|
+
}, [Array(trackDetail.cloneNodeCount).fill("").map((_, index) => {
|
|
663
|
+
var _a2, _b, _c;
|
|
664
|
+
const nodeIndex = getIndex(index - trackDetail.cloneNodeCount);
|
|
665
|
+
const item = (_c = (_a2 = itemList[nodeIndex]) == null ? void 0 : (_b = _a2.slots).default) == null ? void 0 : _c.call(_b);
|
|
666
|
+
return item ? createVNode(YSwipeItem, {
|
|
667
|
+
"clonenNode": item,
|
|
668
|
+
"index": nodeIndex
|
|
393
669
|
}, null) : null;
|
|
394
|
-
}), (
|
|
395
|
-
var
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
670
|
+
}), (_a = slots.default) == null ? void 0 : _a.call(slots), Array(trackDetail.cloneNodeCount).fill("").map((_, index) => {
|
|
671
|
+
var _a2, _b, _c;
|
|
672
|
+
const nodeIndex = getIndex(index);
|
|
673
|
+
const item = (_c = (_a2 = itemList[nodeIndex]) == null ? void 0 : (_b = _a2.slots).default) == null ? void 0 : _c.call(_b);
|
|
674
|
+
return item ? createVNode(YSwipeItem, {
|
|
675
|
+
"clonenNode": item,
|
|
676
|
+
"index": nodeIndex
|
|
400
677
|
}, null) : null;
|
|
401
|
-
})]),
|
|
678
|
+
})]), slots.dots ? slots.dots() : renderDots()]);
|
|
402
679
|
};
|
|
403
680
|
}
|
|
404
|
-
})
|
|
405
|
-
|
|
681
|
+
});
|
|
682
|
+
const [name$1, bem$1] = createNamespace("tabs-title");
|
|
683
|
+
const YTabTitle = /* @__PURE__ */ defineComponent({
|
|
684
|
+
name: name$1,
|
|
406
685
|
props: {
|
|
407
686
|
active: {
|
|
408
687
|
type: Boolean,
|
|
409
|
-
default:
|
|
688
|
+
default: false
|
|
410
689
|
},
|
|
411
690
|
scrollable: {
|
|
412
691
|
type: Boolean,
|
|
413
|
-
default:
|
|
692
|
+
default: false
|
|
414
693
|
},
|
|
415
694
|
title: {
|
|
416
695
|
type: String,
|
|
@@ -422,39 +701,47 @@ const ke = {
|
|
|
422
701
|
},
|
|
423
702
|
disabled: {
|
|
424
703
|
type: Boolean,
|
|
425
|
-
default:
|
|
704
|
+
default: false
|
|
426
705
|
}
|
|
427
706
|
},
|
|
428
|
-
setup(
|
|
707
|
+
setup(props) {
|
|
429
708
|
const {
|
|
430
|
-
parent
|
|
431
|
-
} =
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
709
|
+
parent
|
|
710
|
+
} = useRelation(TABS_KEY);
|
|
711
|
+
const titleClass = computed(() => {
|
|
712
|
+
return [{
|
|
713
|
+
"y-el--clickable": !props.disabled
|
|
714
|
+
}, bem$1({
|
|
715
|
+
scrollable: props.scrollable,
|
|
716
|
+
disabled: props.disabled
|
|
717
|
+
}), bem$1(`${(parent == null ? void 0 : parent.props.size) || "middle"}`, {
|
|
718
|
+
active: props.active
|
|
719
|
+
}), parent == null ? void 0 : parent.props.titleClass, props.active ? parent == null ? void 0 : parent.props.titleActiveClass : ""];
|
|
720
|
+
});
|
|
721
|
+
const titleStyle = computed(() => {
|
|
722
|
+
return {
|
|
723
|
+
...parent == null ? void 0 : parent.props.titleStyle,
|
|
724
|
+
...props.active ? {
|
|
725
|
+
...parent == null ? void 0 : parent.props.titleActiveStyle
|
|
726
|
+
} : {}
|
|
727
|
+
};
|
|
728
|
+
});
|
|
444
729
|
return () => {
|
|
445
730
|
const {
|
|
446
|
-
title
|
|
447
|
-
titleSlot
|
|
448
|
-
} =
|
|
449
|
-
return
|
|
450
|
-
class:
|
|
451
|
-
title:
|
|
452
|
-
style:
|
|
453
|
-
role: "presentation"
|
|
454
|
-
}, [
|
|
731
|
+
title,
|
|
732
|
+
titleSlot
|
|
733
|
+
} = props;
|
|
734
|
+
return createVNode("div", {
|
|
735
|
+
"class": titleClass.value,
|
|
736
|
+
"title": title,
|
|
737
|
+
"style": titleStyle.value,
|
|
738
|
+
"role": "presentation"
|
|
739
|
+
}, [titleSlot ? titleSlot() : title]);
|
|
455
740
|
};
|
|
456
741
|
}
|
|
457
|
-
})
|
|
742
|
+
});
|
|
743
|
+
const unknownProp = null;
|
|
744
|
+
const acceptProps = {
|
|
458
745
|
initIndex: {
|
|
459
746
|
type: Number,
|
|
460
747
|
default: 0
|
|
@@ -469,7 +756,7 @@ const ke = {
|
|
|
469
756
|
},
|
|
470
757
|
lazy: {
|
|
471
758
|
type: Boolean,
|
|
472
|
-
default:
|
|
759
|
+
default: false
|
|
473
760
|
},
|
|
474
761
|
lineColor: {
|
|
475
762
|
type: String,
|
|
@@ -483,7 +770,7 @@ const ke = {
|
|
|
483
770
|
type: [Number, String],
|
|
484
771
|
default: "3px"
|
|
485
772
|
},
|
|
486
|
-
titleWrapperClass:
|
|
773
|
+
titleWrapperClass: unknownProp,
|
|
487
774
|
titleScrollThreshold: {
|
|
488
775
|
type: Number,
|
|
489
776
|
default: 5
|
|
@@ -493,7 +780,7 @@ const ke = {
|
|
|
493
780
|
default: null
|
|
494
781
|
},
|
|
495
782
|
titleClass: {
|
|
496
|
-
type:
|
|
783
|
+
type: unknownProp,
|
|
497
784
|
default: null
|
|
498
785
|
},
|
|
499
786
|
titleActiveStyle: {
|
|
@@ -501,16 +788,16 @@ const ke = {
|
|
|
501
788
|
default: null
|
|
502
789
|
},
|
|
503
790
|
titleActiveClass: {
|
|
504
|
-
type:
|
|
791
|
+
type: unknownProp,
|
|
505
792
|
default: null
|
|
506
793
|
},
|
|
507
794
|
touchable: {
|
|
508
795
|
type: Boolean,
|
|
509
|
-
default:
|
|
796
|
+
default: true
|
|
510
797
|
},
|
|
511
798
|
changeWithAnimation: {
|
|
512
799
|
type: Boolean,
|
|
513
|
-
default:
|
|
800
|
+
default: false
|
|
514
801
|
},
|
|
515
802
|
size: {
|
|
516
803
|
type: String,
|
|
@@ -521,153 +808,207 @@ const ke = {
|
|
|
521
808
|
default: "center"
|
|
522
809
|
}
|
|
523
810
|
};
|
|
524
|
-
function
|
|
525
|
-
return typeof
|
|
811
|
+
function _isSlot(s) {
|
|
812
|
+
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
|
|
526
813
|
}
|
|
527
|
-
const [
|
|
528
|
-
|
|
814
|
+
const [name, bem] = createNamespace("tabs");
|
|
815
|
+
const TABS_KEY = name;
|
|
816
|
+
const Tabs = /* @__PURE__ */ defineComponent({
|
|
817
|
+
name,
|
|
529
818
|
components: {
|
|
530
|
-
YTabTitle
|
|
819
|
+
YTabTitle
|
|
531
820
|
},
|
|
532
|
-
props:
|
|
533
|
-
setup(
|
|
534
|
-
slots
|
|
535
|
-
emit
|
|
536
|
-
expose
|
|
821
|
+
props: acceptProps,
|
|
822
|
+
setup(props, {
|
|
823
|
+
slots,
|
|
824
|
+
emit,
|
|
825
|
+
expose
|
|
537
826
|
}) {
|
|
538
827
|
const {
|
|
539
|
-
initProvide
|
|
540
|
-
} =
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
828
|
+
initProvide
|
|
829
|
+
} = setRelation(TABS_KEY);
|
|
830
|
+
const inited = ref(false);
|
|
831
|
+
const childrenList = reactive([]);
|
|
832
|
+
const swiperRef = ref();
|
|
833
|
+
const isTabScrollable = computed(() => childrenList.length > props.titleScrollThreshold);
|
|
834
|
+
const getCurIndexByName = (titleName) => {
|
|
835
|
+
return childrenList.findIndex((node) => (node.$props ? node.$props.name : "") === titleName);
|
|
836
|
+
};
|
|
837
|
+
const activeIndex = ref(props.initName ? getCurIndexByName(props.initName) : props.initIndex);
|
|
838
|
+
const scrollTo = (index) => {
|
|
839
|
+
activeIndex.value = index;
|
|
840
|
+
const swiper = swiperRef.value;
|
|
841
|
+
Boolean(swiper) && (swiper == null ? void 0 : swiper.moveTo(index, props.changeWithAnimation));
|
|
842
|
+
};
|
|
843
|
+
const scrollToByIndex = (index) => {
|
|
844
|
+
scrollTo(index);
|
|
845
|
+
};
|
|
846
|
+
const scrollToByName = (tabName) => {
|
|
847
|
+
const curIndex = getCurIndexByName(tabName);
|
|
848
|
+
scrollTo(curIndex);
|
|
849
|
+
};
|
|
850
|
+
expose({
|
|
851
|
+
scrollToByIndex,
|
|
852
|
+
scrollToByName
|
|
553
853
|
});
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
|
|
854
|
+
const titlesRef = ref([]);
|
|
855
|
+
const tabListRef = ref();
|
|
856
|
+
const getTitlesRef = (index) => (titleRef) => {
|
|
857
|
+
titlesRef.value[index] = titleRef;
|
|
858
|
+
};
|
|
859
|
+
const clickTitle = (index) => {
|
|
557
860
|
const {
|
|
558
|
-
title
|
|
559
|
-
name:
|
|
560
|
-
disabled
|
|
561
|
-
} =
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
861
|
+
title,
|
|
862
|
+
name: clickedName,
|
|
863
|
+
disabled
|
|
864
|
+
} = childrenList[index].$props || {};
|
|
865
|
+
if (activeIndex.value === index)
|
|
866
|
+
return;
|
|
867
|
+
emit(disabled ? "disabledClick" : "click", index, title, clickedName);
|
|
868
|
+
if (disabled)
|
|
869
|
+
return;
|
|
870
|
+
scrollTo(index);
|
|
871
|
+
};
|
|
872
|
+
const titleScrollToView = async () => {
|
|
873
|
+
await nextTick(() => {
|
|
874
|
+
if (!isTabScrollable.value || !tabListRef.value)
|
|
566
875
|
return;
|
|
567
|
-
const
|
|
568
|
-
if (!
|
|
876
|
+
const tabListEl = tabListRef.value;
|
|
877
|
+
if (!tabListEl || !titlesRef.value[activeIndex.value])
|
|
569
878
|
return;
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
|
|
879
|
+
const curTitleEl = titlesRef.value[activeIndex.value].$el;
|
|
880
|
+
const scrollDistance = curTitleEl.offsetLeft - (tabListEl.offsetWidth - curTitleEl.offsetWidth) / 2 - tabListEl.scrollLeft;
|
|
881
|
+
tabListEl.scrollBy({
|
|
882
|
+
left: scrollDistance,
|
|
573
883
|
behavior: "smooth"
|
|
574
884
|
});
|
|
575
885
|
});
|
|
576
886
|
};
|
|
577
|
-
|
|
578
|
-
|
|
887
|
+
onBeforeUpdate(() => {
|
|
888
|
+
titlesRef.value = [];
|
|
579
889
|
});
|
|
580
|
-
const
|
|
890
|
+
const lintState = reactive({
|
|
581
891
|
transform: "translateX(50%)",
|
|
582
892
|
transition: "all 0ms ease-out"
|
|
583
|
-
})
|
|
584
|
-
|
|
585
|
-
|
|
893
|
+
});
|
|
894
|
+
const updateLineStyle = async () => {
|
|
895
|
+
await nextTick(() => {
|
|
896
|
+
if (!titlesRef.value || titlesRef.value.length === 0)
|
|
586
897
|
return;
|
|
587
|
-
const
|
|
588
|
-
|
|
898
|
+
const curIndex = activeIndex.value >= titlesRef.value.length ? 0 : activeIndex.value;
|
|
899
|
+
const curTitle = titlesRef.value[curIndex].$el;
|
|
900
|
+
const left = curTitle.offsetLeft + curTitle.offsetWidth / 2;
|
|
901
|
+
lintState.transform = `translateX(${left}px) translateX(-50%)`;
|
|
902
|
+
if (inited.value) {
|
|
903
|
+
lintState.transition = `all ${props.duration}ms ease-out`;
|
|
904
|
+
}
|
|
905
|
+
inited.value = true;
|
|
589
906
|
});
|
|
590
|
-
}
|
|
907
|
+
};
|
|
908
|
+
const swipeChange = (index) => {
|
|
591
909
|
const {
|
|
592
|
-
title
|
|
593
|
-
name:
|
|
594
|
-
} =
|
|
595
|
-
|
|
596
|
-
|
|
910
|
+
title,
|
|
911
|
+
name: swiperedName
|
|
912
|
+
} = childrenList[index].$props || {};
|
|
913
|
+
emit("change", index, title, swiperedName);
|
|
914
|
+
activeIndex.value = index;
|
|
915
|
+
};
|
|
916
|
+
const swipeAfterChange = (index) => {
|
|
597
917
|
const {
|
|
598
|
-
title
|
|
599
|
-
name:
|
|
600
|
-
} =
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
918
|
+
title,
|
|
919
|
+
name: afterSwiperedName
|
|
920
|
+
} = childrenList[index].$props || {};
|
|
921
|
+
emit("afterChange", index, title, afterSwiperedName);
|
|
922
|
+
activeIndex.value = index;
|
|
923
|
+
};
|
|
924
|
+
const tabs = reactive({
|
|
925
|
+
children: childrenList,
|
|
926
|
+
activeIndex,
|
|
927
|
+
props
|
|
928
|
+
});
|
|
929
|
+
initProvide(tabs);
|
|
930
|
+
const getSize = (value) => {
|
|
931
|
+
if (isString(value))
|
|
932
|
+
return /^\d+(\.\d+)?$/.test(value) ? `${value}px` : value;
|
|
933
|
+
return value;
|
|
934
|
+
};
|
|
935
|
+
const isString = (value) => {
|
|
936
|
+
return Object.prototype.toString.call(value) === `[object String]`;
|
|
937
|
+
};
|
|
938
|
+
onMounted(async () => {
|
|
939
|
+
await updateLineStyle();
|
|
606
940
|
});
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
var i;
|
|
615
|
-
return (i = n.default) == null ? void 0 : i.length;
|
|
941
|
+
watch(() => activeIndex.value, async () => {
|
|
942
|
+
await updateLineStyle();
|
|
943
|
+
await titleScrollToView();
|
|
944
|
+
});
|
|
945
|
+
watch(() => {
|
|
946
|
+
var _a;
|
|
947
|
+
return (_a = slots.default) == null ? void 0 : _a.length;
|
|
616
948
|
}, async () => {
|
|
617
|
-
await
|
|
618
|
-
})
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
[
|
|
949
|
+
await updateLineStyle();
|
|
950
|
+
});
|
|
951
|
+
return () => {
|
|
952
|
+
let _slot;
|
|
953
|
+
return createVNode("div", {
|
|
954
|
+
"class": name
|
|
955
|
+
}, [createVNode("div", {
|
|
956
|
+
"class": bem("list")
|
|
957
|
+
}, [createVNode("div", {
|
|
958
|
+
"ref": tabListRef,
|
|
959
|
+
"class": bem("list-child-wrapper", {
|
|
960
|
+
scrollable: isTabScrollable.value,
|
|
961
|
+
[props.size]: props.size,
|
|
962
|
+
[props.align]: props.align
|
|
630
963
|
})
|
|
631
|
-
}, [
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
964
|
+
}, [childrenList.length > 0 && childrenList.map((node, index) => {
|
|
965
|
+
return createVNode(YTabTitle, {
|
|
966
|
+
"title": node.title,
|
|
967
|
+
"disabled": node.disabled,
|
|
968
|
+
"title-slot": node.$slots.title,
|
|
969
|
+
"key": index,
|
|
970
|
+
"ref": getTitlesRef(index),
|
|
971
|
+
"active": activeIndex.value === index,
|
|
972
|
+
"scrollable": isTabScrollable.value,
|
|
973
|
+
"onClick": () => clickTitle(index)
|
|
974
|
+
}, null);
|
|
975
|
+
}), createVNode("div", {
|
|
976
|
+
"class": bem("line"),
|
|
977
|
+
"style": {
|
|
978
|
+
...lintState,
|
|
979
|
+
width: getSize(props.lineWidth),
|
|
980
|
+
height: getSize(props.lineHeight),
|
|
981
|
+
backgroundColor: props.lineColor
|
|
647
982
|
}
|
|
648
|
-
}, null)])]),
|
|
649
|
-
ref:
|
|
650
|
-
dots:
|
|
651
|
-
loop:
|
|
652
|
-
initIndex:
|
|
653
|
-
lazy:
|
|
654
|
-
touchable:
|
|
655
|
-
duration:
|
|
656
|
-
"is-follow-hand":
|
|
657
|
-
onChange:
|
|
658
|
-
onAfterChange:
|
|
659
|
-
},
|
|
660
|
-
default: () => [
|
|
983
|
+
}, null)])]), slots.default ? createVNode(Swipe, {
|
|
984
|
+
"ref": swiperRef,
|
|
985
|
+
"dots": false,
|
|
986
|
+
"loop": false,
|
|
987
|
+
"initIndex": activeIndex.value,
|
|
988
|
+
"lazy": props.lazy,
|
|
989
|
+
"touchable": props.touchable,
|
|
990
|
+
"duration": props.duration,
|
|
991
|
+
"is-follow-hand": props.changeWithAnimation,
|
|
992
|
+
"onChange": swipeChange,
|
|
993
|
+
"onAfterChange": swipeAfterChange
|
|
994
|
+
}, _isSlot(_slot = slots.default()) ? _slot : {
|
|
995
|
+
default: () => [_slot]
|
|
661
996
|
}) : null]);
|
|
662
997
|
};
|
|
663
998
|
}
|
|
664
999
|
});
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
1000
|
+
const reset = "";
|
|
1001
|
+
const libs = "";
|
|
1002
|
+
const font = "";
|
|
1003
|
+
const animation = "";
|
|
1004
|
+
const theme = "";
|
|
1005
|
+
const style = "";
|
|
1006
|
+
Tabs.install = (Vue) => {
|
|
1007
|
+
const { name: name2 } = Tabs;
|
|
1008
|
+
Vue.component(name2, Tabs);
|
|
668
1009
|
};
|
|
669
1010
|
export {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
1011
|
+
acceptProps,
|
|
1012
|
+
Tabs as default,
|
|
1013
|
+
unknownProp
|
|
673
1014
|
};
|