riku
2024-08-14 b4033c002e21c1376d68be61622da56182a962e9
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;