image.js 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  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. /***/ 19:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/utils/types");
  182. /***/ }),
  183. /***/ 2:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/utils/dom");
  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", {
  280. staticClass: "el-image-viewer__mask",
  281. on: {
  282. click: function($event) {
  283. if ($event.target !== $event.currentTarget) {
  284. return null
  285. }
  286. return _vm.handleMaskClick($event)
  287. }
  288. }
  289. }),
  290. _c(
  291. "span",
  292. {
  293. staticClass: "el-image-viewer__btn el-image-viewer__close",
  294. on: { click: _vm.hide }
  295. },
  296. [_c("i", { staticClass: "el-icon-close" })]
  297. ),
  298. !_vm.isSingle
  299. ? [
  300. _c(
  301. "span",
  302. {
  303. staticClass: "el-image-viewer__btn el-image-viewer__prev",
  304. class: { "is-disabled": !_vm.infinite && _vm.isFirst },
  305. on: { click: _vm.prev }
  306. },
  307. [_c("i", { staticClass: "el-icon-arrow-left" })]
  308. ),
  309. _c(
  310. "span",
  311. {
  312. staticClass: "el-image-viewer__btn el-image-viewer__next",
  313. class: { "is-disabled": !_vm.infinite && _vm.isLast },
  314. on: { click: _vm.next }
  315. },
  316. [_c("i", { staticClass: "el-icon-arrow-right" })]
  317. )
  318. ]
  319. : _vm._e(),
  320. _c(
  321. "div",
  322. { staticClass: "el-image-viewer__btn el-image-viewer__actions" },
  323. [
  324. _c("div", { staticClass: "el-image-viewer__actions__inner" }, [
  325. _c("i", {
  326. staticClass: "el-icon-zoom-out",
  327. on: {
  328. click: function($event) {
  329. _vm.handleActions("zoomOut")
  330. }
  331. }
  332. }),
  333. _c("i", {
  334. staticClass: "el-icon-zoom-in",
  335. on: {
  336. click: function($event) {
  337. _vm.handleActions("zoomIn")
  338. }
  339. }
  340. }),
  341. _c("i", { staticClass: "el-image-viewer__actions__divider" }),
  342. _c("i", { class: _vm.mode.icon, on: { click: _vm.toggleMode } }),
  343. _c("i", { staticClass: "el-image-viewer__actions__divider" }),
  344. _c("i", {
  345. staticClass: "el-icon-refresh-left",
  346. on: {
  347. click: function($event) {
  348. _vm.handleActions("anticlocelise")
  349. }
  350. }
  351. }),
  352. _c("i", {
  353. staticClass: "el-icon-refresh-right",
  354. on: {
  355. click: function($event) {
  356. _vm.handleActions("clocelise")
  357. }
  358. }
  359. })
  360. ])
  361. ]
  362. ),
  363. _c(
  364. "div",
  365. { staticClass: "el-image-viewer__canvas" },
  366. _vm._l(_vm.urlList, function(url, i) {
  367. return i === _vm.index
  368. ? _c("img", {
  369. key: url,
  370. ref: "img",
  371. refInFor: true,
  372. staticClass: "el-image-viewer__img",
  373. style: _vm.imgStyle,
  374. attrs: { src: _vm.currentImg },
  375. on: {
  376. load: _vm.handleImgLoad,
  377. error: _vm.handleImgError,
  378. mousedown: _vm.handleMouseDown
  379. }
  380. })
  381. : _vm._e()
  382. }),
  383. 0
  384. )
  385. ],
  386. 2
  387. )
  388. ])
  389. }
  390. var image_viewervue_type_template_id_5e73b307_staticRenderFns = []
  391. image_viewervue_type_template_id_5e73b307_render._withStripped = true
  392. // CONCATENATED MODULE: ./packages/image/src/image-viewer.vue?vue&type=template&id=5e73b307&
  393. // EXTERNAL MODULE: external "element-ui/lib/utils/dom"
  394. var dom_ = __webpack_require__(2);
  395. // EXTERNAL MODULE: external "element-ui/lib/utils/util"
  396. var util_ = __webpack_require__(3);
  397. // 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&
  398. 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; };
  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. //
  443. //
  444. //
  445. //
  446. //
  447. //
  448. //
  449. //
  450. //
  451. //
  452. var Mode = {
  453. CONTAIN: {
  454. name: 'contain',
  455. icon: 'el-icon-full-screen'
  456. },
  457. ORIGINAL: {
  458. name: 'original',
  459. icon: 'el-icon-c-scale-to-original'
  460. }
  461. };
  462. var mousewheelEventName = Object(util_["isFirefox"])() ? 'DOMMouseScroll' : 'mousewheel';
  463. /* harmony default export */ var image_viewervue_type_script_lang_js_ = ({
  464. name: 'elImageViewer',
  465. props: {
  466. urlList: {
  467. type: Array,
  468. default: function _default() {
  469. return [];
  470. }
  471. },
  472. zIndex: {
  473. type: Number,
  474. default: 2000
  475. },
  476. onSwitch: {
  477. type: Function,
  478. default: function _default() {}
  479. },
  480. onClose: {
  481. type: Function,
  482. default: function _default() {}
  483. },
  484. initialIndex: {
  485. type: Number,
  486. default: 0
  487. },
  488. appendToBody: {
  489. type: Boolean,
  490. default: true
  491. },
  492. maskClosable: {
  493. type: Boolean,
  494. default: true
  495. }
  496. },
  497. data: function data() {
  498. return {
  499. index: this.initialIndex,
  500. isShow: false,
  501. infinite: true,
  502. loading: false,
  503. mode: Mode.CONTAIN,
  504. transform: {
  505. scale: 1,
  506. deg: 0,
  507. offsetX: 0,
  508. offsetY: 0,
  509. enableTransition: false
  510. }
  511. };
  512. },
  513. computed: {
  514. isSingle: function isSingle() {
  515. return this.urlList.length <= 1;
  516. },
  517. isFirst: function isFirst() {
  518. return this.index === 0;
  519. },
  520. isLast: function isLast() {
  521. return this.index === this.urlList.length - 1;
  522. },
  523. currentImg: function currentImg() {
  524. return this.urlList[this.index];
  525. },
  526. imgStyle: function imgStyle() {
  527. var _transform = this.transform,
  528. scale = _transform.scale,
  529. deg = _transform.deg,
  530. offsetX = _transform.offsetX,
  531. offsetY = _transform.offsetY,
  532. enableTransition = _transform.enableTransition;
  533. var style = {
  534. transform: 'scale(' + scale + ') rotate(' + deg + 'deg)',
  535. transition: enableTransition ? 'transform .3s' : '',
  536. 'margin-left': offsetX + 'px',
  537. 'margin-top': offsetY + 'px'
  538. };
  539. if (this.mode === Mode.CONTAIN) {
  540. style.maxWidth = style.maxHeight = '100%';
  541. }
  542. return style;
  543. }
  544. },
  545. watch: {
  546. index: {
  547. handler: function handler(val) {
  548. this.reset();
  549. this.onSwitch(val);
  550. }
  551. },
  552. currentImg: function currentImg(val) {
  553. var _this = this;
  554. this.$nextTick(function (_) {
  555. var $img = _this.$refs.img[0];
  556. if (!$img.complete) {
  557. _this.loading = true;
  558. }
  559. });
  560. }
  561. },
  562. methods: {
  563. hide: function hide() {
  564. this.deviceSupportUninstall();
  565. this.onClose();
  566. },
  567. deviceSupportInstall: function deviceSupportInstall() {
  568. var _this2 = this;
  569. this._keyDownHandler = Object(util_["rafThrottle"])(function (e) {
  570. var keyCode = e.keyCode;
  571. switch (keyCode) {
  572. // ESC
  573. case 27:
  574. _this2.hide();
  575. break;
  576. // SPACE
  577. case 32:
  578. _this2.toggleMode();
  579. break;
  580. // LEFT_ARROW
  581. case 37:
  582. _this2.prev();
  583. break;
  584. // UP_ARROW
  585. case 38:
  586. _this2.handleActions('zoomIn');
  587. break;
  588. // RIGHT_ARROW
  589. case 39:
  590. _this2.next();
  591. break;
  592. // DOWN_ARROW
  593. case 40:
  594. _this2.handleActions('zoomOut');
  595. break;
  596. }
  597. });
  598. this._mouseWheelHandler = Object(util_["rafThrottle"])(function (e) {
  599. var delta = e.wheelDelta ? e.wheelDelta : -e.detail;
  600. if (delta > 0) {
  601. _this2.handleActions('zoomIn', {
  602. zoomRate: 0.015,
  603. enableTransition: false
  604. });
  605. } else {
  606. _this2.handleActions('zoomOut', {
  607. zoomRate: 0.015,
  608. enableTransition: false
  609. });
  610. }
  611. });
  612. Object(dom_["on"])(document, 'keydown', this._keyDownHandler);
  613. Object(dom_["on"])(document, mousewheelEventName, this._mouseWheelHandler);
  614. },
  615. deviceSupportUninstall: function deviceSupportUninstall() {
  616. Object(dom_["off"])(document, 'keydown', this._keyDownHandler);
  617. Object(dom_["off"])(document, mousewheelEventName, this._mouseWheelHandler);
  618. this._keyDownHandler = null;
  619. this._mouseWheelHandler = null;
  620. },
  621. handleImgLoad: function handleImgLoad(e) {
  622. this.loading = false;
  623. },
  624. handleImgError: function handleImgError(e) {
  625. this.loading = false;
  626. e.target.alt = '加载失败';
  627. },
  628. handleMouseDown: function handleMouseDown(e) {
  629. var _this3 = this;
  630. if (this.loading || e.button !== 0) return;
  631. var _transform2 = this.transform,
  632. offsetX = _transform2.offsetX,
  633. offsetY = _transform2.offsetY;
  634. var startX = e.pageX;
  635. var startY = e.pageY;
  636. this._dragHandler = Object(util_["rafThrottle"])(function (ev) {
  637. _this3.transform.offsetX = offsetX + ev.pageX - startX;
  638. _this3.transform.offsetY = offsetY + ev.pageY - startY;
  639. });
  640. Object(dom_["on"])(document, 'mousemove', this._dragHandler);
  641. Object(dom_["on"])(document, 'mouseup', function (ev) {
  642. Object(dom_["off"])(document, 'mousemove', _this3._dragHandler);
  643. });
  644. e.preventDefault();
  645. },
  646. handleMaskClick: function handleMaskClick() {
  647. if (this.maskClosable) {
  648. this.hide();
  649. }
  650. },
  651. reset: function reset() {
  652. this.transform = {
  653. scale: 1,
  654. deg: 0,
  655. offsetX: 0,
  656. offsetY: 0,
  657. enableTransition: false
  658. };
  659. },
  660. toggleMode: function toggleMode() {
  661. if (this.loading) return;
  662. var modeNames = Object.keys(Mode);
  663. var modeValues = Object.values(Mode);
  664. var index = modeValues.indexOf(this.mode);
  665. var nextIndex = (index + 1) % modeNames.length;
  666. this.mode = Mode[modeNames[nextIndex]];
  667. this.reset();
  668. },
  669. prev: function prev() {
  670. if (this.isFirst && !this.infinite) return;
  671. var len = this.urlList.length;
  672. this.index = (this.index - 1 + len) % len;
  673. },
  674. next: function next() {
  675. if (this.isLast && !this.infinite) return;
  676. var len = this.urlList.length;
  677. this.index = (this.index + 1) % len;
  678. },
  679. handleActions: function handleActions(action) {
  680. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  681. if (this.loading) return;
  682. var _zoomRate$rotateDeg$e = _extends({
  683. zoomRate: 0.2,
  684. rotateDeg: 90,
  685. enableTransition: true
  686. }, options),
  687. zoomRate = _zoomRate$rotateDeg$e.zoomRate,
  688. rotateDeg = _zoomRate$rotateDeg$e.rotateDeg,
  689. enableTransition = _zoomRate$rotateDeg$e.enableTransition;
  690. var transform = this.transform;
  691. switch (action) {
  692. case 'zoomOut':
  693. if (transform.scale > 0.2) {
  694. transform.scale = parseFloat((transform.scale - zoomRate).toFixed(3));
  695. }
  696. break;
  697. case 'zoomIn':
  698. transform.scale = parseFloat((transform.scale + zoomRate).toFixed(3));
  699. break;
  700. case 'clocelise':
  701. transform.deg += rotateDeg;
  702. break;
  703. case 'anticlocelise':
  704. transform.deg -= rotateDeg;
  705. break;
  706. }
  707. transform.enableTransition = enableTransition;
  708. }
  709. },
  710. mounted: function mounted() {
  711. this.deviceSupportInstall();
  712. if (this.appendToBody) {
  713. document.body.appendChild(this.$el);
  714. }
  715. // add tabindex then wrapper can be focusable via Javascript
  716. // focus wrapper so arrow key can't cause inner scroll behavior underneath
  717. this.$refs['el-image-viewer__wrapper'].focus();
  718. },
  719. destroyed: function destroyed() {
  720. // if appendToBody is true, remove DOM node after destroy
  721. if (this.appendToBody && this.$el && this.$el.parentNode) {
  722. this.$el.parentNode.removeChild(this.$el);
  723. }
  724. }
  725. });
  726. // CONCATENATED MODULE: ./packages/image/src/image-viewer.vue?vue&type=script&lang=js&
  727. /* harmony default export */ var src_image_viewervue_type_script_lang_js_ = (image_viewervue_type_script_lang_js_);
  728. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  729. var componentNormalizer = __webpack_require__(0);
  730. // CONCATENATED MODULE: ./packages/image/src/image-viewer.vue
  731. /* normalize component */
  732. var component = Object(componentNormalizer["a" /* default */])(
  733. src_image_viewervue_type_script_lang_js_,
  734. image_viewervue_type_template_id_5e73b307_render,
  735. image_viewervue_type_template_id_5e73b307_staticRenderFns,
  736. false,
  737. null,
  738. null,
  739. null
  740. )
  741. /* hot reload */
  742. if (false) { var api; }
  743. component.options.__file = "packages/image/src/image-viewer.vue"
  744. /* harmony default export */ var image_viewer = (component.exports);
  745. // EXTERNAL MODULE: external "element-ui/lib/mixins/locale"
  746. var locale_ = __webpack_require__(6);
  747. var locale_default = /*#__PURE__*/__webpack_require__.n(locale_);
  748. // EXTERNAL MODULE: external "element-ui/lib/utils/types"
  749. var types_ = __webpack_require__(19);
  750. // EXTERNAL MODULE: external "throttle-debounce/throttle"
  751. var throttle_ = __webpack_require__(25);
  752. var throttle_default = /*#__PURE__*/__webpack_require__.n(throttle_);
  753. // 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&
  754. //
  755. //
  756. //
  757. //
  758. //
  759. //
  760. //
  761. //
  762. //
  763. //
  764. //
  765. //
  766. //
  767. //
  768. //
  769. //
  770. //
  771. //
  772. //
  773. //
  774. //
  775. //
  776. //
  777. var isSupportObjectFit = function isSupportObjectFit() {
  778. return document.documentElement.style.objectFit !== undefined;
  779. };
  780. var ObjectFit = {
  781. NONE: 'none',
  782. CONTAIN: 'contain',
  783. COVER: 'cover',
  784. FILL: 'fill',
  785. SCALE_DOWN: 'scale-down'
  786. };
  787. var prevOverflow = '';
  788. /* harmony default export */ var mainvue_type_script_lang_js_ = ({
  789. name: 'ElImage',
  790. mixins: [locale_default.a],
  791. inheritAttrs: false,
  792. components: {
  793. ImageViewer: image_viewer
  794. },
  795. props: {
  796. src: String,
  797. fit: String,
  798. lazy: Boolean,
  799. scrollContainer: {},
  800. previewSrcList: {
  801. type: Array,
  802. default: function _default() {
  803. return [];
  804. }
  805. },
  806. zIndex: {
  807. type: Number,
  808. default: 2000
  809. }
  810. },
  811. data: function data() {
  812. return {
  813. loading: true,
  814. error: false,
  815. show: !this.lazy,
  816. imageWidth: 0,
  817. imageHeight: 0,
  818. showViewer: false
  819. };
  820. },
  821. computed: {
  822. imageStyle: function imageStyle() {
  823. var fit = this.fit;
  824. if (!this.$isServer && fit) {
  825. return isSupportObjectFit() ? { 'object-fit': fit } : this.getImageStyle(fit);
  826. }
  827. return {};
  828. },
  829. alignCenter: function alignCenter() {
  830. return !this.$isServer && !isSupportObjectFit() && this.fit !== ObjectFit.FILL;
  831. },
  832. preview: function preview() {
  833. var previewSrcList = this.previewSrcList;
  834. return Array.isArray(previewSrcList) && previewSrcList.length > 0;
  835. },
  836. imageIndex: function imageIndex() {
  837. var previewIndex = 0;
  838. var srcIndex = this.previewSrcList.indexOf(this.src);
  839. if (srcIndex >= 0) {
  840. previewIndex = srcIndex;
  841. }
  842. return previewIndex;
  843. }
  844. },
  845. watch: {
  846. src: function src(val) {
  847. this.show && this.loadImage();
  848. },
  849. show: function show(val) {
  850. val && this.loadImage();
  851. }
  852. },
  853. mounted: function mounted() {
  854. if (this.lazy) {
  855. this.addLazyLoadListener();
  856. } else {
  857. this.loadImage();
  858. }
  859. },
  860. beforeDestroy: function beforeDestroy() {
  861. this.lazy && this.removeLazyLoadListener();
  862. },
  863. methods: {
  864. loadImage: function loadImage() {
  865. var _this = this;
  866. if (this.$isServer) return;
  867. // reset status
  868. this.loading = true;
  869. this.error = false;
  870. var img = new Image();
  871. img.onload = function (e) {
  872. return _this.handleLoad(e, img);
  873. };
  874. img.onerror = this.handleError.bind(this);
  875. // bind html attrs
  876. // so it can behave consistently
  877. Object.keys(this.$attrs).forEach(function (key) {
  878. var value = _this.$attrs[key];
  879. img.setAttribute(key, value);
  880. });
  881. img.src = this.src;
  882. },
  883. handleLoad: function handleLoad(e, img) {
  884. this.imageWidth = img.width;
  885. this.imageHeight = img.height;
  886. this.loading = false;
  887. this.error = false;
  888. },
  889. handleError: function handleError(e) {
  890. this.loading = false;
  891. this.error = true;
  892. this.$emit('error', e);
  893. },
  894. handleLazyLoad: function handleLazyLoad() {
  895. if (Object(dom_["isInContainer"])(this.$el, this._scrollContainer)) {
  896. this.show = true;
  897. this.removeLazyLoadListener();
  898. }
  899. },
  900. addLazyLoadListener: function addLazyLoadListener() {
  901. if (this.$isServer) return;
  902. var scrollContainer = this.scrollContainer;
  903. var _scrollContainer = null;
  904. if (Object(types_["isHtmlElement"])(scrollContainer)) {
  905. _scrollContainer = scrollContainer;
  906. } else if (Object(types_["isString"])(scrollContainer)) {
  907. _scrollContainer = document.querySelector(scrollContainer);
  908. } else {
  909. _scrollContainer = Object(dom_["getScrollContainer"])(this.$el);
  910. }
  911. if (_scrollContainer) {
  912. this._scrollContainer = _scrollContainer;
  913. this._lazyLoadHandler = throttle_default()(200, this.handleLazyLoad);
  914. Object(dom_["on"])(_scrollContainer, 'scroll', this._lazyLoadHandler);
  915. this.handleLazyLoad();
  916. }
  917. },
  918. removeLazyLoadListener: function removeLazyLoadListener() {
  919. var _scrollContainer = this._scrollContainer,
  920. _lazyLoadHandler = this._lazyLoadHandler;
  921. if (this.$isServer || !_scrollContainer || !_lazyLoadHandler) return;
  922. Object(dom_["off"])(_scrollContainer, 'scroll', _lazyLoadHandler);
  923. this._scrollContainer = null;
  924. this._lazyLoadHandler = null;
  925. },
  926. /**
  927. * simulate object-fit behavior to compatible with IE11 and other browsers which not support object-fit
  928. */
  929. getImageStyle: function getImageStyle(fit) {
  930. var imageWidth = this.imageWidth,
  931. imageHeight = this.imageHeight;
  932. var _$el = this.$el,
  933. containerWidth = _$el.clientWidth,
  934. containerHeight = _$el.clientHeight;
  935. if (!imageWidth || !imageHeight || !containerWidth || !containerHeight) return {};
  936. var imageAspectRatio = imageWidth / imageHeight;
  937. var containerAspectRatio = containerWidth / containerHeight;
  938. if (fit === ObjectFit.SCALE_DOWN) {
  939. var isSmaller = imageWidth < containerWidth && imageHeight < containerHeight;
  940. fit = isSmaller ? ObjectFit.NONE : ObjectFit.CONTAIN;
  941. }
  942. switch (fit) {
  943. case ObjectFit.NONE:
  944. return { width: 'auto', height: 'auto' };
  945. case ObjectFit.CONTAIN:
  946. return imageAspectRatio < containerAspectRatio ? { width: 'auto' } : { height: 'auto' };
  947. case ObjectFit.COVER:
  948. return imageAspectRatio < containerAspectRatio ? { height: 'auto' } : { width: 'auto' };
  949. default:
  950. return {};
  951. }
  952. },
  953. clickHandler: function clickHandler() {
  954. // don't show viewer when preview is false
  955. if (!this.preview) {
  956. return;
  957. }
  958. // prevent body scroll
  959. prevOverflow = document.body.style.overflow;
  960. document.body.style.overflow = 'hidden';
  961. this.showViewer = true;
  962. },
  963. closeViewer: function closeViewer() {
  964. document.body.style.overflow = prevOverflow;
  965. this.showViewer = false;
  966. }
  967. }
  968. });
  969. // CONCATENATED MODULE: ./packages/image/src/main.vue?vue&type=script&lang=js&
  970. /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_);
  971. // CONCATENATED MODULE: ./packages/image/src/main.vue
  972. /* normalize component */
  973. var main_component = Object(componentNormalizer["a" /* default */])(
  974. src_mainvue_type_script_lang_js_,
  975. render,
  976. staticRenderFns,
  977. false,
  978. null,
  979. null,
  980. null
  981. )
  982. /* hot reload */
  983. if (false) { var main_api; }
  984. main_component.options.__file = "packages/image/src/main.vue"
  985. /* harmony default export */ var main = (main_component.exports);
  986. // CONCATENATED MODULE: ./packages/image/index.js
  987. /* istanbul ignore next */
  988. main.install = function (Vue) {
  989. Vue.component(main.name, main);
  990. };
  991. /* harmony default export */ var packages_image = __webpack_exports__["default"] = (main);
  992. /***/ })
  993. /******/ });