mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-17 03:03:41 +00:00
perf: 优化图片预览缩放
This commit is contained in:
parent
cbaa5c3464
commit
6bd8c590ab
1
public/js/pinch-zoom.umd.min.js
vendored
Normal file
1
public/js/pinch-zoom.umd.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -28,6 +28,12 @@ import 'photoswipe/style.css';
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
|
className: {
|
||||||
|
type: String,
|
||||||
|
default: () => {
|
||||||
|
return "preview-image-swipe-" + Math.round(Math.random() * 10000);
|
||||||
|
}
|
||||||
|
},
|
||||||
urlList: {
|
urlList: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => []
|
default: () => []
|
||||||
@ -48,6 +54,8 @@ export default {
|
|||||||
watch: {
|
watch: {
|
||||||
urlList: {
|
urlList: {
|
||||||
handler(array) {
|
handler(array) {
|
||||||
|
let dragIng = false
|
||||||
|
let htmlZoom = false;
|
||||||
this.lightbox?.destroy();
|
this.lightbox?.destroy();
|
||||||
const dataSource = array.map(item => {
|
const dataSource = array.map(item => {
|
||||||
if ($A.isJson(item)) {
|
if ($A.isJson(item)) {
|
||||||
@ -59,6 +67,7 @@ export default {
|
|||||||
}
|
}
|
||||||
item = item.src;
|
item = item.src;
|
||||||
}
|
}
|
||||||
|
htmlZoom = true;
|
||||||
return {
|
return {
|
||||||
html: `<div class="preview-image-swipe"><img src="${$A.rightDelete(item, "_thumb.jpg")}"/></div>`,
|
html: `<div class="preview-image-swipe"><img src="${$A.rightDelete(item, "_thumb.jpg")}"/></div>`,
|
||||||
}
|
}
|
||||||
@ -66,9 +75,38 @@ export default {
|
|||||||
this.lightbox = new PhotoSwipeLightbox({
|
this.lightbox = new PhotoSwipeLightbox({
|
||||||
dataSource,
|
dataSource,
|
||||||
escKey: false,
|
escKey: false,
|
||||||
|
mainClass: this.className,
|
||||||
showHideAnimationType: 'none',
|
showHideAnimationType: 'none',
|
||||||
pswpModule: () => import('photoswipe'),
|
pswpModule: () => import('photoswipe'),
|
||||||
});
|
});
|
||||||
|
this.lightbox.on('change', () => {
|
||||||
|
if (htmlZoom) {
|
||||||
|
$A.loadScript('js/pinch-zoom.umd.min.js', _ => {
|
||||||
|
if (PinchZoom !== 'object') {
|
||||||
|
const swiperItems = document.querySelector(`.${this.className}`).querySelectorAll(".preview-image-swipe")
|
||||||
|
swiperItems.forEach(swipeItem => {
|
||||||
|
if (swipeItem.getAttribute("data-init-pinch-zoom") !== "init") {
|
||||||
|
swipeItem.setAttribute("data-init-pinch-zoom", "init")
|
||||||
|
swipeItem.querySelector("img").addEventListener("pointermove", e => {
|
||||||
|
if (dragIng) {
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
new PinchZoom.default(swipeItem, {
|
||||||
|
draggableUnzoomed: false,
|
||||||
|
onDragStart: () => {
|
||||||
|
dragIng = true;
|
||||||
|
},
|
||||||
|
onDragEnd: () => {
|
||||||
|
dragIng = false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
this.lightbox.on('close', () => {
|
this.lightbox.on('close', () => {
|
||||||
this.$emit("on-close")
|
this.$emit("on-close")
|
||||||
});
|
});
|
||||||
|
|||||||
1
resources/assets/statics/public/js/pinch-zoom.umd.min.js
vendored
Normal file
1
resources/assets/statics/public/js/pinch-zoom.umd.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user