@tdesign/uniapp 0.7.3 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/dist/action-sheet/README.md +1 -1
- package/dist/action-sheet/action-sheet.vue +158 -150
- package/dist/action-sheet/props.ts +2 -2
- package/dist/action-sheet/type.ts +1 -1
- package/dist/avatar/avatar.vue +89 -87
- package/dist/avatar-group/avatar-group.vue +69 -67
- package/dist/back-top/back-top.vue +60 -58
- package/dist/badge/badge.vue +69 -59
- package/dist/button/button.vue +121 -116
- package/dist/button/props.ts +2 -2
- package/dist/button/type.ts +1 -1
- package/dist/calendar/calendar-header.vue +4 -4
- package/dist/calendar/calendar.vue +308 -297
- package/dist/calendar/template.vue +1 -1
- package/dist/cascader/README.en-US.md +2 -1
- package/dist/cascader/README.md +2 -1
- package/dist/cascader/cascader.vue +340 -328
- package/dist/cascader/props.ts +6 -1
- package/dist/cascader/type.ts +6 -0
- package/dist/cell/cell.vue +127 -121
- package/dist/cell-group/cell-group.vue +32 -30
- package/dist/check-tag/check-tag.vue +73 -71
- package/dist/checkbox/checkbox.vue +127 -127
- package/dist/checkbox/props.ts +6 -6
- package/dist/checkbox/type.ts +3 -3
- package/dist/checkbox-group/checkbox-group.vue +175 -173
- package/dist/checkbox-group/props.ts +6 -6
- package/dist/checkbox-group/type.ts +4 -4
- package/dist/col/col.vue +26 -24
- package/dist/collapse/collapse.vue +83 -81
- package/dist/collapse-panel/collapse-panel.vue +121 -119
- package/dist/collapse-panel/props.ts +4 -4
- package/dist/collapse-panel/type.ts +2 -2
- package/dist/color-picker/README.md +1 -1
- package/dist/color-picker/color-picker.vue +324 -322
- package/dist/color-picker/props.ts +2 -2
- package/dist/color-picker/template.vue +14 -10
- package/dist/common/common.ts +1 -0
- package/dist/common/style/theme/index.css +5 -5
- package/dist/common/utils.js +7 -2
- package/dist/common/validator.js +172 -0
- package/dist/config-provider/README.en-US.md +184 -0
- package/dist/config-provider/README.md +234 -0
- package/dist/config-provider/config-provider.vue +105 -0
- package/dist/config-provider/config-store.js +70 -0
- package/dist/config-provider/props.ts +16 -0
- package/dist/config-provider/reactive-state.js +39 -0
- package/dist/config-provider/type.ts +401 -0
- package/dist/config-provider/use-config.js +29 -0
- package/dist/config-provider/utils.js +29 -0
- package/dist/count-down/count-down.vue +98 -97
- package/dist/date-time-picker/date-time-picker.vue +410 -395
- package/dist/demo/demo.vue +1 -0
- package/dist/dialog/dialog.vue +175 -173
- package/dist/divider/divider.vue +38 -36
- package/dist/draggable/draggable.vue +60 -58
- package/dist/drawer/README.md +1 -1
- package/dist/drawer/drawer.vue +48 -46
- package/dist/dropdown-item/dropdown-item.vue +209 -207
- package/dist/dropdown-item/props.ts +4 -4
- package/dist/dropdown-item/type.ts +3 -3
- package/dist/dropdown-menu/dropdown-menu.vue +93 -99
- package/dist/empty/empty.vue +43 -42
- package/dist/fab/fab.vue +88 -86
- package/dist/footer/footer.vue +36 -34
- package/dist/form/README.en-US.md +17 -24
- package/dist/form/README.md +18 -25
- package/dist/form/form.css +1 -166
- package/dist/form/form.vue +251 -236
- package/dist/form/props.ts +2 -21
- package/dist/form/type.ts +7 -70
- package/dist/form-item/README.en-US.md +4 -5
- package/dist/form-item/README.md +4 -5
- package/dist/form-item/form-item.css +69 -96
- package/dist/form-item/form-item.vue +315 -336
- package/dist/form-item/form-model.ts +125 -173
- package/dist/form-item/props.ts +4 -17
- package/dist/form-item/type.ts +43 -1
- package/dist/grid/grid.vue +53 -51
- package/dist/grid-item/grid-item.vue +121 -119
- package/dist/guide/README.md +1 -1
- package/dist/guide/guide.vue +281 -277
- package/dist/icon/README.md +2 -4
- package/dist/icon/icon.vue +78 -76
- package/dist/image/README.md +1 -1
- package/dist/image/image.vue +103 -101
- package/dist/image-viewer/image-viewer.vue +160 -158
- package/dist/image-viewer/props.ts +2 -2
- package/dist/image-viewer/type.ts +1 -1
- package/dist/index.js +3 -0
- package/dist/indexes/indexes.vue +264 -267
- package/dist/indexes-anchor/indexes-anchor.vue +41 -41
- package/dist/input/input.vue +192 -192
- package/dist/input/props.ts +6 -6
- package/dist/input/type.ts +3 -3
- package/dist/link/link.vue +73 -71
- package/dist/loading/loading.vue +59 -59
- package/dist/locale/ar_KW.ts +157 -0
- package/dist/locale/en_US.ts +146 -0
- package/dist/locale/it_IT.ts +145 -0
- package/dist/locale/ja_JP.ts +132 -0
- package/dist/locale/ko_KR.ts +132 -0
- package/dist/locale/ru_RU.ts +157 -0
- package/dist/locale/zh_CN.ts +133 -0
- package/dist/locale/zh_TW.ts +132 -0
- package/dist/message/message.vue +181 -173
- package/dist/message/props.ts +2 -2
- package/dist/message/type.ts +1 -1
- package/dist/message-item/message-item.vue +192 -184
- package/dist/mixins/using-config.js +39 -0
- package/dist/navbar/navbar.vue +201 -199
- package/dist/notice-bar/notice-bar.vue +175 -171
- package/dist/notice-bar/props.ts +2 -2
- package/dist/notice-bar/type.ts +1 -1
- package/dist/npm/dayjs/esm/locale/ar.js +81 -0
- package/dist/npm/dayjs/esm/locale/it.js +39 -0
- package/dist/overlay/overlay.vue +50 -48
- package/dist/picker/picker.vue +168 -161
- package/dist/picker-item/picker-item.vue +269 -269
- package/dist/popover/README.md +1 -1
- package/dist/popover/popover.vue +262 -261
- package/dist/popover/props.ts +4 -4
- package/dist/popover/type.ts +2 -2
- package/dist/popup/popup.vue +46 -45
- package/dist/progress/README.md +1 -1
- package/dist/progress/progress.vue +76 -76
- package/dist/pull-down-refresh/props.ts +2 -2
- package/dist/pull-down-refresh/pull-down-refresh.vue +240 -234
- package/dist/pull-down-refresh/type.ts +1 -1
- package/dist/qrcode/README.md +1 -1
- package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +340 -338
- package/dist/qrcode/components/qrcode-status/qrcode-status.vue +6 -6
- package/dist/qrcode/qrcode.vue +93 -87
- package/dist/radio/props.ts +6 -6
- package/dist/radio/radio.vue +118 -120
- package/dist/radio/type.ts +3 -3
- package/dist/radio-group/props.ts +4 -4
- package/dist/radio-group/radio-group.vue +136 -134
- package/dist/radio-group/type.ts +4 -4
- package/dist/rate/computed.js +2 -2
- package/dist/rate/props.ts +4 -4
- package/dist/rate/rate.vue +155 -154
- package/dist/rate/type.ts +2 -2
- package/dist/result/result.vue +41 -39
- package/dist/row/row.vue +38 -36
- package/dist/scroll-view/scroll-view.vue +24 -22
- package/dist/search/props.ts +2 -2
- package/dist/search/search.vue +127 -125
- package/dist/search/type.ts +1 -1
- package/dist/side-bar/side-bar.vue +57 -55
- package/dist/side-bar-item/side-bar-item.vue +86 -86
- package/dist/skeleton/skeleton.vue +126 -124
- package/dist/slider/README.md +1 -1
- package/dist/slider/props.ts +2 -2
- package/dist/slider/slider.vue +457 -457
- package/dist/slider/type.ts +1 -1
- package/dist/step-item/step-item.vue +77 -75
- package/dist/stepper/props.ts +2 -2
- package/dist/stepper/stepper.vue +168 -149
- package/dist/stepper/type.ts +1 -1
- package/dist/steps/props.ts +2 -2
- package/dist/steps/steps.vue +83 -81
- package/dist/steps/type.ts +1 -1
- package/dist/sticky/sticky.vue +104 -102
- package/dist/swipe-cell/swipe-cell.vue +91 -89
- package/dist/swiper/README.md +1 -1
- package/dist/swiper/swiper.vue +91 -89
- package/dist/swiper-nav/swiper-nav.vue +38 -36
- package/dist/switch/props.ts +2 -2
- package/dist/switch/switch.vue +62 -62
- package/dist/switch/type.ts +1 -1
- package/dist/tab-bar/tab-bar.vue +88 -86
- package/dist/tab-bar-item/tab-bar-item.vue +85 -82
- package/dist/tab-panel/tab-panel.vue +66 -64
- package/dist/tabs/tabs.vue +294 -287
- package/dist/tag/tag.vue +79 -77
- package/dist/textarea/props.ts +6 -6
- package/dist/textarea/textarea.vue +127 -126
- package/dist/textarea/type.ts +3 -3
- package/dist/toast/toast.vue +107 -106
- package/dist/transition/transition.vue +30 -28
- package/dist/tree-select/tree-select.vue +151 -151
- package/dist/types/config-provider.d.ts +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/popover.d.ts +7 -0
- package/dist/upload/README.en-US.md +13 -14
- package/dist/upload/README.md +11 -12
- package/dist/upload/props.ts +2 -4
- package/dist/upload/type.ts +12 -11
- package/dist/upload/upload.css +1 -1
- package/dist/upload/upload.vue +672 -512
- package/dist/watermark/watermark.vue +151 -149
- package/global.d.ts +2 -0
- package/package.json +15 -3
- package/dist/form/form-item-props.ts +0 -56
package/dist/tabs/tabs.vue
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view
|
|
3
|
-
:style="tools._style([customStyle])"
|
|
4
|
-
:class="tools.cls(classPrefix, [placement]) + ' ' + tClass"
|
|
3
|
+
:style="'' + tools._style([customStyle])"
|
|
4
|
+
:class="'' + tools.cls(classPrefix, [placement]) + ' ' + tClass"
|
|
5
5
|
>
|
|
6
6
|
<t-sticky
|
|
7
7
|
:t-class="tools.cls(classPrefix + '__sticky', [placement])"
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
:container="stickyProps && stickyProps.container"
|
|
12
12
|
@scroll="onTouchScroll"
|
|
13
13
|
>
|
|
14
|
-
<view :class="tools.cls(classPrefix + '__wrapper', [theme])">
|
|
14
|
+
<view :class="'' + tools.cls(classPrefix + '__wrapper', [theme])">
|
|
15
15
|
<scroll-view
|
|
16
|
-
:class="tools.cls(classPrefix + '__scroll', [placement, ['split', split]])"
|
|
16
|
+
:class="'' + tools.cls(classPrefix + '__scroll', [placement, ['split', split]])"
|
|
17
17
|
enhanced
|
|
18
18
|
enable-flex
|
|
19
19
|
:scroll-left="offset"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
@scroll="onScroll"
|
|
27
27
|
>
|
|
28
28
|
<view
|
|
29
|
-
:class="tools.cls(classPrefix + '__nav', [placement, ['evenly', spaceEvenly]])"
|
|
29
|
+
:class="'' + tools.cls(classPrefix + '__nav', [placement, ['evenly', spaceEvenly]])"
|
|
30
30
|
aria-role="tablist"
|
|
31
31
|
>
|
|
32
32
|
<view
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
:key="index"
|
|
35
35
|
:data-index="index"
|
|
36
36
|
:class="
|
|
37
|
-
tools.cls(classPrefix + '__item', [theme, ['evenly', spaceEvenly], placement, ['disabled', item.disabled], ['active', currentIndex === index]]) +
|
|
37
|
+
'' + tools.cls(classPrefix + '__item', [theme, ['evenly', spaceEvenly], placement, ['disabled', item.disabled], ['active', currentIndex === index]]) +
|
|
38
38
|
' ' +
|
|
39
39
|
(currentIndex === index ? tClassActive : '') +
|
|
40
40
|
' ' +
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
@click="onTabTap"
|
|
49
49
|
>
|
|
50
50
|
<view
|
|
51
|
-
:class="tools.cls(classPrefix + '__item-inner', [theme, ['active', currentIndex === index]])"
|
|
51
|
+
:class="'' + tools.cls(classPrefix + '__item-inner', [theme, ['active', currentIndex === index]])"
|
|
52
52
|
:aria-hidden="item.badgeProps.dot || item.badgeProps.count"
|
|
53
53
|
>
|
|
54
54
|
<block
|
|
@@ -107,8 +107,8 @@
|
|
|
107
107
|
</view>
|
|
108
108
|
<view
|
|
109
109
|
v-if="theme == 'line' && showBottomLine"
|
|
110
|
-
:class="tools.cls(classPrefix + '__track', [placement]) + ' ' + tClassTrack"
|
|
111
|
-
:style="trackStyle(trackOption)"
|
|
110
|
+
:class="'' + tools.cls(classPrefix + '__track', [placement]) + ' ' + tClassTrack"
|
|
111
|
+
:style="''+trackStyle(trackOption)"
|
|
112
112
|
/>
|
|
113
113
|
</view>
|
|
114
114
|
</scroll-view>
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
</t-sticky>
|
|
117
117
|
<slot name="middle" />
|
|
118
118
|
<view
|
|
119
|
-
:class="tools.cls(classPrefix + '__content', [['animated', animation]])"
|
|
119
|
+
:class="'' + tools.cls(classPrefix + '__content', [['animated', animation]])"
|
|
120
120
|
@touchstart="onTouchStart"
|
|
121
121
|
@touchmove="onTouchMove"
|
|
122
122
|
@touchend="onTouchEnd"
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
>
|
|
125
125
|
<view
|
|
126
126
|
:class="classPrefix + '__content-inner ' + tClassContent"
|
|
127
|
-
:style="animate({ duration: animation && animation.duration, currentIndex: currentIndex })"
|
|
127
|
+
:style="''+animate({ duration: animation && animation.duration, currentIndex: currentIndex })"
|
|
128
128
|
>
|
|
129
129
|
<slot />
|
|
130
130
|
</view>
|
|
@@ -149,334 +149,341 @@ const name = `${prefix}-tabs`;
|
|
|
149
149
|
const getUniqueID = uniqueFactory('tabs');
|
|
150
150
|
|
|
151
151
|
|
|
152
|
-
export default
|
|
153
|
-
name,
|
|
154
|
-
options: {
|
|
155
|
-
styleIsolation: 'shared',
|
|
156
|
-
},
|
|
157
|
-
controlledProps: [{
|
|
158
|
-
key: 'value',
|
|
159
|
-
event: 'change',
|
|
160
|
-
}],
|
|
161
|
-
externalClasses: [
|
|
162
|
-
`${prefix}-class`,
|
|
163
|
-
`${prefix}-class-item`,
|
|
164
|
-
`${prefix}-class-active`,
|
|
165
|
-
`${prefix}-class-track`,
|
|
166
|
-
`${prefix}-class-content`,
|
|
167
|
-
],
|
|
168
|
-
mixins: [touch, ParentMixin(RELATION_MAP.TabPanel)],
|
|
152
|
+
export default {
|
|
169
153
|
components: {
|
|
170
154
|
TSticky,
|
|
171
155
|
TBadge,
|
|
172
156
|
TIcon,
|
|
173
157
|
},
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
'change',
|
|
179
|
-
'scroll',
|
|
180
|
-
'error',
|
|
181
|
-
'click',
|
|
182
|
-
],
|
|
183
|
-
watch: {
|
|
184
|
-
value: {
|
|
185
|
-
handler(e) {
|
|
186
|
-
this.dataValue = e;
|
|
187
|
-
},
|
|
188
|
-
immediate: true,
|
|
158
|
+
...uniComponent({
|
|
159
|
+
name,
|
|
160
|
+
options: {
|
|
161
|
+
styleIsolation: 'shared',
|
|
189
162
|
},
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
163
|
+
controlledProps: [{
|
|
164
|
+
key: 'value',
|
|
165
|
+
event: 'change',
|
|
166
|
+
}],
|
|
167
|
+
externalClasses: [
|
|
168
|
+
`${prefix}-class`,
|
|
169
|
+
`${prefix}-class-item`,
|
|
170
|
+
`${prefix}-class-active`,
|
|
171
|
+
`${prefix}-class-track`,
|
|
172
|
+
`${prefix}-class-content`,
|
|
173
|
+
],
|
|
174
|
+
mixins: [touch, ParentMixin(RELATION_MAP.TabPanel)],
|
|
175
|
+
props: {
|
|
176
|
+
...props,
|
|
194
177
|
},
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
classPrefix: name,
|
|
213
|
-
tabs: [],
|
|
214
|
-
currentLabels: [],
|
|
215
|
-
currentIndex: -1,
|
|
216
|
-
trackOption: {
|
|
217
|
-
lineWidth: 0,
|
|
218
|
-
distance: 0,
|
|
219
|
-
isInit: true,
|
|
178
|
+
emits: [
|
|
179
|
+
'change',
|
|
180
|
+
'scroll',
|
|
181
|
+
'error',
|
|
182
|
+
'click',
|
|
183
|
+
],
|
|
184
|
+
watch: {
|
|
185
|
+
value: {
|
|
186
|
+
handler(e) {
|
|
187
|
+
this.dataValue = e;
|
|
188
|
+
},
|
|
189
|
+
immediate: true,
|
|
190
|
+
},
|
|
191
|
+
dataValue(name) {
|
|
192
|
+
if (name !== this.getCurrentName()) {
|
|
193
|
+
this.setCurrentIndexByName(name);
|
|
194
|
+
}
|
|
220
195
|
},
|
|
221
|
-
offset: 0,
|
|
222
|
-
scrollLeft: 0,
|
|
223
|
-
tabID: '',
|
|
224
|
-
placement: 'top',
|
|
225
|
-
tools,
|
|
226
|
-
|
|
227
|
-
dataValue: coalesce(this.value, this.defaultValue),
|
|
228
|
-
};
|
|
229
|
-
},
|
|
230
|
-
methods: {
|
|
231
|
-
trackStyle,
|
|
232
|
-
animate,
|
|
233
|
-
innerAfterLinked(target) {
|
|
234
|
-
// mixin 中已注入
|
|
235
|
-
// this.children.push(target);
|
|
236
|
-
this.initChildId();
|
|
237
|
-
target.dataIndex = this.children.length - 1;
|
|
238
|
-
this.updateTabs();
|
|
239
|
-
},
|
|
240
|
-
innerAfterUnlinked(target) {
|
|
241
|
-
this.children = this.children.filter(item => item.index !== target.dataIndex);
|
|
242
|
-
this.updateTabs(() => this.setTrack());
|
|
243
|
-
this.initChildId();
|
|
244
|
-
},
|
|
245
|
-
initChildId() {
|
|
246
|
-
this.children.forEach((item, index) => {
|
|
247
|
-
item.setId(`${this.tabID}_panel_${index}`);
|
|
248
|
-
});
|
|
249
196
|
},
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
this.scrollLeft = scrollLeft;
|
|
197
|
+
created() {
|
|
198
|
+
this.children = this.children || [];
|
|
253
199
|
},
|
|
254
|
-
updateTabs(cb) {
|
|
255
|
-
const { children } = this;
|
|
256
|
-
const tabs = children.map((child) => {
|
|
257
|
-
const { label, badgeProps, disabled, icon, panel, value, lazy } = child;
|
|
258
|
-
return {
|
|
259
|
-
label, badgeProps, disabled, icon, panel, value, lazy,
|
|
260
|
-
};
|
|
261
|
-
});
|
|
262
200
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
201
|
+
mounted() {
|
|
202
|
+
nextTick().then(() => {
|
|
203
|
+
this.setTrack();
|
|
267
204
|
});
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
this.setCurrentIndexByName(this.dataValue);
|
|
205
|
+
getRect(this, `.${name}`).then((rect) => {
|
|
206
|
+
this.containerWidth = rect.width;
|
|
207
|
+
});
|
|
208
|
+
this.tabID = getUniqueID();
|
|
275
209
|
},
|
|
210
|
+
data() {
|
|
211
|
+
return {
|
|
212
|
+
prefix,
|
|
213
|
+
classPrefix: name,
|
|
214
|
+
tabs: [],
|
|
215
|
+
currentLabels: [],
|
|
216
|
+
currentIndex: -1,
|
|
217
|
+
trackOption: {
|
|
218
|
+
lineWidth: 0,
|
|
219
|
+
distance: 0,
|
|
220
|
+
isInit: true,
|
|
221
|
+
},
|
|
222
|
+
offset: 0,
|
|
223
|
+
scrollLeft: 0,
|
|
224
|
+
tabID: '',
|
|
225
|
+
placement: 'top',
|
|
226
|
+
tools,
|
|
276
227
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const index = children.findIndex(child => child.getComputedName() === `${name}`);
|
|
280
|
-
if (index > -1) {
|
|
281
|
-
this.setCurrentIndex(index);
|
|
282
|
-
}
|
|
228
|
+
dataValue: coalesce(this.value, this.defaultValue),
|
|
229
|
+
};
|
|
283
230
|
},
|
|
231
|
+
methods: {
|
|
232
|
+
trackStyle,
|
|
233
|
+
animate,
|
|
234
|
+
innerAfterLinked(target) {
|
|
235
|
+
// mixin 中已注入
|
|
236
|
+
// this.children.push(target);
|
|
237
|
+
this.initChildId();
|
|
238
|
+
target.dataIndex = this.children.length - 1;
|
|
239
|
+
this.updateTabs();
|
|
240
|
+
},
|
|
241
|
+
innerAfterUnlinked(target) {
|
|
242
|
+
this.children = this.children.filter(item => item.index !== target.dataIndex);
|
|
243
|
+
this.updateTabs(() => this.setTrack());
|
|
244
|
+
this.initChildId();
|
|
245
|
+
},
|
|
246
|
+
initChildId() {
|
|
247
|
+
this.children.forEach((item, index) => {
|
|
248
|
+
item.setId(`${this.tabID}_panel_${index}`);
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
onScroll(e = {}) {
|
|
252
|
+
const { scrollLeft } = e.detail || {};
|
|
253
|
+
this.scrollLeft = scrollLeft;
|
|
254
|
+
},
|
|
255
|
+
updateTabs(cb) {
|
|
256
|
+
const { children } = this;
|
|
257
|
+
const tabs = children.map((child) => {
|
|
258
|
+
const { label, badgeProps, disabled, icon, panel, value, lazy } = child;
|
|
259
|
+
return {
|
|
260
|
+
label, badgeProps, disabled, icon, panel, value, lazy,
|
|
261
|
+
};
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
tabs.forEach((item) => {
|
|
265
|
+
if (typeof item.icon === 'string') {
|
|
266
|
+
item.icon = { name: item.icon };
|
|
267
|
+
}
|
|
268
|
+
});
|
|
284
269
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
this.children.forEach((child, idx) => {
|
|
289
|
-
const isActive = index === idx;
|
|
290
|
-
if (isActive !== child.active || !child.initialized) {
|
|
291
|
-
child.render(isActive, this);
|
|
270
|
+
this.tabs = tabs;
|
|
271
|
+
if (typeof cb === 'function') {
|
|
272
|
+
setTimeout(cb, 33);
|
|
292
273
|
}
|
|
293
|
-
Labels.push(child.label);
|
|
294
|
-
});
|
|
295
274
|
|
|
296
|
-
|
|
297
|
-
|
|
275
|
+
this.setCurrentIndexByName(this.dataValue);
|
|
276
|
+
},
|
|
298
277
|
|
|
299
|
-
|
|
300
|
-
|
|
278
|
+
setCurrentIndexByName(name) {
|
|
279
|
+
const { children } = this;
|
|
280
|
+
const index = children.findIndex(child => child.getComputedName() === `${name}`);
|
|
281
|
+
if (index > -1) {
|
|
282
|
+
this.setCurrentIndex(index);
|
|
283
|
+
}
|
|
284
|
+
},
|
|
301
285
|
|
|
286
|
+
setCurrentIndex(index) {
|
|
287
|
+
if (index <= -1 || index >= this.children.length) return;
|
|
288
|
+
const Labels = [];
|
|
289
|
+
this.children.forEach((child, idx) => {
|
|
290
|
+
const isActive = index === idx;
|
|
291
|
+
if (isActive !== child.active || !child.initialized) {
|
|
292
|
+
child.render(isActive, this);
|
|
293
|
+
}
|
|
294
|
+
// 当存在 animation 时,translate 偏移依赖所有 panel 占位,
|
|
295
|
+
// 需确保目标 index 及之前的 panel 都已激活 DOM
|
|
296
|
+
if (this.animation && idx <= index && !child.hasActivated) {
|
|
297
|
+
child.hasActivated = true;
|
|
298
|
+
}
|
|
299
|
+
Labels.push(child.label);
|
|
300
|
+
});
|
|
302
301
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}, 33);
|
|
306
|
-
},
|
|
302
|
+
const { currentIndex, currentLabels } = this;
|
|
303
|
+
if (currentIndex === index && currentLabels.join('') === Labels.join('')) return;
|
|
307
304
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const activeTab = this.children[this.currentIndex];
|
|
311
|
-
if (activeTab) {
|
|
312
|
-
return activeTab.getComputedName();
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
},
|
|
305
|
+
this.currentIndex = index;
|
|
306
|
+
this.currentLabels = Labels;
|
|
316
307
|
|
|
317
|
-
calcScrollOffset(containerWidth, targetLeft, targetWidth, offset) {
|
|
318
|
-
return offset + targetLeft - (1 / 2) * containerWidth + targetWidth / 2;
|
|
319
|
-
},
|
|
320
308
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
309
|
+
setTimeout(() => {
|
|
310
|
+
this.setTrack();
|
|
311
|
+
}, 33);
|
|
312
|
+
},
|
|
325
313
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
};
|
|
333
|
-
return new Promise((resolve, reject) => {
|
|
334
|
-
if (this.trackWidth) {
|
|
335
|
-
resolve(this.trackWidth);
|
|
336
|
-
return;
|
|
314
|
+
getCurrentName() {
|
|
315
|
+
if (this.children) {
|
|
316
|
+
const activeTab = this.children[this.currentIndex];
|
|
317
|
+
if (activeTab) {
|
|
318
|
+
return activeTab.getComputedName();
|
|
319
|
+
}
|
|
337
320
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
321
|
+
},
|
|
322
|
+
|
|
323
|
+
calcScrollOffset(containerWidth, targetLeft, targetWidth, offset) {
|
|
324
|
+
return offset + targetLeft - (1 / 2) * containerWidth + targetWidth / 2;
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
// 外部无法获取虚拟组件节点位置信息
|
|
328
|
+
getTabHeight() {
|
|
329
|
+
return getRect(this, `.${name}`);
|
|
330
|
+
},
|
|
347
331
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
let distance = 0;
|
|
360
|
-
let totalSize = 0;
|
|
361
|
-
|
|
362
|
-
res.forEach((item) => {
|
|
363
|
-
if (count < currentIndex) {
|
|
364
|
-
distance += item.width;
|
|
365
|
-
count += 1;
|
|
332
|
+
getTrackSize() {
|
|
333
|
+
const { bottomLineMode } = this;
|
|
334
|
+
const targetMap = {
|
|
335
|
+
fixed: `.${prefix}-tabs__track`,
|
|
336
|
+
auto: `.${prefix}-tabs__item--active .${prefix}-tabs__item-inner`,
|
|
337
|
+
full: `.${prefix}-tabs__item--active`,
|
|
338
|
+
};
|
|
339
|
+
return new Promise((resolve, reject) => {
|
|
340
|
+
if (this.trackWidth) {
|
|
341
|
+
resolve(this.trackWidth);
|
|
342
|
+
return;
|
|
366
343
|
}
|
|
367
|
-
|
|
344
|
+
getRect(this, targetMap[bottomLineMode] || targetMap.fixed)
|
|
345
|
+
.then((res) => {
|
|
346
|
+
if (res) {
|
|
347
|
+
resolve(res.width);
|
|
348
|
+
}
|
|
349
|
+
})
|
|
350
|
+
.catch(reject);
|
|
368
351
|
});
|
|
352
|
+
},
|
|
369
353
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
354
|
+
async setTrack() {
|
|
355
|
+
const { children } = this;
|
|
356
|
+
if (!children) return;
|
|
357
|
+
const { currentIndex } = this;
|
|
358
|
+
if (currentIndex <= -1) return;
|
|
359
|
+
|
|
360
|
+
try {
|
|
361
|
+
const res = await getRect(this, `.${prefix}-tabs__item`, true);
|
|
362
|
+
const rect = res[currentIndex];
|
|
363
|
+
if (!rect) return;
|
|
364
|
+
let count = 0;
|
|
365
|
+
let distance = 0;
|
|
366
|
+
let totalSize = 0;
|
|
367
|
+
|
|
368
|
+
res.forEach((item) => {
|
|
369
|
+
if (count < currentIndex) {
|
|
370
|
+
distance += item.width;
|
|
371
|
+
count += 1;
|
|
372
|
+
}
|
|
373
|
+
totalSize += item.width;
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
if (this.containerWidth) {
|
|
377
|
+
const offset = this.calcScrollOffset(this.containerWidth, rect.left, rect.width, this.scrollLeft);
|
|
378
|
+
const maxOffset = totalSize - this.containerWidth;
|
|
379
|
+
this.offset = Math.min(Math.max(offset, 0), maxOffset);
|
|
380
|
+
} else if (!this._hasObserved) {
|
|
381
|
+
this._hasObserved = true;
|
|
382
|
+
getObserver(this, `.${name}`).then(() => this.setTrack());
|
|
383
|
+
}
|
|
378
384
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
385
|
+
const lineWidth = await this.getTrackSize();
|
|
386
|
+
if (this.theme === 'line') {
|
|
387
|
+
distance += (rect.width - lineWidth) / 2;
|
|
388
|
+
}
|
|
383
389
|
|
|
384
|
-
|
|
385
|
-
|
|
390
|
+
const isInit = this.previousIndex === undefined;
|
|
391
|
+
if (isInit
|
|
386
392
|
|| this.previousIndex !== currentIndex
|
|
387
393
|
|| this.lastDistance !== distance
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
394
|
+
) {
|
|
395
|
+
this.previousIndex = currentIndex;
|
|
396
|
+
this.trackOption = { lineWidth, distance, isInit };
|
|
397
|
+
this.lastDistance = distance;
|
|
398
|
+
}
|
|
399
|
+
} catch (err) {
|
|
400
|
+
this.$emit('error', err);
|
|
392
401
|
}
|
|
393
|
-
}
|
|
394
|
-
this.$emit('error', err);
|
|
395
|
-
}
|
|
396
|
-
},
|
|
402
|
+
},
|
|
397
403
|
|
|
398
|
-
|
|
399
|
-
|
|
404
|
+
onTabTap(event) {
|
|
405
|
+
const { index } = event.currentTarget.dataset;
|
|
400
406
|
|
|
401
|
-
|
|
402
|
-
|
|
407
|
+
this.changeIndex(index);
|
|
408
|
+
},
|
|
403
409
|
|
|
404
|
-
|
|
405
|
-
|
|
410
|
+
onTouchStart(event) {
|
|
411
|
+
if (!this.swipeable) return;
|
|
406
412
|
|
|
407
|
-
|
|
408
|
-
|
|
413
|
+
this.touchStart(event);
|
|
414
|
+
},
|
|
409
415
|
|
|
410
|
-
|
|
411
|
-
|
|
416
|
+
onTouchMove(event) {
|
|
417
|
+
if (!this.swipeable) return;
|
|
412
418
|
|
|
413
|
-
|
|
414
|
-
|
|
419
|
+
this.touchMove(event);
|
|
420
|
+
},
|
|
415
421
|
|
|
416
|
-
|
|
417
|
-
|
|
422
|
+
onTouchEnd() {
|
|
423
|
+
if (!this.swipeable) return;
|
|
418
424
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
+
const { direction, deltaX, offsetX } = this;
|
|
426
|
+
const minSwipeDistance = 50;
|
|
427
|
+
if (direction === 'horizontal' && offsetX >= minSwipeDistance) {
|
|
428
|
+
const index = this.getAvailableTabIndex(deltaX);
|
|
429
|
+
if (index !== -1) {
|
|
430
|
+
this.changeIndex(index);
|
|
431
|
+
}
|
|
425
432
|
}
|
|
426
|
-
}
|
|
427
|
-
},
|
|
433
|
+
},
|
|
428
434
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
435
|
+
onTouchScroll(event) {
|
|
436
|
+
this._trigger('scroll', event);
|
|
437
|
+
},
|
|
432
438
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
439
|
+
changeIndex(index) {
|
|
440
|
+
const currentTab = this.tabs[index];
|
|
441
|
+
const { value, label } = currentTab;
|
|
442
|
+
if (!currentTab?.disabled && index !== this.currentIndex) {
|
|
443
|
+
this._trigger('change', { value, label });
|
|
444
|
+
}
|
|
445
|
+
this._trigger('click', { value, label });
|
|
446
|
+
},
|
|
441
447
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
448
|
+
getAvailableTabIndex(deltaX) {
|
|
449
|
+
const step = deltaX > 0 ? -1 : 1;
|
|
450
|
+
const { currentIndex, tabs } = this;
|
|
451
|
+
const len = tabs.length;
|
|
452
|
+
for (let i = step; currentIndex + step >= 0 && currentIndex + step < len; i += step) {
|
|
453
|
+
const newIndex = currentIndex + i;
|
|
454
|
+
if (newIndex >= 0 && newIndex < len && tabs[newIndex]) {
|
|
455
|
+
if (!tabs[newIndex].disabled) {
|
|
456
|
+
return newIndex;
|
|
457
|
+
}
|
|
458
|
+
} else {
|
|
459
|
+
return currentIndex;
|
|
451
460
|
}
|
|
452
|
-
} else {
|
|
453
|
-
return currentIndex;
|
|
454
461
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
},
|
|
462
|
+
return -1;
|
|
463
|
+
},
|
|
458
464
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
465
|
+
getBadgeCustomStyle(item, index) {
|
|
466
|
+
if (item.disabled) {
|
|
467
|
+
return '--td-badge-content-text-color: var(--td-tab-item-disabled-color, var(--td-text-color-disabled, var(--td-font-gray-4, rgba(0, 0, 0, .26))))';
|
|
468
|
+
}
|
|
469
|
+
if (this.currentIndex === index) {
|
|
470
|
+
return '--td-badge-content-text-color: var(--td-tab-item-active-color, var(--td-brand-color, var(--td-primary-color-7, #0052d9)));';
|
|
471
|
+
}
|
|
472
|
+
return '';
|
|
473
|
+
},
|
|
468
474
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
475
|
+
getIconCustomStyle(item) {
|
|
476
|
+
return tools._style([
|
|
477
|
+
{
|
|
478
|
+
fontSize: 'var(--td-tab-icon-size, 18px)',
|
|
479
|
+
marginRight: 'calc(var(--td-spacer, 8px) / 4)',
|
|
480
|
+
},
|
|
481
|
+
item.icon.style || '',
|
|
482
|
+
]);
|
|
483
|
+
},
|
|
477
484
|
},
|
|
478
|
-
},
|
|
479
|
-
}
|
|
485
|
+
}),
|
|
486
|
+
};
|
|
480
487
|
</script>
|
|
481
488
|
<style scoped src="./tabs.css"></style>
|
|
482
489
|
<style scoped>
|