riku
2025-04-27 f46786f11c5c08ead7501a82e5a71430ad69b782
miniprogram_npm/tdesign-miniprogram/navbar/navbar.js
@@ -5,6 +5,7 @@
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { SuperComponent, wxComponent } from '../common/src/index';
import { getRect } from '../common/utils';
import config from '../common/config';
import props from './props';
const { prefix } = config;
@@ -14,6 +15,8 @@
        super(...arguments);
        this.externalClasses = [
            `${prefix}-class`,
            `${prefix}-class-placeholder`,
            `${prefix}-class-content`,
            `${prefix}-class-title`,
            `${prefix}-class-left`,
            `${prefix}-class-center`,
@@ -24,7 +27,6 @@
        ];
        this.timer = null;
        this.options = {
            addGlobalClass: true,
            multipleSlots: true,
        };
        this.properties = props;
@@ -62,8 +64,35 @@
            classPrefix: name,
            boxStyle: '',
            showTitle: '',
            hideLeft: false,
            hideCenter: false,
        };
        this.methods = {
            queryElements(capsuleRect) {
                Promise.all([
                    getRect(this, `.${this.data.classPrefix}__left`),
                    getRect(this, `.${this.data.classPrefix}__center`),
                ]).then(([leftRect, centerRect]) => {
                    if (leftRect.right > capsuleRect.left) {
                        this.setData({
                            hideLeft: true,
                            hideCenter: true,
                        });
                    }
                    else if (centerRect.right > capsuleRect.left) {
                        this.setData({
                            hideLeft: false,
                            hideCenter: true,
                        });
                    }
                    else {
                        this.setData({
                            hideLeft: false,
                            hideCenter: false,
                        });
                    }
                });
            },
            goBack() {
                const { delta } = this.data;
                const that = this;
@@ -95,23 +124,30 @@
        wx.getSystemInfo({
            success: (res) => {
                const boxStyleList = [];
                const { statusBarHeight } = wx.getSystemInfoSync();
                boxStyleList.push(`--td-navbar-padding-top:${statusBarHeight}px`);
                boxStyleList.push(`--td-navbar-padding-top: ${res.statusBarHeight}px`);
                if (rect && (res === null || res === void 0 ? void 0 : res.windowWidth)) {
                    boxStyleList.push(`--td-navbar-right:${res.windowWidth - rect.left}px`);
                    boxStyleList.push(`--td-navbar-right: ${res.windowWidth - rect.left}px`);
                }
                boxStyleList.push(`--td-navbar-capsule-height: ${rect.height}px`);
                boxStyleList.push(`--td-navbar-capsule-width: ${rect.width}px`);
                boxStyleList.push(`--td-navbar-height: ${(rect.top - statusBarHeight) * 2 + rect.height}px`);
                boxStyleList.push(`--td-navbar-height: ${(rect.top - res.statusBarHeight) * 2 + rect.height}px`);
                this.setData({
                    boxStyle: `${boxStyleList.join('; ')}`,
                });
                if (wx.onMenuButtonBoundingClientRectWeightChange) {
                    wx.onMenuButtonBoundingClientRectWeightChange((res) => this.queryElements(res));
                }
            },
            fail: (err) => {
                console.error('navbar 获取系统信息失败', err);
            },
        });
    }
    detached() {
        if (wx.offMenuButtonBoundingClientRectWeightChange) {
            wx.offMenuButtonBoundingClientRectWeightChange((res) => this.queryElements(res));
        }
    }
};
Navbar = __decorate([
    wxComponent()