Blame view

build/Form/Form.js 2.12 KB
3a3ecabe   Imshann   init
1
2
3
4
5
6
7
8
9
10
11
12
13
  import template from "./Form.html";
  import style from "antd/lib/form/style/index.css";
  angular.module("esNgAntd").directive("esForm", function (esNgAntd) {
      return {
          controllerAs: "esForm",
          restrict: "E",
          transclude: true,
          replace: true,
          scope: {
              name: "@",
              labelCol: "=",
              wrapperCol: "=",
              onFinish: "&",
dd962f77   Imshann   优化
14
              form: "=",
3a3ecabe   Imshann   init
15
16
          },
          template: template,
061629e7   Imshann   add
17
          controller: function ($scope, $element, $attrs) {
3a3ecabe   Imshann   init
18
19
20
21
              this.getContext = function () {
                  return $scope;
              };
  
dd962f77   Imshann   优化
22
23
24
25
26
27
              $scope.state = {
                  formItems: [],
              };
  
              $scope.resetFields = function () {
                  $scope.state.formItems.forEach(function (item) {
a468667f   Imshann   优化
28
29
30
31
32
                      if (typeof item.setValue === "function") {
                          item.setValue(item.defaultValue || null);
                      } else {
                          item.value = null;
                      }
dd962f77   Imshann   优化
33
34
                  });
              };
3a3ecabe   Imshann   init
35
  
061629e7   Imshann   add
36
37
38
39
              $scope.submit = function () {
                  $scope.handleSubmit();
              };
  
3a3ecabe   Imshann   init
40
41
              $scope.handleSubmit = function () {
                  let values = {};
dd962f77   Imshann   优化
42
43
44
45
                  $scope.state.formItems.forEach(function (item) {
                      let name = item.esFormItem && item.esFormItem.name;
                      let value = item.value || item.state.value || null;
                      values[name] = value;
061629e7   Imshann   add
46
                  });
3a3ecabe   Imshann   init
47
48
49
50
51
52
53
                  $scope.onFinish({
                      values: values,
                  });
              };
          },
          link: function ($scope, $element, $attrs, $controllers, $transclude) {
              esNgAntd.createStyle("ant-form", style);
3a3ecabe   Imshann   init
54
  
4b23b387   Imshann   feat(pagination):...
55
56
57
58
              if ($scope.form !== undefined) {
                  $scope.form = $scope;
              }
  
3a3ecabe   Imshann   init
59
60
61
62
63
64
65
66
67
68
69
              if ($scope.name) {
                  let inputs = $element[0].querySelectorAll("input");
  
                  for (let i = 0; i < inputs.length; i++) {
                      const element = inputs[i];
                      element.id = $scope.name + "_" + element.id;
                  }
              }
          },
      };
  });