index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  6. var _vue = _interopRequireDefault(require("vue"));
  7. var _ImagePreview = _interopRequireDefault(require("./ImagePreview"));
  8. var _utils = require("../utils");
  9. var instance;
  10. var defaultConfig = {
  11. loop: true,
  12. value: true,
  13. images: [],
  14. maxZoom: 3,
  15. minZoom: 1 / 3,
  16. onClose: null,
  17. onChange: null,
  18. className: '',
  19. showIndex: true,
  20. closeable: false,
  21. closeIcon: 'clear',
  22. asyncClose: false,
  23. transition: 'van-fade',
  24. getContainer: 'body',
  25. overlayStyle: null,
  26. startPosition: 0,
  27. swipeDuration: 300,
  28. showIndicators: false,
  29. closeOnPopstate: true,
  30. closeIconPosition: 'top-right'
  31. };
  32. var initInstance = function initInstance() {
  33. instance = new (_vue.default.extend(_ImagePreview.default))({
  34. el: document.createElement('div')
  35. });
  36. document.body.appendChild(instance.$el);
  37. instance.$on('change', function (index) {
  38. if (instance.onChange) {
  39. instance.onChange(index);
  40. }
  41. });
  42. instance.$on('scale', function (data) {
  43. if (instance.onScale) {
  44. instance.onScale(data);
  45. }
  46. });
  47. };
  48. var ImagePreview = function ImagePreview(images, startPosition) {
  49. if (startPosition === void 0) {
  50. startPosition = 0;
  51. }
  52. /* istanbul ignore if */
  53. if (_utils.isServer) {
  54. return;
  55. }
  56. if (!instance) {
  57. initInstance();
  58. }
  59. var options = Array.isArray(images) ? {
  60. images: images,
  61. startPosition: startPosition
  62. } : images;
  63. (0, _extends2.default)(instance, defaultConfig, options);
  64. instance.$once('input', function (show) {
  65. instance.value = show;
  66. });
  67. instance.$once('closed', function () {
  68. instance.images = [];
  69. });
  70. if (options.onClose) {
  71. instance.$off('close');
  72. instance.$once('close', options.onClose);
  73. }
  74. return instance;
  75. };
  76. ImagePreview.Component = _ImagePreview.default;
  77. ImagePreview.install = function () {
  78. _vue.default.use(_ImagePreview.default);
  79. };
  80. var _default = ImagePreview;
  81. exports.default = _default;