image.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  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 vertical = imageWidth / imageHeight < 1;
  937. if (fit === ObjectFit.SCALE_DOWN) {
  938. var isSmaller = imageWidth < containerWidth && imageHeight < containerHeight;
  939. fit = isSmaller ? ObjectFit.NONE : ObjectFit.CONTAIN;
  940. }
  941. switch (fit) {
  942. case ObjectFit.NONE:
  943. return { width: 'auto', height: 'auto' };
  944. case ObjectFit.CONTAIN:
  945. return vertical ? { width: 'auto' } : { height: 'auto' };
  946. case ObjectFit.COVER:
  947. return vertical ? { height: 'auto' } : { width: 'auto' };
  948. default:
  949. return {};
  950. }
  951. },
  952. clickHandler: function clickHandler() {
  953. // don't show viewer when preview is false
  954. if (!this.preview) {
  955. return;
  956. }
  957. // prevent body scroll
  958. prevOverflow = document.body.style.overflow;
  959. document.body.style.overflow = 'hidden';
  960. this.showViewer = true;
  961. },
  962. closeViewer: function closeViewer() {
  963. document.body.style.overflow = prevOverflow;
  964. this.showViewer = false;
  965. }
  966. }
  967. });
  968. // CONCATENATED MODULE: ./packages/image/src/main.vue?vue&type=script&lang=js&
  969. /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_);
  970. // CONCATENATED MODULE: ./packages/image/src/main.vue
  971. /* normalize component */
  972. var main_component = Object(componentNormalizer["a" /* default */])(
  973. src_mainvue_type_script_lang_js_,
  974. render,
  975. staticRenderFns,
  976. false,
  977. null,
  978. null,
  979. null
  980. )
  981. /* hot reload */
  982. if (false) { var main_api; }
  983. main_component.options.__file = "packages/image/src/main.vue"
  984. /* harmony default export */ var main = (main_component.exports);
  985. // CONCATENATED MODULE: ./packages/image/index.js
  986. /* istanbul ignore next */
  987. main.install = function (Vue) {
  988. Vue.component(main.name, main);
  989. };
  990. /* harmony default export */ var packages_image = __webpack_exports__["default"] = (main);
  991. /***/ })
  992. /******/ });