image.js 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "/dist/";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 64);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 0:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; });
  93. /* globals __VUE_SSR_CONTEXT__ */
  94. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  95. // This module is a runtime utility for cleaner component module output and will
  96. // be included in the final webpack user bundle.
  97. function normalizeComponent (
  98. scriptExports,
  99. render,
  100. staticRenderFns,
  101. functionalTemplate,
  102. injectStyles,
  103. scopeId,
  104. moduleIdentifier, /* server only */
  105. shadowMode /* vue-cli only */
  106. ) {
  107. // Vue.extend constructor export interop
  108. var options = typeof scriptExports === 'function'
  109. ? scriptExports.options
  110. : scriptExports
  111. // render functions
  112. if (render) {
  113. options.render = render
  114. options.staticRenderFns = staticRenderFns
  115. options._compiled = true
  116. }
  117. // functional template
  118. if (functionalTemplate) {
  119. options.functional = true
  120. }
  121. // scopedId
  122. if (scopeId) {
  123. options._scopeId = 'data-v-' + scopeId
  124. }
  125. var hook
  126. if (moduleIdentifier) { // server build
  127. hook = function (context) {
  128. // 2.3 injection
  129. context =
  130. context || // cached call
  131. (this.$vnode && this.$vnode.ssrContext) || // stateful
  132. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  133. // 2.2 with runInNewContext: true
  134. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  135. context = __VUE_SSR_CONTEXT__
  136. }
  137. // inject component styles
  138. if (injectStyles) {
  139. injectStyles.call(this, context)
  140. }
  141. // register component module identifier for async chunk inferrence
  142. if (context && context._registeredComponents) {
  143. context._registeredComponents.add(moduleIdentifier)
  144. }
  145. }
  146. // used by ssr in case component is cached and beforeCreate
  147. // never gets called
  148. options._ssrRegister = hook
  149. } else if (injectStyles) {
  150. hook = shadowMode
  151. ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
  152. : injectStyles
  153. }
  154. if (hook) {
  155. if (options.functional) {
  156. // for template-only hot-reload because in that case the render fn doesn't
  157. // go through the normalizer
  158. options._injectStyles = hook
  159. // register for functioal component in vue file
  160. var originalRender = options.render
  161. options.render = function renderWithStyleInjection (h, context) {
  162. hook.call(context)
  163. return originalRender(h, context)
  164. }
  165. } else {
  166. // inject component registration as beforeCreate hook
  167. var existing = options.beforeCreate
  168. options.beforeCreate = existing
  169. ? [].concat(existing, hook)
  170. : [hook]
  171. }
  172. }
  173. return {
  174. exports: scriptExports,
  175. options: options
  176. }
  177. }
  178. /***/ }),
  179. /***/ 2:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/utils/dom");
  182. /***/ }),
  183. /***/ 20:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/utils/types");
  186. /***/ }),
  187. /***/ 25:
  188. /***/ (function(module, exports) {
  189. module.exports = require("throttle-debounce/throttle");
  190. /***/ }),
  191. /***/ 3:
  192. /***/ (function(module, exports) {
  193. module.exports = require("element-ui/lib/utils/util");
  194. /***/ }),
  195. /***/ 6:
  196. /***/ (function(module, exports) {
  197. module.exports = require("element-ui/lib/mixins/locale");
  198. /***/ }),
  199. /***/ 64:
  200. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  201. "use strict";
  202. __webpack_require__.r(__webpack_exports__);
  203. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/image/src/main.vue?vue&type=template&id=44d84a7c&
  204. var render = function() {
  205. var _vm = this
  206. var _h = _vm.$createElement
  207. var _c = _vm._self._c || _h
  208. return _c(
  209. "div",
  210. { staticClass: "el-image" },
  211. [
  212. _vm.loading
  213. ? _vm._t("placeholder", [
  214. _c("div", { staticClass: "el-image__placeholder" })
  215. ])
  216. : _vm.error
  217. ? _vm._t("error", [
  218. _c("div", { staticClass: "el-image__error" }, [
  219. _vm._v(_vm._s(_vm.t("el.image.error")))
  220. ])
  221. ])
  222. : _c(
  223. "img",
  224. _vm._g(
  225. _vm._b(
  226. {
  227. staticClass: "el-image__inner",
  228. class: {
  229. "el-image__inner--center": _vm.alignCenter,
  230. "el-image__preview": _vm.preview
  231. },
  232. style: _vm.imageStyle,
  233. attrs: { src: _vm.src },
  234. on: { click: _vm.clickHandler }
  235. },
  236. "img",
  237. _vm.$attrs,
  238. false
  239. ),
  240. _vm.$listeners
  241. )
  242. ),
  243. _vm.preview
  244. ? [
  245. _vm.showViewer
  246. ? _c("image-viewer", {
  247. attrs: {
  248. "z-index": _vm.zIndex,
  249. "initial-index": _vm.imageIndex,
  250. "on-close": _vm.closeViewer,
  251. "url-list": _vm.previewSrcList
  252. }
  253. })
  254. : _vm._e()
  255. ]
  256. : _vm._e()
  257. ],
  258. 2
  259. )
  260. }
  261. var staticRenderFns = []
  262. render._withStripped = true
  263. // CONCATENATED MODULE: ./packages/image/src/main.vue?vue&type=template&id=44d84a7c&
  264. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/image/src/image-viewer.vue?vue&type=template&id=5e73b307&
  265. var image_viewervue_type_template_id_5e73b307_render = function() {
  266. var _vm = this
  267. var _h = _vm.$createElement
  268. var _c = _vm._self._c || _h
  269. return _c("transition", { attrs: { name: "viewer-fade" } }, [
  270. _c(
  271. "div",
  272. {
  273. ref: "el-image-viewer__wrapper",
  274. staticClass: "el-image-viewer__wrapper",
  275. style: { "z-index": _vm.zIndex },
  276. attrs: { tabindex: "-1" }
  277. },
  278. [
  279. _c("div", { staticClass: "el-image-viewer__mask" }),
  280. _c(
  281. "span",
  282. {
  283. staticClass: "el-image-viewer__btn el-image-viewer__close",
  284. on: { click: _vm.hide }
  285. },
  286. [_c("i", { staticClass: "el-icon-circle-close" })]
  287. ),
  288. !_vm.isSingle
  289. ? [
  290. _c(
  291. "span",
  292. {
  293. staticClass: "el-image-viewer__btn el-image-viewer__prev",
  294. class: { "is-disabled": !_vm.infinite && _vm.isFirst },
  295. on: { click: _vm.prev }
  296. },
  297. [_c("i", { staticClass: "el-icon-arrow-left" })]
  298. ),
  299. _c(
  300. "span",
  301. {
  302. staticClass: "el-image-viewer__btn el-image-viewer__next",
  303. class: { "is-disabled": !_vm.infinite && _vm.isLast },
  304. on: { click: _vm.next }
  305. },
  306. [_c("i", { staticClass: "el-icon-arrow-right" })]
  307. )
  308. ]
  309. : _vm._e(),
  310. _c(
  311. "div",
  312. { staticClass: "el-image-viewer__btn el-image-viewer__actions" },
  313. [
  314. _c("div", { staticClass: "el-image-viewer__actions__inner" }, [
  315. _c("i", {
  316. staticClass: "el-icon-zoom-out",
  317. on: {
  318. click: function($event) {
  319. _vm.handleActions("zoomOut")
  320. }
  321. }
  322. }),
  323. _c("i", {
  324. staticClass: "el-icon-zoom-in",
  325. on: {
  326. click: function($event) {
  327. _vm.handleActions("zoomIn")
  328. }
  329. }
  330. }),
  331. _c("i", { staticClass: "el-image-viewer__actions__divider" }),
  332. _c("i", { class: _vm.mode.icon, on: { click: _vm.toggleMode } }),
  333. _c("i", { staticClass: "el-image-viewer__actions__divider" }),
  334. _c("i", {
  335. staticClass: "el-icon-refresh-left",
  336. on: {
  337. click: function($event) {
  338. _vm.handleActions("anticlocelise")
  339. }
  340. }
  341. }),
  342. _c("i", {
  343. staticClass: "el-icon-refresh-right",
  344. on: {
  345. click: function($event) {
  346. _vm.handleActions("clocelise")
  347. }
  348. }
  349. })
  350. ])
  351. ]
  352. ),
  353. _c(
  354. "div",
  355. { staticClass: "el-image-viewer__canvas" },
  356. _vm._l(_vm.urlList, function(url, i) {
  357. return i === _vm.index
  358. ? _c("img", {
  359. key: url,
  360. ref: "img",
  361. refInFor: true,
  362. staticClass: "el-image-viewer__img",
  363. style: _vm.imgStyle,
  364. attrs: { src: _vm.currentImg },
  365. on: {
  366. load: _vm.handleImgLoad,
  367. error: _vm.handleImgError,
  368. mousedown: _vm.handleMouseDown
  369. }
  370. })
  371. : _vm._e()
  372. }),
  373. 0
  374. )
  375. ],
  376. 2
  377. )
  378. ])
  379. }
  380. var image_viewervue_type_template_id_5e73b307_staticRenderFns = []
  381. image_viewervue_type_template_id_5e73b307_render._withStripped = true
  382. // CONCATENATED MODULE: ./packages/image/src/image-viewer.vue?vue&type=template&id=5e73b307&
  383. // EXTERNAL MODULE: external "element-ui/lib/utils/dom"
  384. var dom_ = __webpack_require__(2);
  385. // EXTERNAL MODULE: external "element-ui/lib/utils/util"
  386. var util_ = __webpack_require__(3);
  387. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/image/src/image-viewer.vue?vue&type=script&lang=js&
  388. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  389. //
  390. //
  391. //
  392. //
  393. //
  394. //
  395. //
  396. //
  397. //
  398. //
  399. //
  400. //
  401. //
  402. //
  403. //
  404. //
  405. //
  406. //
  407. //
  408. //
  409. //
  410. //
  411. //
  412. //
  413. //
  414. //
  415. //
  416. //
  417. //
  418. //
  419. //
  420. //
  421. //
  422. //
  423. //
  424. //
  425. //
  426. //
  427. //
  428. //
  429. //
  430. //
  431. //
  432. //
  433. //
  434. //
  435. //
  436. //
  437. //
  438. //
  439. //
  440. //
  441. //
  442. var Mode = {
  443. CONTAIN: {
  444. name: 'contain',
  445. icon: 'el-icon-full-screen'
  446. },
  447. ORIGINAL: {
  448. name: 'original',
  449. icon: 'el-icon-c-scale-to-original'
  450. }
  451. };
  452. var mousewheelEventName = Object(util_["isFirefox"])() ? 'DOMMouseScroll' : 'mousewheel';
  453. /* harmony default export */ var image_viewervue_type_script_lang_js_ = ({
  454. name: 'elImageViewer',
  455. props: {
  456. urlList: {
  457. type: Array,
  458. default: function _default() {
  459. return [];
  460. }
  461. },
  462. zIndex: {
  463. type: Number,
  464. default: 2000
  465. },
  466. onSwitch: {
  467. type: Function,
  468. default: function _default() {}
  469. },
  470. onClose: {
  471. type: Function,
  472. default: function _default() {}
  473. },
  474. initialIndex: {
  475. type: Number,
  476. default: 0
  477. }
  478. },
  479. data: function data() {
  480. return {
  481. index: this.initialIndex,
  482. isShow: false,
  483. infinite: true,
  484. loading: false,
  485. mode: Mode.CONTAIN,
  486. transform: {
  487. scale: 1,
  488. deg: 0,
  489. offsetX: 0,
  490. offsetY: 0,
  491. enableTransition: false
  492. }
  493. };
  494. },
  495. computed: {
  496. isSingle: function isSingle() {
  497. return this.urlList.length <= 1;
  498. },
  499. isFirst: function isFirst() {
  500. return this.index === 0;
  501. },
  502. isLast: function isLast() {
  503. return this.index === this.urlList.length - 1;
  504. },
  505. currentImg: function currentImg() {
  506. return this.urlList[this.index];
  507. },
  508. imgStyle: function imgStyle() {
  509. var _transform = this.transform,
  510. scale = _transform.scale,
  511. deg = _transform.deg,
  512. offsetX = _transform.offsetX,
  513. offsetY = _transform.offsetY,
  514. enableTransition = _transform.enableTransition;
  515. var style = {
  516. transform: 'scale(' + scale + ') rotate(' + deg + 'deg)',
  517. transition: enableTransition ? 'transform .3s' : '',
  518. 'margin-left': offsetX + 'px',
  519. 'margin-top': offsetY + 'px'
  520. };
  521. if (this.mode === Mode.CONTAIN) {
  522. style.maxWidth = style.maxHeight = '100%';
  523. }
  524. return style;
  525. }
  526. },
  527. watch: {
  528. index: {
  529. handler: function handler(val) {
  530. this.reset();
  531. this.onSwitch(val);
  532. }
  533. },
  534. currentImg: function currentImg(val) {
  535. var _this = this;
  536. this.$nextTick(function (_) {
  537. var $img = _this.$refs.img[0];
  538. if (!$img.complete) {
  539. _this.loading = true;
  540. }
  541. });
  542. }
  543. },
  544. methods: {
  545. hide: function hide() {
  546. this.deviceSupportUninstall();
  547. this.onClose();
  548. },
  549. deviceSupportInstall: function deviceSupportInstall() {
  550. var _this2 = this;
  551. this._keyDownHandler = Object(util_["rafThrottle"])(function (e) {
  552. var keyCode = e.keyCode;
  553. switch (keyCode) {
  554. // ESC
  555. case 27:
  556. _this2.hide();
  557. break;
  558. // SPACE
  559. case 32:
  560. _this2.toggleMode();
  561. break;
  562. // LEFT_ARROW
  563. case 37:
  564. _this2.prev();
  565. break;
  566. // UP_ARROW
  567. case 38:
  568. _this2.handleActions('zoomIn');
  569. break;
  570. // RIGHT_ARROW
  571. case 39:
  572. _this2.next();
  573. break;
  574. // DOWN_ARROW
  575. case 40:
  576. _this2.handleActions('zoomOut');
  577. break;
  578. }
  579. });
  580. this._mouseWheelHandler = Object(util_["rafThrottle"])(function (e) {
  581. var delta = e.wheelDelta ? e.wheelDelta : -e.detail;
  582. if (delta > 0) {
  583. _this2.handleActions('zoomIn', {
  584. zoomRate: 0.015,
  585. enableTransition: false
  586. });
  587. } else {
  588. _this2.handleActions('zoomOut', {
  589. zoomRate: 0.015,
  590. enableTransition: false
  591. });
  592. }
  593. });
  594. Object(dom_["on"])(document, 'keydown', this._keyDownHandler);
  595. Object(dom_["on"])(document, mousewheelEventName, this._mouseWheelHandler);
  596. },
  597. deviceSupportUninstall: function deviceSupportUninstall() {
  598. Object(dom_["off"])(document, 'keydown', this._keyDownHandler);
  599. Object(dom_["off"])(document, mousewheelEventName, this._mouseWheelHandler);
  600. this._keyDownHandler = null;
  601. this._mouseWheelHandler = null;
  602. },
  603. handleImgLoad: function handleImgLoad(e) {
  604. this.loading = false;
  605. },
  606. handleImgError: function handleImgError(e) {
  607. this.loading = false;
  608. e.target.alt = '加载失败';
  609. },
  610. handleMouseDown: function handleMouseDown(e) {
  611. var _this3 = this;
  612. if (this.loading || e.button !== 0) return;
  613. var _transform2 = this.transform,
  614. offsetX = _transform2.offsetX,
  615. offsetY = _transform2.offsetY;
  616. var startX = e.pageX;
  617. var startY = e.pageY;
  618. this._dragHandler = Object(util_["rafThrottle"])(function (ev) {
  619. _this3.transform.offsetX = offsetX + ev.pageX - startX;
  620. _this3.transform.offsetY = offsetY + ev.pageY - startY;
  621. });
  622. Object(dom_["on"])(document, 'mousemove', this._dragHandler);
  623. Object(dom_["on"])(document, 'mouseup', function (ev) {
  624. Object(dom_["off"])(document, 'mousemove', _this3._dragHandler);
  625. });
  626. e.preventDefault();
  627. },
  628. reset: function reset() {
  629. this.transform = {
  630. scale: 1,
  631. deg: 0,
  632. offsetX: 0,
  633. offsetY: 0,
  634. enableTransition: false
  635. };
  636. },
  637. toggleMode: function toggleMode() {
  638. if (this.loading) return;
  639. var modeNames = Object.keys(Mode);
  640. var modeValues = Object.values(Mode);
  641. var index = modeValues.indexOf(this.mode);
  642. var nextIndex = (index + 1) % modeNames.length;
  643. this.mode = Mode[modeNames[nextIndex]];
  644. this.reset();
  645. },
  646. prev: function prev() {
  647. if (this.isFirst && !this.infinite) return;
  648. var len = this.urlList.length;
  649. this.index = (this.index - 1 + len) % len;
  650. },
  651. next: function next() {
  652. if (this.isLast && !this.infinite) return;
  653. var len = this.urlList.length;
  654. this.index = (this.index + 1) % len;
  655. },
  656. handleActions: function handleActions(action) {
  657. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  658. if (this.loading) return;
  659. var _zoomRate$rotateDeg$e = _extends({
  660. zoomRate: 0.2,
  661. rotateDeg: 90,
  662. enableTransition: true
  663. }, options),
  664. zoomRate = _zoomRate$rotateDeg$e.zoomRate,
  665. rotateDeg = _zoomRate$rotateDeg$e.rotateDeg,
  666. enableTransition = _zoomRate$rotateDeg$e.enableTransition;
  667. var transform = this.transform;
  668. switch (action) {
  669. case 'zoomOut':
  670. if (transform.scale > 0.2) {
  671. transform.scale = parseFloat((transform.scale - zoomRate).toFixed(3));
  672. }
  673. break;
  674. case 'zoomIn':
  675. transform.scale = parseFloat((transform.scale + zoomRate).toFixed(3));
  676. break;
  677. case 'clocelise':
  678. transform.deg += rotateDeg;
  679. break;
  680. case 'anticlocelise':
  681. transform.deg -= rotateDeg;
  682. break;
  683. }
  684. transform.enableTransition = enableTransition;
  685. }
  686. },
  687. mounted: function mounted() {
  688. this.deviceSupportInstall();
  689. // add tabindex then wrapper can be focusable via Javascript
  690. // focus wrapper so arrow key can't cause inner scroll behavior underneath
  691. this.$refs['el-image-viewer__wrapper'].focus();
  692. }
  693. });
  694. // CONCATENATED MODULE: ./packages/image/src/image-viewer.vue?vue&type=script&lang=js&
  695. /* harmony default export */ var src_image_viewervue_type_script_lang_js_ = (image_viewervue_type_script_lang_js_);
  696. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  697. var componentNormalizer = __webpack_require__(0);
  698. // CONCATENATED MODULE: ./packages/image/src/image-viewer.vue
  699. /* normalize component */
  700. var component = Object(componentNormalizer["a" /* default */])(
  701. src_image_viewervue_type_script_lang_js_,
  702. image_viewervue_type_template_id_5e73b307_render,
  703. image_viewervue_type_template_id_5e73b307_staticRenderFns,
  704. false,
  705. null,
  706. null,
  707. null
  708. )
  709. /* hot reload */
  710. if (false) { var api; }
  711. component.options.__file = "packages/image/src/image-viewer.vue"
  712. /* harmony default export */ var image_viewer = (component.exports);
  713. // EXTERNAL MODULE: external "element-ui/lib/mixins/locale"
  714. var locale_ = __webpack_require__(6);
  715. var locale_default = /*#__PURE__*/__webpack_require__.n(locale_);
  716. // EXTERNAL MODULE: external "element-ui/lib/utils/types"
  717. var types_ = __webpack_require__(20);
  718. // EXTERNAL MODULE: external "throttle-debounce/throttle"
  719. var throttle_ = __webpack_require__(25);
  720. var throttle_default = /*#__PURE__*/__webpack_require__.n(throttle_);
  721. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/image/src/main.vue?vue&type=script&lang=js&
  722. //
  723. //
  724. //
  725. //
  726. //
  727. //
  728. //
  729. //
  730. //
  731. //
  732. //
  733. //
  734. //
  735. //
  736. //
  737. //
  738. //
  739. //
  740. //
  741. //
  742. //
  743. //
  744. //
  745. var isSupportObjectFit = function isSupportObjectFit() {
  746. return document.documentElement.style.objectFit !== undefined;
  747. };
  748. var ObjectFit = {
  749. NONE: 'none',
  750. CONTAIN: 'contain',
  751. COVER: 'cover',
  752. FILL: 'fill',
  753. SCALE_DOWN: 'scale-down'
  754. };
  755. var prevOverflow = '';
  756. /* harmony default export */ var mainvue_type_script_lang_js_ = ({
  757. name: 'ElImage',
  758. mixins: [locale_default.a],
  759. inheritAttrs: false,
  760. components: {
  761. ImageViewer: image_viewer
  762. },
  763. props: {
  764. src: String,
  765. fit: String,
  766. lazy: Boolean,
  767. scrollContainer: {},
  768. previewSrcList: {
  769. type: Array,
  770. default: function _default() {
  771. return [];
  772. }
  773. },
  774. zIndex: {
  775. type: Number,
  776. default: 2000
  777. }
  778. },
  779. data: function data() {
  780. return {
  781. loading: true,
  782. error: false,
  783. show: !this.lazy,
  784. imageWidth: 0,
  785. imageHeight: 0,
  786. showViewer: false
  787. };
  788. },
  789. computed: {
  790. imageStyle: function imageStyle() {
  791. var fit = this.fit;
  792. if (!this.$isServer && fit) {
  793. return isSupportObjectFit() ? { 'object-fit': fit } : this.getImageStyle(fit);
  794. }
  795. return {};
  796. },
  797. alignCenter: function alignCenter() {
  798. return !this.$isServer && !isSupportObjectFit() && this.fit !== ObjectFit.FILL;
  799. },
  800. preview: function preview() {
  801. var previewSrcList = this.previewSrcList;
  802. return Array.isArray(previewSrcList) && previewSrcList.length > 0;
  803. },
  804. imageIndex: function imageIndex() {
  805. var previewIndex = 0;
  806. var srcIndex = this.previewSrcList.indexOf(this.src);
  807. if (srcIndex >= 0) {
  808. previewIndex = srcIndex;
  809. }
  810. return previewIndex;
  811. }
  812. },
  813. watch: {
  814. src: function src(val) {
  815. this.show && this.loadImage();
  816. },
  817. show: function show(val) {
  818. val && this.loadImage();
  819. }
  820. },
  821. mounted: function mounted() {
  822. if (this.lazy) {
  823. this.addLazyLoadListener();
  824. } else {
  825. this.loadImage();
  826. }
  827. },
  828. beforeDestroy: function beforeDestroy() {
  829. this.lazy && this.removeLazyLoadListener();
  830. },
  831. methods: {
  832. loadImage: function loadImage() {
  833. var _this = this;
  834. if (this.$isServer) return;
  835. // reset status
  836. this.loading = true;
  837. this.error = false;
  838. var img = new Image();
  839. img.onload = function (e) {
  840. return _this.handleLoad(e, img);
  841. };
  842. img.onerror = this.handleError.bind(this);
  843. // bind html attrs
  844. // so it can behave consistently
  845. Object.keys(this.$attrs).forEach(function (key) {
  846. var value = _this.$attrs[key];
  847. img.setAttribute(key, value);
  848. });
  849. img.src = this.src;
  850. },
  851. handleLoad: function handleLoad(e, img) {
  852. this.imageWidth = img.width;
  853. this.imageHeight = img.height;
  854. this.loading = false;
  855. this.error = false;
  856. },
  857. handleError: function handleError(e) {
  858. this.loading = false;
  859. this.error = true;
  860. this.$emit('error', e);
  861. },
  862. handleLazyLoad: function handleLazyLoad() {
  863. if (Object(dom_["isInContainer"])(this.$el, this._scrollContainer)) {
  864. this.show = true;
  865. this.removeLazyLoadListener();
  866. }
  867. },
  868. addLazyLoadListener: function addLazyLoadListener() {
  869. if (this.$isServer) return;
  870. var scrollContainer = this.scrollContainer;
  871. var _scrollContainer = null;
  872. if (Object(types_["isHtmlElement"])(scrollContainer)) {
  873. _scrollContainer = scrollContainer;
  874. } else if (Object(types_["isString"])(scrollContainer)) {
  875. _scrollContainer = document.querySelector(scrollContainer);
  876. } else {
  877. _scrollContainer = Object(dom_["getScrollContainer"])(this.$el);
  878. }
  879. if (_scrollContainer) {
  880. this._scrollContainer = _scrollContainer;
  881. this._lazyLoadHandler = throttle_default()(200, this.handleLazyLoad);
  882. Object(dom_["on"])(_scrollContainer, 'scroll', this._lazyLoadHandler);
  883. this.handleLazyLoad();
  884. }
  885. },
  886. removeLazyLoadListener: function removeLazyLoadListener() {
  887. var _scrollContainer = this._scrollContainer,
  888. _lazyLoadHandler = this._lazyLoadHandler;
  889. if (this.$isServer || !_scrollContainer || !_lazyLoadHandler) return;
  890. Object(dom_["off"])(_scrollContainer, 'scroll', _lazyLoadHandler);
  891. this._scrollContainer = null;
  892. this._lazyLoadHandler = null;
  893. },
  894. /**
  895. * simulate object-fit behavior to compatible with IE11 and other browsers which not support object-fit
  896. */
  897. getImageStyle: function getImageStyle(fit) {
  898. var imageWidth = this.imageWidth,
  899. imageHeight = this.imageHeight;
  900. var _$el = this.$el,
  901. containerWidth = _$el.clientWidth,
  902. containerHeight = _$el.clientHeight;
  903. if (!imageWidth || !imageHeight || !containerWidth || !containerHeight) return {};
  904. var vertical = imageWidth / imageHeight < 1;
  905. if (fit === ObjectFit.SCALE_DOWN) {
  906. var isSmaller = imageWidth < containerWidth && imageHeight < containerHeight;
  907. fit = isSmaller ? ObjectFit.NONE : ObjectFit.CONTAIN;
  908. }
  909. switch (fit) {
  910. case ObjectFit.NONE:
  911. return { width: 'auto', height: 'auto' };
  912. case ObjectFit.CONTAIN:
  913. return vertical ? { width: 'auto' } : { height: 'auto' };
  914. case ObjectFit.COVER:
  915. return vertical ? { height: 'auto' } : { width: 'auto' };
  916. default:
  917. return {};
  918. }
  919. },
  920. clickHandler: function clickHandler() {
  921. // don't show viewer when preview is false
  922. if (!this.preview) {
  923. return;
  924. }
  925. // prevent body scroll
  926. prevOverflow = document.body.style.overflow;
  927. document.body.style.overflow = 'hidden';
  928. this.showViewer = true;
  929. },
  930. closeViewer: function closeViewer() {
  931. document.body.style.overflow = prevOverflow;
  932. this.showViewer = false;
  933. }
  934. }
  935. });
  936. // CONCATENATED MODULE: ./packages/image/src/main.vue?vue&type=script&lang=js&
  937. /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_);
  938. // CONCATENATED MODULE: ./packages/image/src/main.vue
  939. /* normalize component */
  940. var main_component = Object(componentNormalizer["a" /* default */])(
  941. src_mainvue_type_script_lang_js_,
  942. render,
  943. staticRenderFns,
  944. false,
  945. null,
  946. null,
  947. null
  948. )
  949. /* hot reload */
  950. if (false) { var main_api; }
  951. main_component.options.__file = "packages/image/src/main.vue"
  952. /* harmony default export */ var main = (main_component.exports);
  953. // CONCATENATED MODULE: ./packages/image/index.js
  954. /* istanbul ignore next */
  955. main.install = function (Vue) {
  956. Vue.component(main.name, main);
  957. };
  958. /* harmony default export */ var packages_image = __webpack_exports__["default"] = (main);
  959. /***/ })
  960. /******/ });