Blame view

build/ImagePreviewGroup/ImagePreviewGroup.js 5.16 KB
3a3ecabe   Imshann   init
1
  import template from "./ImagePreviewGroup.html";
9dc592c0   Imshann   升级Image和ImagePrev...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  angular.module("esNgAntd").directive("antdImagePreviewGroup", ["esNgAntd", function (esNgAntd) {
    return {
      template: template,
      restrict: "E",
      replace: true,
      transclude: true,
      scope: {
        preview: "="
      },
      controller: function ($scope, $element, $attrs) {
        $scope.state = {
          current: 0,
          visible: false,
          src: null,
          childrens: []
        };
3a3ecabe   Imshann   init
18
  
9dc592c0   Imshann   升级Image和ImagePrev...
19
20
21
22
23
24
25
26
27
        $scope.addChildren = function (children) {
          [children].forEach(function (value, key) {
            if ([undefined, null, ""].includes(value)) {
              throw new Error(`${["children"][key]} parameter of addChildren method is required.`);
            }
          });
          $scope.state.childrens.push(children);
          return $scope.state.childrens.length - 1;
        };
1b6f912f   Imshann   优化
28
  
9dc592c0   Imshann   升级Image和ImagePrev...
29
30
31
32
33
34
35
        $scope.setCurrent = function (value) {
          [value].forEach(function (value, key) {
            if ([undefined, null, ""].includes(value)) {
              throw new Error(`${["value"][key]} parameter of setCurrent method is required.`);
            }
          });
          $scope.state.current = value;
1b6f912f   Imshann   优化
36
  
9dc592c0   Imshann   升级Image和ImagePrev...
37
38
39
40
          if (typeof $scope.preview === "object" && typeof $scope.preview.onCurrentChange === "function") {
            $scope.preview.onCurrentChange(value);
          }
        };
4c519425   Imshann   优化图片组件
41
  
9dc592c0   Imshann   升级Image和ImagePrev...
42
43
44
45
46
47
48
        $scope.setVisible = function (value) {
          [value].forEach(function (value, key) {
            if ([undefined, null, ""].includes(value)) {
              throw new Error(`${["value"][key]} parameter of setVisible method is required.`);
            }
          });
          $scope.state.visible = value;
4c519425   Imshann   优化图片组件
49
  
9dc592c0   Imshann   升级Image和ImagePrev...
50
51
52
53
          if (typeof $scope.preview === "object" && typeof $scope.preview.onVisibleChange === "function") {
            $scope.preview.onVisibleChange(value);
          }
        };
4c519425   Imshann   优化图片组件
54
  
9dc592c0   Imshann   升级Image和ImagePrev...
55
56
57
58
59
60
61
62
63
64
        $scope.handleOpen = function (index) {
          [index].forEach(function (value, key) {
            if ([undefined, null, ""].includes(value)) {
              throw new Error(`${["index"][key]} parameter of handleOpen method is required.`);
            }
          });
          $scope.setCurrent(index);
          $scope.state.src = $scope.state.childrens[index].state.src;
          $scope.setVisible(true);
        };
4c519425   Imshann   优化图片组件
65
  
9dc592c0   Imshann   升级Image和ImagePrev...
66
67
68
        $scope.handleClose = function () {
          $scope.setVisible(false);
        };
1b6f912f   Imshann   优化
69
  
9dc592c0   Imshann   升级Image和ImagePrev...
70
71
72
73
        $scope.handlePrev = function () {
          $scope.setCurrent($scope.state.current > 0 ? $scope.state.current - 1 : 0);
          $scope.state.src = $scope.state.childrens[$scope.state.current].state.src;
        };
1b6f912f   Imshann   优化
74
  
9dc592c0   Imshann   升级Image和ImagePrev...
75
76
77
78
        $scope.handleNext = function () {
          $scope.setCurrent($scope.state.current < $scope.state.childrens.length - 1 ? $scope.state.current + 1 : $scope.state.childrens.length - 1);
          $scope.state.src = $scope.state.childrens[$scope.state.current].state.src;
        };
1b6f912f   Imshann   优化
79
  
9dc592c0   Imshann   升级Image和ImagePrev...
80
81
        $scope.handlePreview = function () {
          let className;
1b6f912f   Imshann   优化
82
  
9dc592c0   Imshann   升级Image和ImagePrev...
83
84
85
          if ($attrs.class) {
            className = ` ${$attrs.class}`;
          }
4c519425   Imshann   优化图片组件
86
  
9dc592c0   Imshann   升级Image和ImagePrev...
87
          esNgAntd.createLayer(`
4c519425   Imshann   优化图片组件
88
              <div class="ant-image-preview-root${className}">
1b6f912f   Imshann   优化
89
90
91
92
93
94
95
96
                  <div class="ant-image-preview-mask" ng-if="state.visible"></div>
                  <div class="ant-image-preview-wrap" ng-show="state.visible">
                      <div class="ant-image-preview">
                          <div class="ant-image-preview-content">
                              <div class="ant-image-preview-body">
                                  <ul class="ant-image-preview-operations">
                                      <li class="ant-image-preview-operations-operation">
                                          <span class="anticon anticon-close ant-image-preview-operations-icon" ng-click="handleClose()">
81f8a467   Imshann   调整组件前缀
97
                                              <antd-icon type="CloseOutlined"></antd-icon>
1b6f912f   Imshann   优化
98
99
100
101
102
103
104
                                          </span>
                                      </li> 
                                  </ul>
                                  <div class="ant-image-preview-img-wrapper">
                                      <img class="ant-image-preview-img" ng-src="{{state.src}}"/>
                                  </div>
                                  <div ng-class="{'ant-image-preview-switch-left': true, 'ant-image-preview-switch-left-disabled': state.current===0}" ng-click="handlePrev()">
81f8a467   Imshann   调整组件前缀
105
                                      <antd-icon type="LeftOutlined"></antd-icon>
1b6f912f   Imshann   优化
106
107
                                  </div>
                                  <div ng-class="{'ant-image-preview-switch-right': true,'ant-image-preview-switch-right-disabled': (state.childrens.length-1)===state.current}"  ng-click="handleNext()">
81f8a467   Imshann   调整组件前缀
108
                                      <antd-icon type="RightOutlined"></antd-icon>
1b6f912f   Imshann   优化
109
110
111
112
113
114
                                  </div>
                              </div>
                          </div>
                      </div>
                  </div>
              </div>
9dc592c0   Imshann   升级Image和ImagePrev...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
          `, $scope);
        };
  
        this.getContext = function () {
          return $scope;
        };
      },
      link: function ($scope, $element, $attrs) {
        [$element, $attrs].forEach(function (value, key) {
          if ([undefined, null, ""].includes(value)) {
            throw new Error(`${["$element", "$attrs"][key]} parameter of constructor method is required.`);
          }
        });
        $scope.handlePreview();
      }
    };
  }]);