将滚轮事件监听从 img 标签移至父 div

将滚轮事件监听从 img 标签移至父 div,以简化代码结构并提升可维护性。同时调整了相关样式和事件绑定的逻辑。
This commit is contained in:
theluyuan 2025-04-15 10:32:23 +08:00
parent 74e66728f8
commit 371ea1495b
6 changed files with 35 additions and 36 deletions

View File

@ -1,5 +1,5 @@
import { w as withInstall } from "../badge/index2.js"; import { w as withInstall } from "../badge/index2.js";
import { defineComponent, computed, openBlock, createElementBlock, normalizeStyle, unref, createCommentVNode, toDisplayString, normalizeClass, ref, watch, onMounted, nextTick, createElementVNode, withModifiers, Fragment, renderList, shallowRef, createTextVNode, createVNode, useSlots, inject, Transition, withCtx, createBlock, renderSlot, h, render, isVNode, getCurrentInstance, onUnmounted } from "vue"; import { defineComponent, computed, openBlock, createElementBlock, normalizeStyle, unref, createCommentVNode, toDisplayString, normalizeClass, ref, watch, onMounted, nextTick, withModifiers, createElementVNode, Fragment, renderList, shallowRef, createTextVNode, createVNode, useSlots, inject, Transition, withCtx, createBlock, renderSlot, h, render, isVNode, getCurrentInstance, onUnmounted } from "vue";
import { I as ImageCompressor } from "../_chunks/js-image-compressor/index.js"; import { I as ImageCompressor } from "../_chunks/js-image-compressor/index.js";
import { t as templateRef } from "../_chunks/@vueuse/index.js"; import { t as templateRef } from "../_chunks/@vueuse/index.js";
import { _ as _sfc_main$9 } from "../button/index2.js"; import { _ as _sfc_main$9 } from "../button/index2.js";
@ -632,10 +632,8 @@ function _objectSpread$3(e) {
} }
return e; return e;
} }
var _hoisted_1$2 = { var _hoisted_1$2 = ["onWheel"];
class: "layui-layer-phimg" var _hoisted_2$2 = ["src"];
};
var _hoisted_2$2 = ["src", "onWheel"];
var _hoisted_3$2 = { var _hoisted_3$2 = {
key: 0, key: 0,
class: "layui-layer-imgsee" class: "layui-layer-imgsee"
@ -711,13 +709,15 @@ var _sfc_main$2 = defineComponent(_objectSpread$3(_objectSpread$3({}, __default_
scale.value = Math.min(Math.max(newScale, 0.5), 3); scale.value = Math.min(Math.max(newScale, 0.5), 3);
}; };
return function(_ctx, _cache) { return function(_ctx, _cache) {
return openBlock(), createElementBlock("div", _hoisted_1$2, [createElementVNode("img", { return openBlock(), createElementBlock("div", {
src: __props.imgList[index2.value].src, class: "layui-layer-phimg",
onWheel: withModifiers(handleWheel, ["prevent"]), onWheel: withModifiers(handleWheel, ["prevent"]),
style: normalizeStyle({ style: normalizeStyle({
transform: "scale(".concat(scale.value, ")") transform: "scale(".concat(scale.value, ")")
}) })
}, null, 44, _hoisted_2$2), __props.imgList.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_3$2, [__props.imgList.length > 1 ? (openBlock(), createElementBlock("span", _hoisted_4$1, [createElementVNode("a", { }, [createElementVNode("img", {
src: __props.imgList[index2.value].src
}, null, 8, _hoisted_2$2), __props.imgList.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_3$2, [__props.imgList.length > 1 ? (openBlock(), createElementBlock("span", _hoisted_4$1, [createElementVNode("a", {
href: "javascript:;", href: "javascript:;",
class: "layui-layer-iconext layui-layer-imgprev", class: "layui-layer-iconext layui-layer-imgprev",
onClick: _cache[0] || (_cache[0] = function($event) { onClick: _cache[0] || (_cache[0] = function($event) {
@ -750,7 +750,7 @@ var _sfc_main$2 = defineComponent(_objectSpread$3(_objectSpread$3({}, __default_
style: normalizeStyle({ style: normalizeStyle({
left: "calc(calc( calc(100% - ".concat(100 * __props.imgList.length, "px) / 2) + ").concat(index2.value * 100, "px)") left: "calc(calc( calc(100% - ".concat(100 * __props.imgList.length, "px) / 2) + ").concat(index2.value * 100, "px)")
}) })
}, null, 4)])) : (openBlock(), createElementBlock("span", _hoisted_8$1, [__props.imgList[index2.value].alt ? (openBlock(), createElementBlock("span", _hoisted_9, toDisplayString(__props.imgList[index2.value].alt), 1)) : createCommentVNode("", true), __props.imgList.length > 1 ? (openBlock(), createElementBlock("em", _hoisted_10, toDisplayString(index2.value + 1) + " / " + toDisplayString(__props.imgList.length), 1)) : createCommentVNode("", true)]))], 4)) : createCommentVNode("", true)])) : createCommentVNode("", true)]); }, null, 4)])) : (openBlock(), createElementBlock("span", _hoisted_8$1, [__props.imgList[index2.value].alt ? (openBlock(), createElementBlock("span", _hoisted_9, toDisplayString(__props.imgList[index2.value].alt), 1)) : createCommentVNode("", true), __props.imgList.length > 1 ? (openBlock(), createElementBlock("em", _hoisted_10, toDisplayString(index2.value + 1) + " / " + toDisplayString(__props.imgList.length), 1)) : createCommentVNode("", true)]))], 4)) : createCommentVNode("", true)])) : createCommentVNode("", true)], 44, _hoisted_1$2);
}; };
} }
})); }));

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
import { defineComponent, computed, openBlock, createElementBlock, normalizeStyle, unref, createCommentVNode, toDisplayString, normalizeClass, ref, watch, onMounted, nextTick, createElementVNode, withModifiers, Fragment, renderList, shallowRef, createTextVNode, createVNode, useSlots, inject, Transition, withCtx, createBlock, renderSlot, h, render, isVNode } from "vue"; import { defineComponent, computed, openBlock, createElementBlock, normalizeStyle, unref, createCommentVNode, toDisplayString, normalizeClass, ref, watch, onMounted, nextTick, withModifiers, createElementVNode, Fragment, renderList, shallowRef, createTextVNode, createVNode, useSlots, inject, Transition, withCtx, createBlock, renderSlot, h, render, isVNode } from "vue";
function _typeof$1(o) { function _typeof$1(o) {
"@babel/helpers - typeof"; "@babel/helpers - typeof";
return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) { return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
@ -625,10 +625,8 @@ function _objectSpread$3(e) {
} }
return e; return e;
} }
var _hoisted_1$2 = { var _hoisted_1$2 = ["onWheel"];
class: "layui-layer-phimg" var _hoisted_2$2 = ["src"];
};
var _hoisted_2$2 = ["src", "onWheel"];
var _hoisted_3$2 = { var _hoisted_3$2 = {
key: 0, key: 0,
class: "layui-layer-imgsee" class: "layui-layer-imgsee"
@ -704,13 +702,15 @@ var _sfc_main$2 = defineComponent(_objectSpread$3(_objectSpread$3({}, __default_
scale.value = Math.min(Math.max(newScale, 0.5), 3); scale.value = Math.min(Math.max(newScale, 0.5), 3);
}; };
return function(_ctx, _cache) { return function(_ctx, _cache) {
return openBlock(), createElementBlock("div", _hoisted_1$2, [createElementVNode("img", { return openBlock(), createElementBlock("div", {
src: __props.imgList[index2.value].src, class: "layui-layer-phimg",
onWheel: withModifiers(handleWheel, ["prevent"]), onWheel: withModifiers(handleWheel, ["prevent"]),
style: normalizeStyle({ style: normalizeStyle({
transform: "scale(".concat(scale.value, ")") transform: "scale(".concat(scale.value, ")")
}) })
}, null, 44, _hoisted_2$2), __props.imgList.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_3$2, [__props.imgList.length > 1 ? (openBlock(), createElementBlock("span", _hoisted_4$1, [createElementVNode("a", { }, [createElementVNode("img", {
src: __props.imgList[index2.value].src
}, null, 8, _hoisted_2$2), __props.imgList.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_3$2, [__props.imgList.length > 1 ? (openBlock(), createElementBlock("span", _hoisted_4$1, [createElementVNode("a", {
href: "javascript:;", href: "javascript:;",
class: "layui-layer-iconext layui-layer-imgprev", class: "layui-layer-iconext layui-layer-imgprev",
onClick: _cache[0] || (_cache[0] = function($event) { onClick: _cache[0] || (_cache[0] = function($event) {
@ -743,7 +743,7 @@ var _sfc_main$2 = defineComponent(_objectSpread$3(_objectSpread$3({}, __default_
style: normalizeStyle({ style: normalizeStyle({
left: "calc(calc( calc(100% - ".concat(100 * __props.imgList.length, "px) / 2) + ").concat(index2.value * 100, "px)") left: "calc(calc( calc(100% - ".concat(100 * __props.imgList.length, "px) / 2) + ").concat(index2.value * 100, "px)")
}) })
}, null, 4)])) : (openBlock(), createElementBlock("span", _hoisted_8$1, [__props.imgList[index2.value].alt ? (openBlock(), createElementBlock("span", _hoisted_9, toDisplayString(__props.imgList[index2.value].alt), 1)) : createCommentVNode("", true), __props.imgList.length > 1 ? (openBlock(), createElementBlock("em", _hoisted_10, toDisplayString(index2.value + 1) + " / " + toDisplayString(__props.imgList.length), 1)) : createCommentVNode("", true)]))], 4)) : createCommentVNode("", true)])) : createCommentVNode("", true)]); }, null, 4)])) : (openBlock(), createElementBlock("span", _hoisted_8$1, [__props.imgList[index2.value].alt ? (openBlock(), createElementBlock("span", _hoisted_9, toDisplayString(__props.imgList[index2.value].alt), 1)) : createCommentVNode("", true), __props.imgList.length > 1 ? (openBlock(), createElementBlock("em", _hoisted_10, toDisplayString(index2.value + 1) + " / " + toDisplayString(__props.imgList.length), 1)) : createCommentVNode("", true)]))], 4)) : createCommentVNode("", true)])) : createCommentVNode("", true)], 44, _hoisted_1$2);
}; };
} }
})); }));

File diff suppressed because one or more lines are too long

View File

@ -1,11 +1,10 @@
<template> <template>
<div class="layui-layer-phimg"> <div
<!-- img 标签添加滚轮事件监听 --> class="layui-layer-phimg"
<img @wheel.prevent="handleWheel"
:src="imgList[index].src" :style="{ transform: `scale(${scale})` }"
@wheel.prevent="handleWheel" >
:style="{ transform: `scale(${scale})` }" <img :src="imgList[index].src" />
/>
<div class="layui-layer-imgsee" v-if="imgList.length > 0"> <div class="layui-layer-imgsee" v-if="imgList.length > 0">
<span class="layui-layer-imguide" v-if="imgList.length > 1"> <span class="layui-layer-imguide" v-if="imgList.length > 1">
<a <a