From 0746b7bbe6aa3d9f02e03654a2cd4fde2081c335 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期一, 21 四月 2025 09:29:40 +0800 Subject: [PATCH] bug修复 --- miniprogram_npm/tdesign-miniprogram/tabs/tabs.js | 32 ++++++++++++++++++++++++-------- 1 files changed, 24 insertions(+), 8 deletions(-) diff --git a/miniprogram_npm/tdesign-miniprogram/tabs/tabs.js b/miniprogram_npm/tdesign-miniprogram/tabs/tabs.js index efd4715..232d87f 100644 --- a/miniprogram_npm/tdesign-miniprogram/tabs/tabs.js +++ b/miniprogram_npm/tdesign-miniprogram/tabs/tabs.js @@ -24,6 +24,9 @@ let Tabs = class Tabs extends SuperComponent { constructor() { super(...arguments); + this.options = { + pureDataPattern: /^currentLabels$/, + }; this.behaviors = [touch]; this.externalClasses = [ `${prefix}-class`, @@ -66,9 +69,11 @@ prefix, classPrefix: name, tabs: [], + currentLabels: [], currentIndex: -1, trackStyle: '', offset: 0, + scrollLeft: 0, tabID: '', placement: 'top', }; @@ -92,7 +97,7 @@ onScroll(e) { const { scrollLeft } = e.detail; this.setData({ - offset: scrollLeft, + scrollLeft, }); }, updateTabs(cb) { @@ -116,18 +121,23 @@ setCurrentIndex(index) { if (index <= -1 || index >= this.children.length) return; + const Labels = []; this.children.forEach((child, idx) => { const isActive = index === idx; if (isActive !== child.data.active) { child.render(isActive, this); } + Labels.push(child.data.label); }); - if (this.data.currentIndex === index) + const { currentIndex, currentLabels } = this.data; + if (currentIndex === index && currentLabels.join('') === Labels.join('')) return; this.setData({ currentIndex: index, + currentLabels: Labels, + }, () => { + this.setTrack(); }); - this.setTrack(); }, getCurrentName() { if (this.children) { @@ -139,6 +149,9 @@ }, calcScrollOffset(containerWidth, targetLeft, targetWidth, offset) { return offset + targetLeft - (1 / 2) * containerWidth + targetWidth / 2; + }, + getTabHeight() { + return getRect(this, `.${name}`); }, getTrackSize() { return new Promise((resolve, reject) => { @@ -158,8 +171,6 @@ }, setTrack() { return __awaiter(this, void 0, void 0, function* () { - if (!this.properties.showBottomLine) - return; const { children } = this; if (!children) return; @@ -182,7 +193,7 @@ totalSize += item.width; }); if (this.containerWidth) { - const offset = this.calcScrollOffset(this.containerWidth, rect.left, rect.width, this.data.offset); + const offset = this.calcScrollOffset(this.containerWidth, rect.left, rect.width, this.data.scrollLeft); const maxOffset = totalSize - this.containerWidth; this.setData({ offset: Math.min(Math.max(offset, 0), maxOffset), @@ -246,8 +257,13 @@ const len = tabs.length; for (let i = step; currentIndex + step >= 0 && currentIndex + step < len; i += step) { const newIndex = currentIndex + i; - if (newIndex >= 0 && newIndex < len && tabs[newIndex] && !tabs[newIndex].disabled) { - return newIndex; + if (newIndex >= 0 && newIndex < len && tabs[newIndex]) { + if (!tabs[newIndex].disabled) { + return newIndex; + } + } + else { + return currentIndex; } } return -1; -- Gitblit v1.9.3