vdesign-ui 0.2.14 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/tabs/index.vue +61 -35
- package/dist/token.css +1332 -1332
- package/dist/vdesign-ui.common.js +72 -45
- package/dist/vdesign-ui.css +1 -1
- package/dist/vdesign-ui.umd.js +72 -45
- package/dist/vdesign-ui.umd.min.js +2 -2
- package/package.json +2 -2
|
@@ -208,44 +208,61 @@ export default {
|
|
|
208
208
|
if (tab.disabled) {
|
|
209
209
|
this.$emit('disabled', tab.name !== undefined ? tab.name : index, index);
|
|
210
210
|
} else {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
211
|
+
const newName = tab.name !== undefined ? tab.name : index;
|
|
212
|
+
|
|
213
|
+
// 始终触发 click 事件
|
|
214
|
+
this.$emit('click', newName, index);
|
|
215
|
+
|
|
216
|
+
// 检查是否需要切换标签
|
|
217
|
+
if (newName !== this.currentName) {
|
|
218
|
+
this.currentName = newName;
|
|
219
|
+
|
|
220
|
+
// 如果 currentName 是索引值,确保为数字类型
|
|
221
|
+
if (tab.name === undefined) {
|
|
222
|
+
this.currentName = Number(this.currentName);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
this.$emit('input', this.currentName);
|
|
226
|
+
this.$emit('change', this.currentName, index); // 仅在切换时触发 change 事件
|
|
227
|
+
|
|
228
|
+
// 切换标签后,滚动到当前标签
|
|
229
|
+
this.$nextTick(() => {
|
|
230
|
+
this.scrollToActiveTab();
|
|
231
|
+
});
|
|
215
232
|
}
|
|
216
|
-
this.$emit('input', this.currentName);
|
|
217
|
-
this.$emit('change', this.currentName, index);
|
|
218
|
-
// 切换标签后,滚动到当前标签
|
|
219
|
-
this.$nextTick(() => {
|
|
220
|
-
this.scrollToActiveTab();
|
|
221
|
-
});
|
|
222
233
|
}
|
|
223
234
|
},
|
|
224
|
-
scrollToActiveTab() {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
235
|
+
scrollToActiveTab(targetIndex = null) {
|
|
236
|
+
const scrollWrapper = this.$refs.nav;
|
|
237
|
+
const tabItems = this.$refs.tabItems;
|
|
238
|
+
if (!scrollWrapper || !tabItems || tabItems.length === 0) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
// 如果传入 targetIndex,设置当前激活标签的 name
|
|
242
|
+
if (targetIndex !== null) {
|
|
243
|
+
const targetTab = this.tabs[targetIndex];
|
|
244
|
+
if (targetTab) {
|
|
245
|
+
this.currentName = targetTab.name !== undefined ? targetTab.name : targetIndex;
|
|
246
|
+
} else {
|
|
247
|
+
console.warn('Invalid target index:', targetIndex);
|
|
229
248
|
return;
|
|
230
249
|
}
|
|
250
|
+
}
|
|
231
251
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
const activeTab = tabItems[activeIndex];
|
|
237
|
-
|
|
238
|
-
if (activeTab) {
|
|
239
|
-
const tabOffsetLeft = activeTab.offsetLeft;
|
|
240
|
-
const tabWidth = activeTab.offsetWidth;
|
|
241
|
-
const wrapperWidth = scrollWrapper.offsetWidth;
|
|
242
|
-
const scrollLeft = tabOffsetLeft - (wrapperWidth - tabWidth) / 2;
|
|
252
|
+
const activeIndex = targetIndex !== null ? targetIndex : this.tabs.findIndex((tab, index) => this.isTabActive(tab, index));
|
|
253
|
+
const activeTab = tabItems[activeIndex];
|
|
243
254
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
255
|
+
setTimeout(() => {
|
|
256
|
+
const tabOffsetLeft = activeTab.offsetLeft;
|
|
257
|
+
const tabWidth = activeTab.offsetWidth;
|
|
258
|
+
const wrapperWidth = scrollWrapper.offsetWidth;
|
|
259
|
+
const scrollLeft = tabOffsetLeft - (wrapperWidth - tabWidth) / 2;
|
|
260
|
+
|
|
261
|
+
scrollWrapper.scrollTo({
|
|
262
|
+
left: scrollLeft,
|
|
263
|
+
behavior: 'smooth'
|
|
264
|
+
});
|
|
265
|
+
}, 0); // You can adjust the timeout value if needed
|
|
249
266
|
},
|
|
250
267
|
renderTitle(titleEl, tab) {
|
|
251
268
|
this.$nextTick(() => {
|
|
@@ -261,17 +278,26 @@ export default {
|
|
|
261
278
|
}
|
|
262
279
|
});
|
|
263
280
|
},
|
|
264
|
-
|
|
281
|
+
/**
|
|
265
282
|
* resize 方法
|
|
266
283
|
* 当外层元素大小或组件显示状态变化时调用,触发重绘
|
|
267
|
-
|
|
268
|
-
|
|
284
|
+
*/
|
|
285
|
+
resize() {
|
|
269
286
|
// 重新计算当前激活标签的位置
|
|
270
287
|
this.scrollToActiveTab();
|
|
271
|
-
|
|
272
288
|
// 如果有其他需要重绘或重新计算的逻辑,可以在这里添加
|
|
273
289
|
// 例如,重新计算动画轨道的位置等
|
|
274
290
|
},
|
|
291
|
+
/**
|
|
292
|
+
* scrollTo 方法
|
|
293
|
+
* 刷新页面,滚动到指定位置
|
|
294
|
+
*/
|
|
295
|
+
scrollTo(targetIndex = null){
|
|
296
|
+
// 重新计算当前激活标签的位置
|
|
297
|
+
this.scrollToActiveTab(targetIndex);
|
|
298
|
+
// 如果有其他需要重绘或重新计算的逻辑,可以在这里添加
|
|
299
|
+
// 例如,重新计算动画轨道的位置等
|
|
300
|
+
}
|
|
275
301
|
},
|
|
276
302
|
mounted() {
|
|
277
303
|
if (this.currentName !== undefined) {
|