riku
2026-01-20 91f7d372fa318e859efd20d71eafbd34274902c4
component/switchtab/switchtab.js
@@ -8,13 +8,23 @@
   * 组件的属性列表
   */
  properties: {
    extClass: {
      type: String,
      value: ''
    },
    extClassOn: {
      type: String,
      value: ''
    },
    tabList: {
      type: Array,
      value: []
    },
    pageList: {
      type: Array,
      value: []
    //通知组件刷新高度
    refresh: {
      type: Boolean,
      value: false,
      observer: 'refreshHeight'
    },
  },
@@ -27,34 +37,36 @@
    // pageheight: '600px',
  },
  observers: {
    'pageList': function() {
      this.tabsHeight('.page0');
    }
  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show: function () {
      // this.refreshHeight(true)
    },
    hide: function () { },
    resize: function () {
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    refreshHeight: function(e) {
      // console.log(`refreshHeight: ${e}`);
      if (e) {
        setTimeout(() => {
          const p = `.page${this.data.currentTab}`
          // console.log(p);
          this.tabsHeight(p);
        }, 50);
      }
    },
    //计算swiper高度方法(在切换的时候调用)
    tabsHeight(element) {
      let that = this;
      let query = this.createSelectorQuery(); //必须要先创建一个查询
      let query = this.createSelectorQuery().in(this); //必须要先创建一个查询
      query.select(element).boundingClientRect(function (rect) {
        // if (that.data.pageheight) {
        //   let pageheight = that.data.pageheight.split('px')[0]
        //   pageheight = parseInt(pageheight)
        //   if (rect.height > pageheight) {
        //     that.setData({
        //       pageheight: rect.height + 'px'
        //     });
        //   }
        // } else {
        //   that.setData({
        //     pageheight: rect.height + 'px'
        //   });
        // }
        that.setData({
          pageheight: rect.height + 'px'
        });
@@ -67,18 +79,16 @@
      } else {
        that.setData({
          currentTab: e.target.dataset.current,
          navScrollLeft: e.target.dataset.current >= 3 ? ((e.target.dataset.current) * 60) : 0 //判断当前选中的个数是否是第5个
        })
        // that.tabsHeight('.page' + e.target.dataset.current); //查询哪一个元素
      }
    },
    bindChange: function (e) {
      var that = this;
      that.setData({
        currentTab: e.detail.current,
        navScrollLeft: e.detail.current >= 3 ? ((e.detail.current) * 60) : 0 //判断当前选中的个数是否是第5个
      });
      that.tabsHeight('.page' + e.detail.current); //查询哪一个元素
      that.tabsHeight('.page' + e.detail.current); //查询哪一个元素
      this.triggerEvent('tabchange', this.data.currentTab)
    },
  }
})