Blame view

build/TabPane/TabPane.js 1.66 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
  import template from "./TabPane.html";
  angular.module("esNgAntd").directive("esTabPane", function () {
      return {
          controllerAs: "esTabPane",
          restrict: "E",
          transclude: true,
          replace: true,
          scope: {
              key: "@",
              tab: "@",
          },
          template: template,
          controller: function ($scope, $element) {
              this.getContext = function () {
                  return $scope;
              };
  
              $scope.state = {
                  activeKey: null,
                  key: $scope.key,
              };
              $scope.watch = {
                  tab: function (newVal, oldVal) {
                      if (newVal !== oldVal) {
                          let item = $scope.esTabs.state.labels.find(function (
                              item
                          ) {
                              return item.key === $scope.key;
                          });
  
                          if (item) {
                              item.name = newVal;
                          }
                      }
                  },
              };
  
              for (const key in $scope.watch) {
                  $scope.$watch(key, $scope.watch[key], true);
              }
          },
          require: ["?^esTabs"],
          link: function ($scope, $element, $attrs, $controllers, $transclude) {
              let [esTabs] = $controllers;
              $scope.esTabs = esTabs.getContext();
              $scope.esTabs.state.labels.push({
                  name: $scope.tab,
                  key: $scope.key,
              });
              $scope.esTabs.state.childrens.push($scope);
              $scope.state.activeKey = $scope.esTabs.state.activeKey;
          },
      };
  });