image.js 29 KB

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