Blame view

build/TabPane/TabPane.js 1.69 KB
3a3ecabe   Imshann   init
1
  import template from "./TabPane.html";
81f8a467   Imshann   调整组件前缀
2
  angular.module("esNgAntd").directive("antdTabPane", function () {
3a3ecabe   Imshann   init
3
      return {
81f8a467   Imshann   调整组件前缀
4
          controllerAs: "antdTabPane",
3a3ecabe   Imshann   init
5
6
7
8
9
10
11
12
          restrict: "E",
          transclude: true,
          replace: true,
          scope: {
              key: "@",
              tab: "@",
          },
          template: template,
81f8a467   Imshann   调整组件前缀
13
          controller: function ($scope, $element, $attrs) {
3a3ecabe   Imshann   init
14
15
16
17
18
19
20
21
22
23
24
              this.getContext = function () {
                  return $scope;
              };
  
              $scope.state = {
                  activeKey: null,
                  key: $scope.key,
              };
              $scope.watch = {
                  tab: function (newVal, oldVal) {
                      if (newVal !== oldVal) {
81f8a467   Imshann   调整组件前缀
25
                          let item = $scope.antdTabs.state.labels.find(function (
3a3ecabe   Imshann   init
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
                              item
                          ) {
                              return item.key === $scope.key;
                          });
  
                          if (item) {
                              item.name = newVal;
                          }
                      }
                  },
              };
  
              for (const key in $scope.watch) {
                  $scope.$watch(key, $scope.watch[key], true);
              }
          },
81f8a467   Imshann   调整组件前缀
42
          require: ["?^antdTabs"],
3a3ecabe   Imshann   init
43
          link: function ($scope, $element, $attrs, $controllers, $transclude) {
81f8a467   Imshann   调整组件前缀
44
45
46
              let [antdTabs] = $controllers;
              $scope.antdTabs = antdTabs.getContext();
              $scope.antdTabs.state.labels.push({
3a3ecabe   Imshann   init
47
48
49
                  name: $scope.tab,
                  key: $scope.key,
              });
81f8a467   Imshann   调整组件前缀
50
51
              $scope.antdTabs.state.childrens.push($scope);
              $scope.state.activeKey = $scope.antdTabs.state.activeKey;
3a3ecabe   Imshann   init
52
53
54
          },
      };
  });