|
@@ -1,34 +1,34 @@
|
1
|
|
-'use strict';
|
|
1
|
+"use strict";
|
2
|
2
|
|
3
|
3
|
Object.defineProperty(exports, "__esModule", {
|
4
|
|
- value: true
|
|
4
|
+ value: true
|
5
|
5
|
});
|
6
|
6
|
|
7
|
|
-var _spin = require('antd/es/spin');
|
|
7
|
+var _spin = require("antd/es/spin");
|
8
|
8
|
|
9
|
9
|
var _spin2 = _interopRequireDefault(_spin);
|
10
|
10
|
|
11
|
|
-var _icon = require('antd/es/icon');
|
|
11
|
+var _icon = require("antd/es/icon");
|
12
|
12
|
|
13
|
13
|
var _icon2 = _interopRequireDefault(_icon);
|
14
|
14
|
|
15
|
15
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
16
|
16
|
|
17
|
|
-require('antd/es/spin/style/css');
|
|
17
|
+require("antd/es/spin/style/css");
|
18
|
18
|
|
19
|
|
-require('antd/es/icon/style/css');
|
|
19
|
+require("antd/es/icon/style/css");
|
20
|
20
|
|
21
|
|
-var _react = require('react');
|
|
21
|
+var _react = require("react");
|
22
|
22
|
|
23
|
23
|
var _react2 = _interopRequireDefault(_react);
|
24
|
24
|
|
25
|
|
-var _classnames = require('classnames');
|
|
25
|
+var _classnames = require("classnames");
|
26
|
26
|
|
27
|
27
|
var _classnames2 = _interopRequireDefault(_classnames);
|
28
|
28
|
|
29
|
|
-require('./ImagePreviewer.css');
|
|
29
|
+require("./ImagePreviewer.css");
|
30
|
30
|
|
31
|
|
-var _helper = require('../../helper');
|
|
31
|
+var _helper = require("../../helper");
|
32
|
32
|
|
33
|
33
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
34
|
34
|
|
|
@@ -39,204 +39,204 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
39
|
39
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
40
|
40
|
|
41
|
41
|
var ImagePreviewer = function (_React$Component) {
|
42
|
|
- _inherits(ImagePreviewer, _React$Component);
|
43
|
|
-
|
44
|
|
- function ImagePreviewer(props) {
|
45
|
|
- _classCallCheck(this, ImagePreviewer);
|
46
|
|
-
|
47
|
|
- var _this = _possibleConstructorReturn(this, (ImagePreviewer.__proto__ || Object.getPrototypeOf(ImagePreviewer)).call(this, props));
|
48
|
|
-
|
49
|
|
- _this.setIndex = _this.setIndex.bind(_this);
|
50
|
|
- _this.onPrev = _this.onPrev.bind(_this);
|
51
|
|
- _this.onNext = _this.onNext.bind(_this);
|
52
|
|
- _this.onOrigin = _this.onOrigin.bind(_this);
|
53
|
|
- _this.rotateLeft = _this.rotateLeft.bind(_this);
|
54
|
|
- _this.rotateRight = _this.rotateRight.bind(_this);
|
55
|
|
- _this.onImgLoad = _this.onImgLoad.bind(_this);
|
56
|
|
- _this.onImageError = _this.onImageError.bind(_this);
|
57
|
|
- _this.state = {
|
58
|
|
- cIndex: props.index,
|
59
|
|
- direction: 0, // 0- 0deg 1- 90deg 2- 180deg 3- 270deg
|
60
|
|
- loading: false
|
61
|
|
- };
|
62
|
|
- return _this;
|
|
42
|
+ _inherits(ImagePreviewer, _React$Component);
|
|
43
|
+
|
|
44
|
+ function ImagePreviewer(props) {
|
|
45
|
+ _classCallCheck(this, ImagePreviewer);
|
|
46
|
+
|
|
47
|
+ var _this = _possibleConstructorReturn(this, (ImagePreviewer.__proto__ || Object.getPrototypeOf(ImagePreviewer)).call(this, props));
|
|
48
|
+
|
|
49
|
+ _this.setIndex = _this.setIndex.bind(_this);
|
|
50
|
+ _this.onPrev = _this.onPrev.bind(_this);
|
|
51
|
+ _this.onNext = _this.onNext.bind(_this);
|
|
52
|
+ _this.onOrigin = _this.onOrigin.bind(_this);
|
|
53
|
+ _this.rotateLeft = _this.rotateLeft.bind(_this);
|
|
54
|
+ _this.rotateRight = _this.rotateRight.bind(_this);
|
|
55
|
+ _this.onImgLoad = _this.onImgLoad.bind(_this);
|
|
56
|
+ _this.onImageError = _this.onImageError.bind(_this);
|
|
57
|
+ _this.state = {
|
|
58
|
+ cIndex: props.index,
|
|
59
|
+ direction: 0, // 0- 0deg 1- 90deg 2- 180deg 3- 270deg
|
|
60
|
+ loading: false
|
|
61
|
+ };
|
|
62
|
+ return _this;
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ _createClass(ImagePreviewer, [{
|
|
66
|
+ key: "componentWillReceiveProps",
|
|
67
|
+ value: function componentWillReceiveProps(nextProps) {
|
|
68
|
+ if (nextProps.index !== this.props.index) {
|
|
69
|
+ this.setIndex(nextProps.index);
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+ }, {
|
|
73
|
+ key: "onPrev",
|
|
74
|
+ value: function onPrev() {
|
|
75
|
+ var prev = this.state.cIndex === 0 ? this.props.list.length - 1 : this.state.cIndex - 1;
|
|
76
|
+ this.setIndex(prev);
|
|
77
|
+ }
|
|
78
|
+ }, {
|
|
79
|
+ key: "onNext",
|
|
80
|
+ value: function onNext() {
|
|
81
|
+ var next = this.state.cIndex === this.props.list.length - 1 ? 0 : this.state.cIndex + 1;
|
|
82
|
+ this.setIndex(next);
|
|
83
|
+ }
|
|
84
|
+ }, {
|
|
85
|
+ key: "onOrigin",
|
|
86
|
+ value: function onOrigin() {
|
|
87
|
+ window.open(this.props.list[this.state.cIndex]);
|
|
88
|
+ }
|
|
89
|
+ }, {
|
|
90
|
+ key: "onImgLoad",
|
|
91
|
+ value: function onImgLoad() {
|
|
92
|
+ this.setState({
|
|
93
|
+ loading: false
|
|
94
|
+ });
|
|
95
|
+ }
|
|
96
|
+ }, {
|
|
97
|
+ key: "onImageError",
|
|
98
|
+ value: function onImageError() {
|
|
99
|
+ this.setState({
|
|
100
|
+ loading: false
|
|
101
|
+ });
|
|
102
|
+ }
|
|
103
|
+ }, {
|
|
104
|
+ key: "setIndex",
|
|
105
|
+ value: function setIndex(index) {
|
|
106
|
+ this.setState({
|
|
107
|
+ cIndex: index,
|
|
108
|
+ direction: 0,
|
|
109
|
+ loading: true
|
|
110
|
+ });
|
|
111
|
+ }
|
|
112
|
+ }, {
|
|
113
|
+ key: "rotateLeft",
|
|
114
|
+ value: function rotateLeft() {
|
|
115
|
+ var direction = this.state.direction - 1;
|
|
116
|
+ if (direction === -1) {
|
|
117
|
+ direction = 3;
|
|
118
|
+ }
|
|
119
|
+ this.setState({
|
|
120
|
+ direction: direction
|
|
121
|
+ });
|
|
122
|
+ }
|
|
123
|
+ }, {
|
|
124
|
+ key: "rotateRight",
|
|
125
|
+ value: function rotateRight() {
|
|
126
|
+ var direction = this.state.direction + 1;
|
|
127
|
+ if (direction === 4) {
|
|
128
|
+ direction = 0;
|
|
129
|
+ }
|
|
130
|
+ this.setState({
|
|
131
|
+ direction: direction
|
|
132
|
+ });
|
63
|
133
|
}
|
64
|
134
|
|
65
|
|
- _createClass(ImagePreviewer, [{
|
66
|
|
- key: 'componentWillReceiveProps',
|
67
|
|
- value: function componentWillReceiveProps(nextProps) {
|
68
|
|
- if (nextProps.index !== this.props.index) {
|
69
|
|
- this.setIndex(nextProps.index);
|
70
|
|
- }
|
71
|
|
- }
|
72
|
|
- }, {
|
73
|
|
- key: 'onPrev',
|
74
|
|
- value: function onPrev() {
|
75
|
|
- var prev = this.state.cIndex === 0 ? this.props.list.length - 1 : this.state.cIndex - 1;
|
76
|
|
- this.setIndex(prev);
|
77
|
|
- }
|
78
|
|
- }, {
|
79
|
|
- key: 'onNext',
|
80
|
|
- value: function onNext() {
|
81
|
|
- var next = this.state.cIndex === this.props.list.length - 1 ? 0 : this.state.cIndex + 1;
|
82
|
|
- this.setIndex(next);
|
83
|
|
- }
|
84
|
|
- }, {
|
85
|
|
- key: 'onOrigin',
|
86
|
|
- value: function onOrigin() {
|
87
|
|
- window.open(this.props.list[this.state.cIndex]);
|
88
|
|
- }
|
89
|
|
- }, {
|
90
|
|
- key: 'onImgLoad',
|
91
|
|
- value: function onImgLoad() {
|
92
|
|
- this.setState({
|
93
|
|
- loading: false
|
94
|
|
- });
|
95
|
|
- }
|
96
|
|
- }, {
|
97
|
|
- key: 'onImageError',
|
98
|
|
- value: function onImageError() {
|
99
|
|
- this.setState({
|
100
|
|
- loading: false
|
101
|
|
- });
|
102
|
|
- }
|
103
|
|
- }, {
|
104
|
|
- key: 'setIndex',
|
105
|
|
- value: function setIndex(index) {
|
106
|
|
- this.setState({
|
107
|
|
- cIndex: index,
|
108
|
|
- direction: 0,
|
109
|
|
- loading: true
|
110
|
|
- });
|
111
|
|
- }
|
112
|
|
- }, {
|
113
|
|
- key: 'rotateLeft',
|
114
|
|
- value: function rotateLeft() {
|
115
|
|
- var direction = this.state.direction - 1;
|
116
|
|
- if (direction === -1) {
|
117
|
|
- direction = 3;
|
118
|
|
- }
|
119
|
|
- this.setState({
|
120
|
|
- direction: direction
|
121
|
|
- });
|
122
|
|
- }
|
123
|
|
- }, {
|
124
|
|
- key: 'rotateRight',
|
125
|
|
- value: function rotateRight() {
|
126
|
|
- var direction = this.state.direction + 1;
|
127
|
|
- if (direction === 4) {
|
128
|
|
- direction = 0;
|
129
|
|
- }
|
130
|
|
- this.setState({
|
131
|
|
- direction: direction
|
132
|
|
- });
|
133
|
|
- }
|
134
|
|
-
|
135
|
|
- // calcHeight(node) {
|
136
|
|
- // const { naturalHeight, naturalWidth } = node;
|
137
|
|
- // }
|
138
|
|
-
|
139
|
|
- }, {
|
140
|
|
- key: 'render',
|
141
|
|
- value: function render() {
|
142
|
|
- var _this2 = this;
|
143
|
|
-
|
144
|
|
- var _props = this.props,
|
145
|
|
- list = _props.list,
|
146
|
|
- onFold = _props.onFold;
|
147
|
|
- var cIndex = this.state.cIndex;
|
148
|
|
-
|
|
135
|
+ // calcHeight(node) {
|
|
136
|
+ // const { naturalHeight, naturalWidth } = node;
|
|
137
|
+ // }
|
|
138
|
+
|
|
139
|
+ }, {
|
|
140
|
+ key: "render",
|
|
141
|
+ value: function render() {
|
|
142
|
+ var _this2 = this;
|
|
143
|
+
|
|
144
|
+ var _props = this.props,
|
|
145
|
+ list = _props.list,
|
|
146
|
+ onFold = _props.onFold;
|
|
147
|
+ var cIndex = this.state.cIndex;
|
|
148
|
+
|
|
149
|
+ return _react2.default.createElement(
|
|
150
|
+ "div",
|
|
151
|
+ { className: "container" },
|
|
152
|
+ _react2.default.createElement(
|
|
153
|
+ "div",
|
|
154
|
+ { className: "toolbar" },
|
|
155
|
+ _react2.default.createElement(
|
|
156
|
+ "span",
|
|
157
|
+ { className: "button", onClick: onFold },
|
|
158
|
+ _react2.default.createElement(_icon2.default, { type: "to-top" }),
|
|
159
|
+ "\u6536\u8D77"
|
|
160
|
+ ),
|
|
161
|
+ _react2.default.createElement(
|
|
162
|
+ "span",
|
|
163
|
+ { className: "button", onClick: this.onOrigin },
|
|
164
|
+ _react2.default.createElement(_icon2.default, { type: "search" }),
|
|
165
|
+ " \u67E5\u770B\u539F\u56FE"
|
|
166
|
+ )
|
|
167
|
+ ),
|
|
168
|
+ _react2.default.createElement(
|
|
169
|
+ "div",
|
|
170
|
+ { className: "pictureWrapper" },
|
|
171
|
+ _react2.default.createElement(
|
|
172
|
+ _spin2.default,
|
|
173
|
+ { spinning: this.state.loading },
|
|
174
|
+ _react2.default.createElement("img", {
|
|
175
|
+ // ref={node => {
|
|
176
|
+ // if (node) {
|
|
177
|
+ // this.calcHeight(node);
|
|
178
|
+ // }
|
|
179
|
+ // }}
|
|
180
|
+ className: "picture",
|
|
181
|
+ src: (0, _helper.addImageProcess)(list[cIndex], { large: true }),
|
|
182
|
+ alt: list[cIndex],
|
|
183
|
+ style: {
|
|
184
|
+ transform: "rotate(" + this.state.direction * 90 + "deg)",
|
|
185
|
+ opacity: this.state.loading ? 0 : 1,
|
|
186
|
+ transition: "0.3s opacity"
|
|
187
|
+ },
|
|
188
|
+ onLoad: this.onImgLoad,
|
|
189
|
+ onError: this.onImageError
|
|
190
|
+ })
|
|
191
|
+ ),
|
|
192
|
+ _react2.default.createElement(
|
|
193
|
+ "div",
|
|
194
|
+ { className: "tools" },
|
|
195
|
+ list.length > 1 && _react2.default.createElement("div", {
|
|
196
|
+ onClick: this.onPrev,
|
|
197
|
+ className: (0, _classnames2.default)("item", "left")
|
|
198
|
+ }),
|
|
199
|
+ _react2.default.createElement("div", { onClick: onFold, className: (0, _classnames2.default)("item", "shrink") }),
|
|
200
|
+ list.length > 1 && _react2.default.createElement("div", {
|
|
201
|
+ onClick: this.onNext,
|
|
202
|
+ className: (0, _classnames2.default)("item", "right")
|
|
203
|
+ })
|
|
204
|
+ )
|
|
205
|
+ ),
|
|
206
|
+ list.length > 1 && _react2.default.createElement(
|
|
207
|
+ "div",
|
|
208
|
+ { className: "list" },
|
|
209
|
+ list.map(function (item, index) {
|
149
|
210
|
return _react2.default.createElement(
|
150
|
|
- 'div',
|
151
|
|
- { className: 'container' },
|
152
|
|
- _react2.default.createElement(
|
153
|
|
- 'div',
|
154
|
|
- { className: 'toolbar' },
|
155
|
|
- _react2.default.createElement(
|
156
|
|
- 'span',
|
157
|
|
- { className: 'button', onClick: onFold },
|
158
|
|
- _react2.default.createElement(_icon2.default, { type: 'to-top' }),
|
159
|
|
- '\u6536\u8D77'
|
160
|
|
- ),
|
161
|
|
- _react2.default.createElement(
|
162
|
|
- 'span',
|
163
|
|
- { className: 'button', onClick: this.onOrigin },
|
164
|
|
- _react2.default.createElement(_icon2.default, { type: 'search' }),
|
165
|
|
- ' \u67E5\u770B\u539F\u56FE'
|
166
|
|
- )
|
167
|
|
- ),
|
168
|
|
- _react2.default.createElement(
|
169
|
|
- 'div',
|
170
|
|
- { className: 'pictureWrapper' },
|
171
|
|
- _react2.default.createElement(
|
172
|
|
- _spin2.default,
|
173
|
|
- { spinning: this.state.loading },
|
174
|
|
- _react2.default.createElement('img', {
|
175
|
|
- // ref={node => {
|
176
|
|
- // if (node) {
|
177
|
|
- // this.calcHeight(node);
|
178
|
|
- // }
|
179
|
|
- // }}
|
180
|
|
- className: 'picture',
|
181
|
|
- src: (0, _helper.addImageProcess)(list[cIndex], { large: true }),
|
182
|
|
- alt: list[cIndex],
|
183
|
|
- style: {
|
184
|
|
- transform: 'rotate(' + this.state.direction * 90 + 'deg)',
|
185
|
|
- opacity: this.state.loading ? 0 : 1,
|
186
|
|
- transition: '0.3s opacity'
|
187
|
|
- },
|
188
|
|
- onLoad: this.onImgLoad,
|
189
|
|
- onError: this.onImageError
|
190
|
|
- })
|
191
|
|
- ),
|
192
|
|
- _react2.default.createElement(
|
193
|
|
- 'div',
|
194
|
|
- { className: 'tools' },
|
195
|
|
- list.length > 1 && _react2.default.createElement('div', {
|
196
|
|
- onClick: this.onPrev,
|
197
|
|
- className: (0, _classnames2.default)("item", "left")
|
198
|
|
- }),
|
199
|
|
- _react2.default.createElement('div', { onClick: onFold, className: (0, _classnames2.default)("item", "shrink") }),
|
200
|
|
- list.length > 1 && _react2.default.createElement('div', {
|
201
|
|
- onClick: this.onNext,
|
202
|
|
- className: (0, _classnames2.default)("item", "right")
|
203
|
|
- })
|
204
|
|
- )
|
205
|
|
- ),
|
206
|
|
- list.length > 1 && _react2.default.createElement(
|
207
|
|
- 'div',
|
208
|
|
- { className: 'list' },
|
209
|
|
- list.map(function (item, index) {
|
210
|
|
- return _react2.default.createElement(
|
211
|
|
- 'div',
|
212
|
|
- {
|
213
|
|
- className: (0, _classnames2.default)({
|
214
|
|
- "wrapper": true,
|
215
|
|
- "active": index === cIndex
|
216
|
|
- }),
|
217
|
|
- key: item
|
218
|
|
- },
|
219
|
|
- _react2.default.createElement('div', {
|
220
|
|
- className: (0, _classnames2.default)({
|
221
|
|
- "thumbnail": true
|
222
|
|
- }),
|
223
|
|
- style: {
|
224
|
|
- backgroundImage: 'url(' + (0, _helper.addImageProcess)(item, {
|
225
|
|
- small: true
|
226
|
|
- }) + ')'
|
227
|
|
- },
|
228
|
|
- onClick: function onClick() {
|
229
|
|
- _this2.setIndex(index);
|
230
|
|
- }
|
231
|
|
- })
|
232
|
|
- );
|
233
|
|
- })
|
234
|
|
- )
|
|
211
|
+ "div",
|
|
212
|
+ {
|
|
213
|
+ className: (0, _classnames2.default)({
|
|
214
|
+ wrapper: true,
|
|
215
|
+ active: index === cIndex
|
|
216
|
+ }),
|
|
217
|
+ key: item
|
|
218
|
+ },
|
|
219
|
+ _react2.default.createElement("div", {
|
|
220
|
+ className: (0, _classnames2.default)({
|
|
221
|
+ thumbnail: true
|
|
222
|
+ }),
|
|
223
|
+ style: {
|
|
224
|
+ backgroundImage: "url(" + (0, _helper.addImageProcess)(item, {
|
|
225
|
+ small: true
|
|
226
|
+ }) + ")"
|
|
227
|
+ },
|
|
228
|
+ onClick: function onClick() {
|
|
229
|
+ _this2.setIndex(index);
|
|
230
|
+ }
|
|
231
|
+ })
|
235
|
232
|
);
|
236
|
|
- }
|
237
|
|
- }]);
|
|
233
|
+ })
|
|
234
|
+ )
|
|
235
|
+ );
|
|
236
|
+ }
|
|
237
|
+ }]);
|
238
|
238
|
|
239
|
|
- return ImagePreviewer;
|
|
239
|
+ return ImagePreviewer;
|
240
|
240
|
}(_react2.default.Component);
|
241
|
241
|
|
242
|
242
|
exports.default = ImagePreviewer;
|