Blame view

build/Input/Input.js 3.27 KB
3a3ecabe   Imshann   init
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
  import style from "antd/lib/input/style/index.css";
  angular.module("esNgAntd").directive("esInput", function ($compile, esNgAntd) {
      return {
          controllerAs: "esInput",
          restrict: "E",
          transclude: true,
          replace: true,
          scope: {
              value: "@",
              placeholder: "@",
              addonBefore: "@",
              addonAfter: "@",
              disabled: "@",
              onChange: "&",
              maxLength: "@",
          },
          controller: function ($scope, $element) {
              this.getContext = function () {
                  return $scope;
              };
  
              $scope.state = {
                  inputEventTarget: null,
              };
  
              $scope.handleClick = function (event) {
                  $scope.state.inputEventTarget = event;
              };
  
              $scope.handleChange = function () {
                  $scope.onChange({
                      event: $scope.state.inputEventTarget,
                  });
              };
  
              $scope.getTemplate = function () {
                  let maxLengthAttribute = "";
                  let styleAttribute = "";
                  let idAttribute = "";
  
                  if ($scope.maxLength) {
                      maxLengthAttribute = `maxlength="${$scope.maxLength}"`;
                  }
  
                  if ($scope.style) {
                      styleAttribute = `style="${$scope.style}"`;
                  }
  
                  if ($scope.esFormItem && $scope.esFormItem.name) {
                      idAttribute = `id="${$scope.esFormItem.name}"`;
                  }
  
                  let templates = [
                      `<input type="text" class="ant-input" placeholder={{placeholder}} ng-change="handleChange()" ng-model="value" ng-focus="handleClick($event)" ng-disabled="disabled==='true'" ${styleAttribute} ${maxLengthAttribute} ${idAttribute}/>`,
                      `<span class="ant-input-group-wrapper" ng-if="addonBefore||addonAfter">
          <span class="ant-input-wrapper ant-input-group" style="">
              <span class="ant-input-group-addon" ng-if="addonBefore">{{addonBefore}}</span>
              <input type="text" class="ant-input" ng-change="handleChange()" ng-model="value" ng-focus="handleClick($event)" ng-disabled="disabled==='true'" style="${$scope.style}" ${styleAttribute} ${maxLengthAttribute} ${idAttribute}/>
              <span class="ant-input-group-addon" ng-if="addonAfter">{{addonAfter}}</span>
          </span>
      </span>`,
                  ];
  
                  if ($scope.addonBefore || $scope.addonAfter) {
                      return templates[1];
                  } else {
                      return templates[0];
                  }
              };
          },
dd962f77   Imshann   优化
71
          require: ["?^esFormItem", "?^esForm"],
3a3ecabe   Imshann   init
72
          link: function ($scope, $element, $attrs, $controllers, $transclude) {
dd962f77   Imshann   优化
73
              let [esFormItem, esForm] = $controllers;
1b6f912f   Imshann   优化
74
75
76
77
78
79
80
81
82
83
84
              esNgAntd.createStyle("ant-input", style); // 上下文
  
              if (esForm) {
                  $scope.esForm = esForm.getContext();
                  $scope.esForm.state.formItems.push($scope);
              }
  
              if (esFormItem) {
                  $scope.esFormItem = esFormItem.getContext();
              }
  
3a3ecabe   Imshann   init
85
              $scope.style = $attrs.style;
3a3ecabe   Imshann   init
86
87
88
89
              $element.replaceWith($compile($scope.getTemplate())($scope));
          },
      };
  });