// Utils import { bem, createComponent } from './shared'; import { callInterceptor } from '../utils/interceptor'; // Mixins import { TouchMixin } from '../mixins/touch'; import { BindEventMixin } from '../mixins/bind-event'; // Components import Icon from '../icon'; import Swipe from '../swipe'; import Popup from '../popup'; import ImagePreviewItem from './ImagePreviewItem'; export default createComponent({ mixins: [ TouchMixin, BindEventMixin(function (bind) { bind(window, 'resize', this.resize, true); bind(window, 'orientationchange', this.resize, true); }), ], props: { show: Boolean, className: null, closeable: Boolean, beforeClose: Function, showIndicators: Boolean, images: { type: Array, default: () => [], }, loop: { type: Boolean, default: true, }, overlay: { type: Boolean, default: true, }, minZoom: { type: [Number, String], default: 1 / 3, }, maxZoom: { type: [Number, String], default: 3, }, showIndex: { type: Boolean, default: true, }, swipeDuration: { type: [Number, String], default: 500, }, startPosition: { type: [Number, String], default: 0, }, closeIcon: { type: String, default: 'clear', }, closeOnPopstate: { type: Boolean, default: true, }, closeIconPosition: { type: String, default: 'top-right', }, }, emits: ['scale', 'close', 'closed', 'change', 'update:show'], data() { return { active: 0, rootWidth: 0, rootHeight: 0, doubleClickTimer: null, }; }, mounted() { this.resize(); }, watch: { startPosition: 'setActive', show(val) { if (val) { this.setActive(+this.startPosition); this.$nextTick(() => { this.resize(); this.$refs.swipe.swipeTo(+this.startPosition, { immediate: true }); }); } else { this.$emit('close', { index: this.active, url: this.images[this.active], }); } }, }, methods: { resize() { if (this.$el && this.$el.getBoundingClientRect) { const rect = this.$el.getBoundingClientRect(); this.rootWidth = rect.width; this.rootHeight = rect.height; } }, emitClose() { callInterceptor({ interceptor: this.beforeClose, args: [this.active], done: () => { this.$emit('update:show', false); }, }); }, emitScale(args) { this.$emit('scale', args); }, setActive(active) { if (active !== this.active) { this.active = active; this.$emit('change', active); } }, genIndex() { if (this.showIndex) { return (