image.js 31 KB

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