riku
2022-09-15 bd3a9d7086f5a428b385599ba2cb08299b22c0df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// component/switchtab/switchtab.js
Component({
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
    extClass: {
      type: String,
      value: ''
    },
    extClassOn: {
      type: String,
      value: ''
    },
    tabList: {
      type: Array,
      value: []
    },
    //通知组件刷新高度
    refresh: {
      type: Boolean,
      value: false,
      observer: 'refreshHeight'
    },
  },
 
  /**
   * 组件的初始数据
   */
  data: {
    //选项卡相关
    currentTab: 0,
    // pageheight: '600px',
  },
 
  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(); //必须要先创建一个查询
      query.select(element).boundingClientRect(function (rect) {
        that.setData({
          pageheight: rect.height + 'px'
        });
      }).exec();
    },
    swichNav: function (e) {
      var that = this;
      if (this.data.currentTab === e.target.dataset.current) {
        return false;
      } else {
        that.setData({
          currentTab: e.target.dataset.current,
        })
      }
    },
    bindChange: function (e) {
      var that = this;
      that.setData({
        currentTab: e.detail.current,
      });
      that.tabsHeight('.page' + e.detail.current); //查询哪一个元素
      this.triggerEvent('tabchange', this.data.currentTab)
    },
  }
})