riku
2025-04-27 233a467167e2b363098cc7fa63e7f26d1d15507b
miniprogram_npm/tdesign-miniprogram/indexes/indexes.js
@@ -30,17 +30,15 @@
                type: 'child',
            },
        };
        this.behaviors = [
            pageScrollMixin(function (event) {
                this.onScroll(event);
            }),
        ];
        this.behaviors = [pageScrollMixin()];
        this.timer = null;
        this.groupTop = [];
        this.sidebar = null;
        this.currentTouchAnchor = null;
        this.observers = {
            indexList(v) {
                this.setIndexList(v);
                this.setHeight(this.data._height);
            },
            height(v) {
                this.setHeight(v);
@@ -48,11 +46,13 @@
        };
        this.lifetimes = {
            ready() {
                var _a;
                this.timer = null;
                this.groupTop = [];
                this.sidebar = null;
                if (this.data._height === 0) {
                    this.setHeight();
                }
                if (((_a = this.data._indexList) === null || _a === void 0 ? void 0 : _a.length) === 0) {
                if (this.data.indexList === null) {
                    this.setIndexList();
                }
            },
@@ -128,22 +128,21 @@
                }
            },
            setAnchorByIndex(index) {
                if (this.preIndex != null && this.preIndex === index)
                    return;
                const { _indexList } = this.data;
                const { _indexList, stickyOffset } = this.data;
                const activeAnchor = _indexList[index];
                if (this.data.activeAnchor !== null && this.data.activeAnchor === activeAnchor)
                    return;
                const target = this.groupTop.find((item) => item.anchor === activeAnchor);
                if (target) {
                    this.currentTouchAnchor = activeAnchor;
                    const scrollTop = target.top - stickyOffset;
                    wx.pageScrollTo({
                        scrollTop: target.top,
                        scrollTop,
                        duration: 0,
                    });
                }
                this.preIndex = index;
                this.toggleTips(true);
                this.triggerEvent('select', { index: activeAnchor });
                if (activeAnchor !== this.data.activeAnchor) {
                    this.triggerEvent('change', { index: activeAnchor });
                    this.toggleTips(true);
                    this.triggerEvent('select', { index: activeAnchor });
                    this.setData({ activeAnchor });
                }
            },
            onClick(e) {
@@ -178,37 +177,46 @@
                if (!this.groupTop) {
                    return;
                }
                const { sticky, stickyOffset } = this.data;
                const { sticky, stickyOffset, activeAnchor } = this.data;
                scrollTop += stickyOffset;
                const curIndex = this.groupTop.findIndex((group) => scrollTop >= group.top - group.height && scrollTop <= group.top + group.totalHeight - group.height);
                if (curIndex === -1)
                    return;
                const curGroup = this.groupTop[curIndex];
                if (this.data.activeAnchor !== curGroup.anchor) {
                if (this.currentTouchAnchor !== null) {
                    this.triggerEvent('change', { index: curGroup.anchor });
                    this.currentTouchAnchor = null;
                }
                this.setData({
                    activeAnchor: curGroup.anchor,
                });
                else if (activeAnchor !== curGroup.anchor) {
                    this.triggerEvent('change', { index: curGroup.anchor });
                    this.setData({ activeAnchor: curGroup.anchor });
                }
                if (sticky) {
                    const offset = curGroup.top - scrollTop;
                    const betwixt = offset < curGroup.height && offset > 0 && scrollTop > stickyOffset;
                    this.$children.forEach((child, index) => {
                        if (index === curIndex) {
                            child.setData({
                                sticky: scrollTop > stickyOffset,
                                active: true,
                                style: `height: ${curGroup.height}px`,
                                anchorStyle: `transform: translate3d(0, ${betwixt ? offset : 0}px, 0); top: ${stickyOffset}px`,
                            });
                            const sticky = scrollTop > stickyOffset;
                            const anchorStyle = `transform: translate3d(0, ${betwixt ? offset : 0}px, 0); top: ${stickyOffset}px`;
                            if (anchorStyle !== child.data.anchorStyle || sticky !== child.data.sticky) {
                                child.setData({
                                    sticky,
                                    active: true,
                                    style: `height: ${curGroup.height}px`,
                                    anchorStyle,
                                });
                            }
                        }
                        else if (index + 1 === curIndex) {
                            child.setData({
                                sticky: true,
                                active: true,
                                style: `height: ${curGroup.height}px`,
                                anchorStyle: `transform: translate3d(0, ${betwixt ? offset - curGroup.height : 0}px, 0); top: ${stickyOffset}px`,
                            });
                            const anchorStyle = `transform: translate3d(0, ${betwixt ? offset - curGroup.height : 0}px, 0); top: ${stickyOffset}px`;
                            if (anchorStyle !== child.data.anchorStyle) {
                                child.setData({
                                    sticky: true,
                                    active: true,
                                    style: `height: ${curGroup.height}px`,
                                    anchorStyle,
                                });
                            }
                        }
                        else {
                            child.setData({ active: false, sticky: false, anchorStyle: '' });