@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.
Files changed (197) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -1
  3. package/dist/action-sheet/README.md +1 -1
  4. package/dist/action-sheet/action-sheet.vue +158 -150
  5. package/dist/action-sheet/props.ts +2 -2
  6. package/dist/action-sheet/type.ts +1 -1
  7. package/dist/avatar/avatar.vue +89 -87
  8. package/dist/avatar-group/avatar-group.vue +69 -67
  9. package/dist/back-top/back-top.vue +60 -58
  10. package/dist/badge/badge.vue +69 -59
  11. package/dist/button/button.vue +121 -116
  12. package/dist/button/props.ts +2 -2
  13. package/dist/button/type.ts +1 -1
  14. package/dist/calendar/calendar-header.vue +4 -4
  15. package/dist/calendar/calendar.vue +308 -297
  16. package/dist/calendar/template.vue +1 -1
  17. package/dist/cascader/README.en-US.md +2 -1
  18. package/dist/cascader/README.md +2 -1
  19. package/dist/cascader/cascader.vue +340 -328
  20. package/dist/cascader/props.ts +6 -1
  21. package/dist/cascader/type.ts +6 -0
  22. package/dist/cell/cell.vue +127 -121
  23. package/dist/cell-group/cell-group.vue +32 -30
  24. package/dist/check-tag/check-tag.vue +73 -71
  25. package/dist/checkbox/checkbox.vue +127 -127
  26. package/dist/checkbox/props.ts +6 -6
  27. package/dist/checkbox/type.ts +3 -3
  28. package/dist/checkbox-group/checkbox-group.vue +175 -173
  29. package/dist/checkbox-group/props.ts +6 -6
  30. package/dist/checkbox-group/type.ts +4 -4
  31. package/dist/col/col.vue +26 -24
  32. package/dist/collapse/collapse.vue +83 -81
  33. package/dist/collapse-panel/collapse-panel.vue +121 -119
  34. package/dist/collapse-panel/props.ts +4 -4
  35. package/dist/collapse-panel/type.ts +2 -2
  36. package/dist/color-picker/README.md +1 -1
  37. package/dist/color-picker/color-picker.vue +324 -322
  38. package/dist/color-picker/props.ts +2 -2
  39. package/dist/color-picker/template.vue +14 -10
  40. package/dist/common/common.ts +1 -0
  41. package/dist/common/style/theme/index.css +5 -5
  42. package/dist/common/utils.js +7 -2
  43. package/dist/common/validator.js +172 -0
  44. package/dist/config-provider/README.en-US.md +184 -0
  45. package/dist/config-provider/README.md +234 -0
  46. package/dist/config-provider/config-provider.vue +105 -0
  47. package/dist/config-provider/config-store.js +70 -0
  48. package/dist/config-provider/props.ts +16 -0
  49. package/dist/config-provider/reactive-state.js +39 -0
  50. package/dist/config-provider/type.ts +401 -0
  51. package/dist/config-provider/use-config.js +29 -0
  52. package/dist/config-provider/utils.js +29 -0
  53. package/dist/count-down/count-down.vue +98 -97
  54. package/dist/date-time-picker/date-time-picker.vue +410 -395
  55. package/dist/demo/demo.vue +1 -0
  56. package/dist/dialog/dialog.vue +175 -173
  57. package/dist/divider/divider.vue +38 -36
  58. package/dist/draggable/draggable.vue +60 -58
  59. package/dist/drawer/README.md +1 -1
  60. package/dist/drawer/drawer.vue +48 -46
  61. package/dist/dropdown-item/dropdown-item.vue +209 -207
  62. package/dist/dropdown-item/props.ts +4 -4
  63. package/dist/dropdown-item/type.ts +3 -3
  64. package/dist/dropdown-menu/dropdown-menu.vue +93 -99
  65. package/dist/empty/empty.vue +43 -42
  66. package/dist/fab/fab.vue +88 -86
  67. package/dist/footer/footer.vue +36 -34
  68. package/dist/form/README.en-US.md +17 -24
  69. package/dist/form/README.md +18 -25
  70. package/dist/form/form.css +1 -166
  71. package/dist/form/form.vue +251 -236
  72. package/dist/form/props.ts +2 -21
  73. package/dist/form/type.ts +7 -70
  74. package/dist/form-item/README.en-US.md +4 -5
  75. package/dist/form-item/README.md +4 -5
  76. package/dist/form-item/form-item.css +69 -96
  77. package/dist/form-item/form-item.vue +315 -336
  78. package/dist/form-item/form-model.ts +125 -173
  79. package/dist/form-item/props.ts +4 -17
  80. package/dist/form-item/type.ts +43 -1
  81. package/dist/grid/grid.vue +53 -51
  82. package/dist/grid-item/grid-item.vue +121 -119
  83. package/dist/guide/README.md +1 -1
  84. package/dist/guide/guide.vue +281 -277
  85. package/dist/icon/README.md +2 -4
  86. package/dist/icon/icon.vue +78 -76
  87. package/dist/image/README.md +1 -1
  88. package/dist/image/image.vue +103 -101
  89. package/dist/image-viewer/image-viewer.vue +160 -158
  90. package/dist/image-viewer/props.ts +2 -2
  91. package/dist/image-viewer/type.ts +1 -1
  92. package/dist/index.js +3 -0
  93. package/dist/indexes/indexes.vue +264 -267
  94. package/dist/indexes-anchor/indexes-anchor.vue +41 -41
  95. package/dist/input/input.vue +192 -192
  96. package/dist/input/props.ts +6 -6
  97. package/dist/input/type.ts +3 -3
  98. package/dist/link/link.vue +73 -71
  99. package/dist/loading/loading.vue +59 -59
  100. package/dist/locale/ar_KW.ts +157 -0
  101. package/dist/locale/en_US.ts +146 -0
  102. package/dist/locale/it_IT.ts +145 -0
  103. package/dist/locale/ja_JP.ts +132 -0
  104. package/dist/locale/ko_KR.ts +132 -0
  105. package/dist/locale/ru_RU.ts +157 -0
  106. package/dist/locale/zh_CN.ts +133 -0
  107. package/dist/locale/zh_TW.ts +132 -0
  108. package/dist/message/message.vue +181 -173
  109. package/dist/message/props.ts +2 -2
  110. package/dist/message/type.ts +1 -1
  111. package/dist/message-item/message-item.vue +192 -184
  112. package/dist/mixins/using-config.js +39 -0
  113. package/dist/navbar/navbar.vue +201 -199
  114. package/dist/notice-bar/notice-bar.vue +175 -171
  115. package/dist/notice-bar/props.ts +2 -2
  116. package/dist/notice-bar/type.ts +1 -1
  117. package/dist/npm/dayjs/esm/locale/ar.js +81 -0
  118. package/dist/npm/dayjs/esm/locale/it.js +39 -0
  119. package/dist/overlay/overlay.vue +50 -48
  120. package/dist/picker/picker.vue +168 -161
  121. package/dist/picker-item/picker-item.vue +269 -269
  122. package/dist/popover/README.md +1 -1
  123. package/dist/popover/popover.vue +262 -261
  124. package/dist/popover/props.ts +4 -4
  125. package/dist/popover/type.ts +2 -2
  126. package/dist/popup/popup.vue +46 -45
  127. package/dist/progress/README.md +1 -1
  128. package/dist/progress/progress.vue +76 -76
  129. package/dist/pull-down-refresh/props.ts +2 -2
  130. package/dist/pull-down-refresh/pull-down-refresh.vue +240 -234
  131. package/dist/pull-down-refresh/type.ts +1 -1
  132. package/dist/qrcode/README.md +1 -1
  133. package/dist/qrcode/components/qrcode-canvas/qrcode-canvas.vue +340 -338
  134. package/dist/qrcode/components/qrcode-status/qrcode-status.vue +6 -6
  135. package/dist/qrcode/qrcode.vue +93 -87
  136. package/dist/radio/props.ts +6 -6
  137. package/dist/radio/radio.vue +118 -120
  138. package/dist/radio/type.ts +3 -3
  139. package/dist/radio-group/props.ts +4 -4
  140. package/dist/radio-group/radio-group.vue +136 -134
  141. package/dist/radio-group/type.ts +4 -4
  142. package/dist/rate/computed.js +2 -2
  143. package/dist/rate/props.ts +4 -4
  144. package/dist/rate/rate.vue +155 -154
  145. package/dist/rate/type.ts +2 -2
  146. package/dist/result/result.vue +41 -39
  147. package/dist/row/row.vue +38 -36
  148. package/dist/scroll-view/scroll-view.vue +24 -22
  149. package/dist/search/props.ts +2 -2
  150. package/dist/search/search.vue +127 -125
  151. package/dist/search/type.ts +1 -1
  152. package/dist/side-bar/side-bar.vue +57 -55
  153. package/dist/side-bar-item/side-bar-item.vue +86 -86
  154. package/dist/skeleton/skeleton.vue +126 -124
  155. package/dist/slider/README.md +1 -1
  156. package/dist/slider/props.ts +2 -2
  157. package/dist/slider/slider.vue +457 -457
  158. package/dist/slider/type.ts +1 -1
  159. package/dist/step-item/step-item.vue +77 -75
  160. package/dist/stepper/props.ts +2 -2
  161. package/dist/stepper/stepper.vue +168 -149
  162. package/dist/stepper/type.ts +1 -1
  163. package/dist/steps/props.ts +2 -2
  164. package/dist/steps/steps.vue +83 -81
  165. package/dist/steps/type.ts +1 -1
  166. package/dist/sticky/sticky.vue +104 -102
  167. package/dist/swipe-cell/swipe-cell.vue +91 -89
  168. package/dist/swiper/README.md +1 -1
  169. package/dist/swiper/swiper.vue +91 -89
  170. package/dist/swiper-nav/swiper-nav.vue +38 -36
  171. package/dist/switch/props.ts +2 -2
  172. package/dist/switch/switch.vue +62 -62
  173. package/dist/switch/type.ts +1 -1
  174. package/dist/tab-bar/tab-bar.vue +88 -86
  175. package/dist/tab-bar-item/tab-bar-item.vue +85 -82
  176. package/dist/tab-panel/tab-panel.vue +66 -64
  177. package/dist/tabs/tabs.vue +294 -287
  178. package/dist/tag/tag.vue +79 -77
  179. package/dist/textarea/props.ts +6 -6
  180. package/dist/textarea/textarea.vue +127 -126
  181. package/dist/textarea/type.ts +3 -3
  182. package/dist/toast/toast.vue +107 -106
  183. package/dist/transition/transition.vue +30 -28
  184. package/dist/tree-select/tree-select.vue +151 -151
  185. package/dist/types/config-provider.d.ts +7 -0
  186. package/dist/types/index.d.ts +2 -0
  187. package/dist/types/popover.d.ts +7 -0
  188. package/dist/upload/README.en-US.md +13 -14
  189. package/dist/upload/README.md +11 -12
  190. package/dist/upload/props.ts +2 -4
  191. package/dist/upload/type.ts +12 -11
  192. package/dist/upload/upload.css +1 -1
  193. package/dist/upload/upload.vue +672 -512
  194. package/dist/watermark/watermark.vue +151 -149
  195. package/global.d.ts +2 -0
  196. package/package.json +15 -3
  197. package/dist/form/form-item-props.ts +0 -56
@@ -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 uniComponent({
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
- props: {
175
- ...props,
176
- },
177
- emits: [
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
- dataValue(name) {
191
- if (name !== this.getCurrentName()) {
192
- this.setCurrentIndexByName(name);
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
- created() {
197
- this.children = this.children || [];
198
- },
199
-
200
- mounted() {
201
- nextTick().then(() => {
202
- this.setTrack();
203
- });
204
- getRect(this, `.${name}`).then((rect) => {
205
- this.containerWidth = rect.width;
206
- });
207
- this.tabID = getUniqueID();
208
- },
209
- data() {
210
- return {
211
- prefix,
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
- onScroll(e = {}) {
251
- const { scrollLeft } = e.detail || {};
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
- tabs.forEach((item) => {
264
- if (typeof item.icon === 'string') {
265
- item.icon = { name: item.icon };
266
- }
201
+ mounted() {
202
+ nextTick().then(() => {
203
+ this.setTrack();
267
204
  });
268
-
269
- this.tabs = tabs;
270
- if (typeof cb === 'function') {
271
- setTimeout(cb, 33);
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
- setCurrentIndexByName(name) {
278
- const { children } = this;
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
- setCurrentIndex(index) {
286
- if (index <= -1 || index >= this.children.length) return;
287
- const Labels = [];
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
- const { currentIndex, currentLabels } = this;
297
- if (currentIndex === index && currentLabels.join('') === Labels.join('')) return;
275
+ this.setCurrentIndexByName(this.dataValue);
276
+ },
298
277
 
299
- this.currentIndex = index;
300
- this.currentLabels = Labels;
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
- setTimeout(() => {
304
- this.setTrack();
305
- }, 33);
306
- },
302
+ const { currentIndex, currentLabels } = this;
303
+ if (currentIndex === index && currentLabels.join('') === Labels.join('')) return;
307
304
 
308
- getCurrentName() {
309
- if (this.children) {
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
- getTabHeight() {
323
- return getRect(this, `.${name}`);
324
- },
309
+ setTimeout(() => {
310
+ this.setTrack();
311
+ }, 33);
312
+ },
325
313
 
326
- getTrackSize() {
327
- const { bottomLineMode } = this;
328
- const targetMap = {
329
- fixed: `.${prefix}-tabs__track`,
330
- auto: `.${prefix}-tabs__item--active .${prefix}-tabs__item-inner`,
331
- full: `.${prefix}-tabs__item--active`,
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
- getRect(this, targetMap[bottomLineMode] || targetMap.fixed)
339
- .then((res) => {
340
- if (res) {
341
- resolve(res.width);
342
- }
343
- })
344
- .catch(reject);
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
- async setTrack() {
349
- const { children } = this;
350
- if (!children) return;
351
- const { currentIndex } = this;
352
- if (currentIndex <= -1) return;
353
-
354
- try {
355
- const res = await getRect(this, `.${prefix}-tabs__item`, true);
356
- const rect = res[currentIndex];
357
- if (!rect) return;
358
- let count = 0;
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
- totalSize += item.width;
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
- if (this.containerWidth) {
371
- const offset = this.calcScrollOffset(this.containerWidth, rect.left, rect.width, this.scrollLeft);
372
- const maxOffset = totalSize - this.containerWidth;
373
- this.offset = Math.min(Math.max(offset, 0), maxOffset);
374
- } else if (!this._hasObserved) {
375
- this._hasObserved = true;
376
- getObserver(this, `.${name}`).then(() => this.setTrack());
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
- const lineWidth = await this.getTrackSize();
380
- if (this.theme === 'line') {
381
- distance += (rect.width - lineWidth) / 2;
382
- }
385
+ const lineWidth = await this.getTrackSize();
386
+ if (this.theme === 'line') {
387
+ distance += (rect.width - lineWidth) / 2;
388
+ }
383
389
 
384
- const isInit = this.previousIndex === undefined;
385
- if (isInit
390
+ const isInit = this.previousIndex === undefined;
391
+ if (isInit
386
392
  || this.previousIndex !== currentIndex
387
393
  || this.lastDistance !== distance
388
- ) {
389
- this.previousIndex = currentIndex;
390
- this.trackOption = { lineWidth, distance, isInit };
391
- this.lastDistance = distance;
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
- } catch (err) {
394
- this.$emit('error', err);
395
- }
396
- },
402
+ },
397
403
 
398
- onTabTap(event) {
399
- const { index } = event.currentTarget.dataset;
404
+ onTabTap(event) {
405
+ const { index } = event.currentTarget.dataset;
400
406
 
401
- this.changeIndex(index);
402
- },
407
+ this.changeIndex(index);
408
+ },
403
409
 
404
- onTouchStart(event) {
405
- if (!this.swipeable) return;
410
+ onTouchStart(event) {
411
+ if (!this.swipeable) return;
406
412
 
407
- this.touchStart(event);
408
- },
413
+ this.touchStart(event);
414
+ },
409
415
 
410
- onTouchMove(event) {
411
- if (!this.swipeable) return;
416
+ onTouchMove(event) {
417
+ if (!this.swipeable) return;
412
418
 
413
- this.touchMove(event);
414
- },
419
+ this.touchMove(event);
420
+ },
415
421
 
416
- onTouchEnd() {
417
- if (!this.swipeable) return;
422
+ onTouchEnd() {
423
+ if (!this.swipeable) return;
418
424
 
419
- const { direction, deltaX, offsetX } = this;
420
- const minSwipeDistance = 50;
421
- if (direction === 'horizontal' && offsetX >= minSwipeDistance) {
422
- const index = this.getAvailableTabIndex(deltaX);
423
- if (index !== -1) {
424
- this.changeIndex(index);
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
- onTouchScroll(event) {
430
- this._trigger('scroll', event);
431
- },
435
+ onTouchScroll(event) {
436
+ this._trigger('scroll', event);
437
+ },
432
438
 
433
- changeIndex(index) {
434
- const currentTab = this.tabs[index];
435
- const { value, label } = currentTab;
436
- if (!currentTab?.disabled && index !== this.currentIndex) {
437
- this._trigger('change', { value, label });
438
- }
439
- this._trigger('click', { value, label });
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
- getAvailableTabIndex(deltaX) {
443
- const step = deltaX > 0 ? -1 : 1;
444
- const { currentIndex, tabs } = this;
445
- const len = tabs.length;
446
- for (let i = step; currentIndex + step >= 0 && currentIndex + step < len; i += step) {
447
- const newIndex = currentIndex + i;
448
- if (newIndex >= 0 && newIndex < len && tabs[newIndex]) {
449
- if (!tabs[newIndex].disabled) {
450
- return newIndex;
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
- return -1;
457
- },
462
+ return -1;
463
+ },
458
464
 
459
- getBadgeCustomStyle(item, index) {
460
- if (item.disabled) {
461
- 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))))';
462
- }
463
- if (this.currentIndex === index) {
464
- return '--td-badge-content-text-color: var(--td-tab-item-active-color, var(--td-brand-color, var(--td-primary-color-7, #0052d9)));';
465
- }
466
- return '';
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
- getIconCustomStyle(item) {
470
- return tools._style([
471
- {
472
- fontSize: 'var(--td-tab-icon-size, 18px)',
473
- marginRight: 'calc(var(--td-spacer, 8px) / 4)',
474
- },
475
- item.icon.style || '',
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>