image.js 29 KB

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