Blame view

src/FormItem/FormItem.js 1.22 KB
3a3ecabe   Imshann   init
1
2
  /**
   * 表单域
3a3ecabe   Imshann   init
3
4
5
6
   */
  import template from "./FormItem.html";
  
  class FormItem {
50f4289a   Imshann   优化Form组件
7
8
9
10
11
  
      require = ["^?antdForm"];
  
      context = true;
  
3a3ecabe   Imshann   init
12
13
14
15
16
      state = {
          labelCol: null,
          wrapperCol: null,
      };
  
50f4289a   Imshann   优化Form组件
17
18
      constructor($element, $attrs, $controllers) {
          let [antdForm] = $controllers;
3a3ecabe   Imshann   init
19
  
50f4289a   Imshann   优化Form组件
20
21
22
          if (antdForm) {
              this.antdForm = antdForm.getContext();
          }
3a3ecabe   Imshann   init
23
24
25
26
  
          if (this.props.labelCol && this.props.labelCol.span) {
              this.state.labelCol = this.props.labelCol.span; 
          } else if (
81f8a467   Imshann   调整组件前缀
27
28
              this.antdForm.labelCol &&
              this.antdForm.labelCol.span
3a3ecabe   Imshann   init
29
          ) {
81f8a467   Imshann   调整组件前缀
30
              this.state.labelCol = this.antdForm.labelCol.span;
3a3ecabe   Imshann   init
31
32
33
34
35
          }
  
          if (this.props.wrapperCol && this.props.wrapperCol.span) {
              this.state.wrapperCol = this.props.wrapperCol.span;
          } else if (
81f8a467   Imshann   调整组件前缀
36
37
              this.antdForm.wrapperCol &&
              this.antdForm.wrapperCol.span
3a3ecabe   Imshann   init
38
          ) {
81f8a467   Imshann   调整组件前缀
39
              this.state.wrapperCol = this.antdForm.wrapperCol.span;
3a3ecabe   Imshann   init
40
41
          }
      }
50f4289a   Imshann   优化Form组件
42
43
44
45
  
      render() {
          return template;
      }
3a3ecabe   Imshann   init
46
  }
50f4289a   Imshann   优化Form组件
47
48
49
50
51
52
53
54
  
  FormItem.propTypes = {
      name: PropTypes.string,
      label: PropTypes.string,
      labelCol: PropTypes.object,
      wrapperCol: PropTypes.object,
      required: PropTypes.boolean,
  };