ImagePreviewGroup.js
4.21 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import template from "./ImagePreviewGroup.html";
angular
.module("esNgAntd")
.directive("esImagePreviewGroup", function (esNgAntd) {
return {
controllerAs: "esImagePreviewGroup",
restrict: "E",
transclude: true,
replace: true,
template: template,
controller: function ($scope, $element) {
this.getContext = function () {
return $scope;
};
$scope.state = {
current: 0,
visible: false,
src: null,
childrens: [],
};
$scope.addChildren = function (children) {
$scope.state.childrens.push(children);
return $scope.state.childrens.length - 1;
};
$scope.handleOpen = function (index) {
$scope.state.current = index;
$scope.state.src = $scope.state.childrens[index].state.src;
$scope.state.visible = true;
};
$scope.handleClose = function () {
$scope.state.visible = false;
};
$scope.handlePrev = function () {
$scope.state.current =
$scope.state.current > 0 ? $scope.state.current - 1 : 0;
$scope.state.src =
$scope.state.childrens[$scope.state.current].state.src;
};
$scope.handleNext = function () {
$scope.state.current =
$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;
};
$scope.handlePreview = function () {
esNgAntd.createLayer(
`
<div class="ant-image-preview-root">
<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()">
<es-icon type="CloseOutlined"></es-icon>
</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()">
<es-icon type="LeftOutlined"></es-icon>
</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()">
<es-icon type="RightOutlined"></es-icon>
</div>
</div>
</div>
</div>
</div>
</div>
`,
$scope
);
};
},
link: function (
$scope,
$element,
$attrs,
$controllers,
$transclude
) {
$scope.handlePreview();
},
};
});