Blame view

src/Form/Form.js 1.6 KB
3a3ecabe   Imshann   init
1
2
3
4
5
6
  import template from "./Form.html";
  import style from "antd/lib/form/style/index.css";
  
  class Form {
      useModules = ["esNgAntd"];
  
dd962f77   Imshann   优化
7
8
      template = template;
  
3a3ecabe   Imshann   init
9
10
11
12
13
      props = {
          name: String,
          labelCol: Object,
          wrapperCol: Object,
          onFinish: Function,
dd962f77   Imshann   优化
14
15
16
17
          form: Object,
      };
  
      state = {
a468667f   Imshann   优化
18
          formItems: [],
3a3ecabe   Imshann   init
19
      };
3a3ecabe   Imshann   init
20
21
22
  
      constructor() {
          esNgAntd.createStyle("ant-form", style);
4b23b387   Imshann   feat(pagination):...
23
24
25
26
  
          if (this.form !== undefined) {
              this.form = $scope;
          }
2c0a9da3   Imshann   优化
27
          
3a3ecabe   Imshann   init
28
29
30
31
32
33
34
35
36
          if (this.props.name) {
              let inputs = $element[0].querySelectorAll("input");
              for (let i = 0; i < inputs.length; i++) {
                  const element = inputs[i];
                  element.id = this.props.name + "_" + element.id;
              }
          }
      }
  
dd962f77   Imshann   优化
37
38
      resetFields() {
          this.state.formItems.forEach(function (item) {
a468667f   Imshann   优化
39
40
41
42
43
44
              if (typeof item.setValue === "function") {
                  item.setValue(item.defaultValue || null);
              } else {
                  item.value = null;
              }
          });
dd962f77   Imshann   优化
45
46
      }
  
061629e7   Imshann   add
47
48
49
50
      submit() {
          this.handleSubmit();
      }
  
3a3ecabe   Imshann   init
51
52
      handleSubmit() {
          let values = {};
dd962f77   Imshann   优化
53
          this.state.formItems.forEach(function (item) {
81f8a467   Imshann   调整组件前缀
54
              let name = item.antdFormItem && item.antdFormItem.name;
fe17acf4   Imshann   优化组件
55
56
57
58
59
60
              let value = null;
              if (item.state.type === "checkbox") {
                  value = item.state.checked;
              } else {
                  value = item.value || item.state.value
              }
dd962f77   Imshann   优化
61
              values[name] = value;
a468667f   Imshann   优化
62
          });
3a3ecabe   Imshann   init
63
64
65
66
67
          this.props.onFinish({
              values: values,
          });
      }
  }