通用评论

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