Blame view

src/TabPane/TabPane.js 1.08 KB
3a3ecabe   Imshann   init
1
2
3
  import template from "./TabPane.html";
  
  class TabPane {
6674355b   Imshann   优化选项阿凯
4
5
  
      require = ["^antdTabs"];
3a3ecabe   Imshann   init
6
7
8
9
10
11
  
      state = {
          activeKey: null,
          key: this.props.key,
      };
  
6674355b   Imshann   优化选项阿凯
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
      constructor($element, $attrs, $controllers) {
          let [antdTabs] = $controllers;
  
          if (antdTabs) {
              this.antdTabs = antdTabs.getContext();
              this.antdTabs.state.labels.push({
                  name: this.props.tab,
                  key: this.props.key,
              });
              this.antdTabs.state.childrens.push($scope);
              this.state.activeKey = this.antdTabs.state.activeKey;
          }
      }
  
      componentDidUpdate(prevProps) {
          if (prevProps.tab !== this.props.tab) {
              if (newVal) {
81f8a467   Imshann   调整组件前缀
29
                  let item = this.antdTabs.state.labels.find(function (item) {
3a3ecabe   Imshann   init
30
31
32
33
34
35
                      return item.key === this.props.key;
                  });
                  if (item) {
                      item.name = newVal;
                  }
              }
6674355b   Imshann   优化选项阿凯
36
37
          }
      }
3a3ecabe   Imshann   init
38
  
6674355b   Imshann   优化选项阿凯
39
40
      render() {
          return template;
3a3ecabe   Imshann   init
41
42
      }
  }
6674355b   Imshann   优化选项阿凯
43
44
45
46
47
  
  TabPane.propTypes = {
      key: PropTypes.string,
      tab: PropTypes.string,
  }