Blame view

build/FormItem/FormItem.js 1.75 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
  /**
   * 表单域
   *
   * @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";
  angular.module("esNgAntd").directive("esFormItem", function () {
      return {
          controllerAs: "esFormItem",
          restrict: "E",
          transclude: true,
          replace: true,
          scope: {
              name: "@",
              label: "@",
              labelCol: "=",
              wrapperCol: "=",
              required: "@",
          },
          template: template,
          controller: function ($scope, $element) {
              this.getContext = function () {
                  return $scope;
              };
  
              $scope.state = {
                  labelCol: null,
                  wrapperCol: null,
              };
          },
          require: ["?^esForm"],
          link: function ($scope, $element, $attrs, $controllers, $transclude) {
              let [esForm] = $controllers;
              $scope.esForm = esForm.getContext();
  
              if ($scope.labelCol && $scope.labelCol.span) {
                  $scope.state.labelCol = $scope.labelCol.span;
              } else if ($scope.esForm.labelCol && $scope.esForm.labelCol.span) {
                  $scope.state.labelCol = $scope.esForm.labelCol.span;
              }
  
              if ($scope.wrapperCol && $scope.wrapperCol.span) {
                  $scope.state.wrapperCol = $scope.wrapperCol.span;
              } else if (
                  $scope.esForm.wrapperCol &&
                  $scope.esForm.wrapperCol.span
              ) {
                  $scope.state.wrapperCol = $scope.esForm.wrapperCol.span;
              }
          },
      };
  });