Blame view

build/FormItem/FormItem.js 1.83 KB
3a3ecabe   Imshann   init
1
2
3
4
5
6
7
8
9
10
11
  /**
   * 表单域
   *
   * @Author: Shann
   * @LastEditors: Shann
   * @Date: 2021-07-26 08:53:33
   * @LastEditTime: 2021-08-05 14:03:05
   * @FilePath: \angular-js-for-bootstrap\src\Essa\FormItem\FormItem.js
   * @Copyright: Copyright 2021-2021, all rights reserved. Essa.cn
   */
  import template from "./FormItem.html";
81f8a467   Imshann   调整组件前缀
12
  angular.module("esNgAntd").directive("antdFormItem", function () {
3a3ecabe   Imshann   init
13
      return {
81f8a467   Imshann   调整组件前缀
14
          controllerAs: "antdFormItem",
3a3ecabe   Imshann   init
15
16
17
18
19
20
21
22
23
24
25
          restrict: "E",
          transclude: true,
          replace: true,
          scope: {
              name: "@",
              label: "@",
              labelCol: "=",
              wrapperCol: "=",
              required: "@",
          },
          template: template,
81f8a467   Imshann   调整组件前缀
26
          controller: function ($scope, $element, $attrs) {
3a3ecabe   Imshann   init
27
28
29
30
31
32
33
34
35
              this.getContext = function () {
                  return $scope;
              };
  
              $scope.state = {
                  labelCol: null,
                  wrapperCol: null,
              };
          },
81f8a467   Imshann   调整组件前缀
36
          require: ["?^antdForm"],
3a3ecabe   Imshann   init
37
          link: function ($scope, $element, $attrs, $controllers, $transclude) {
81f8a467   Imshann   调整组件前缀
38
39
              let [antdForm] = $controllers;
              $scope.antdForm = antdForm.getContext();
3a3ecabe   Imshann   init
40
41
42
  
              if ($scope.labelCol && $scope.labelCol.span) {
                  $scope.state.labelCol = $scope.labelCol.span;
81f8a467   Imshann   调整组件前缀
43
44
45
46
47
              } else if (
                  $scope.antdForm.labelCol &&
                  $scope.antdForm.labelCol.span
              ) {
                  $scope.state.labelCol = $scope.antdForm.labelCol.span;
3a3ecabe   Imshann   init
48
49
50
51
52
              }
  
              if ($scope.wrapperCol && $scope.wrapperCol.span) {
                  $scope.state.wrapperCol = $scope.wrapperCol.span;
              } else if (
81f8a467   Imshann   调整组件前缀
53
54
                  $scope.antdForm.wrapperCol &&
                  $scope.antdForm.wrapperCol.span
3a3ecabe   Imshann   init
55
              ) {
81f8a467   Imshann   调整组件前缀
56
                  $scope.state.wrapperCol = $scope.antdForm.wrapperCol.span;
3a3ecabe   Imshann   init
57
58
59
60
              }
          },
      };
  });