提交 1f094875 编写于 作者: Q qiang

fix: 修复 image 组件使用 transform 样式后,大小计算错误的问题

上级 9ee8be71
...@@ -6152,12 +6152,9 @@ ...@@ -6152,12 +6152,9 @@
}); });
watch(() => extend({}, size2), (value) => emit2("resize", value)); watch(() => extend({}, size2), (value) => emit2("resize", value));
return () => { return () => {
const { const rootEl = rootRef.value;
width, size2.width = rootEl.offsetWidth;
height size2.height = rootEl.offsetHeight;
} = rootRef.value.getBoundingClientRect();
size2.width = width;
size2.height = height;
reset2(); reset2();
}; };
} }
...@@ -6278,8 +6275,8 @@ ...@@ -6278,8 +6275,8 @@
} }
}; };
const FIX_MODES = { const FIX_MODES = {
widthFix: ["width", "height"], widthFix: ["offsetWidth", "height"],
heightFix: ["height", "width"] heightFix: ["offsetHeight", "width"]
}; };
const IMAGE_MODES = { const IMAGE_MODES = {
aspectFit: ["center center", "contain"], aspectFit: ["center center", "contain"],
...@@ -6449,8 +6446,7 @@ ...@@ -6449,8 +6446,7 @@
return; return;
} }
const rootEl = rootRef.value; const rootEl = rootRef.value;
const rect = rootEl.getBoundingClientRect(); const value = rootEl[names[0]];
const value = rect[names[0]];
if (value) { if (value) {
rootEl.style[names[1]] = fixNumber(value / ratio) + "px"; rootEl.style[names[1]] = fixNumber(value / ratio) + "px";
} }
......
...@@ -37,8 +37,8 @@ type ImageState = ReturnType<typeof useImageState> ...@@ -37,8 +37,8 @@ type ImageState = ReturnType<typeof useImageState>
type FixSize = ReturnType<typeof useImageSize>['fixSize'] type FixSize = ReturnType<typeof useImageSize>['fixSize']
const FIX_MODES = { const FIX_MODES = {
widthFix: ['width', 'height'], widthFix: ['offsetWidth', 'height'],
heightFix: ['height', 'width'], heightFix: ['offsetHeight', 'width'],
} }
const IMAGE_MODES = { const IMAGE_MODES = {
aspectFit: ['center center', 'contain'], aspectFit: ['center center', 'contain'],
...@@ -76,6 +76,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({ ...@@ -76,6 +76,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
<div style={modeStyle} /> <div style={modeStyle} />
{imgSrc ? <img src={imgSrc} draggable={props.draggable} /> : <img />} {imgSrc ? <img src={imgSrc} draggable={props.draggable} /> : <img />}
{FIX_MODES[mode as keyof typeof FIX_MODES] ? ( {FIX_MODES[mode as keyof typeof FIX_MODES] ? (
// @ts-ignore
<ResizeSensor onResize={fixSize} /> <ResizeSensor onResize={fixSize} />
) : ( ) : (
<span></span> <span></span>
...@@ -209,8 +210,7 @@ function useImageSize( ...@@ -209,8 +210,7 @@ function useImageSize(
return return
} }
const rootEl = rootRef.value! const rootEl = rootRef.value!
const rect = rootEl.getBoundingClientRect() const value = rootEl[names[0] as 'offsetWidth' | 'offsetHeight']
const value = rect[names[0] as keyof DOMRect] as number
if (value) { if (value) {
rootEl.style[names[1] as 'height' | 'width'] = rootEl.style[names[1] as 'height' | 'width'] =
fixNumber(value / ratio) + 'px' fixNumber(value / ratio) + 'px'
......
...@@ -49,9 +49,9 @@ function useResizeSensorUpdate( ...@@ -49,9 +49,9 @@ function useResizeSensorUpdate(
(value: typeof size) => emit('resize', value) (value: typeof size) => emit('resize', value)
) )
return () => { return () => {
const { width, height } = rootRef.value!.getBoundingClientRect() const rootEl = rootRef.value!
size.width = width size.width = rootEl.offsetWidth
size.height = height size.height = rootEl.offsetHeight
reset() reset()
} }
} }
......
...@@ -1573,12 +1573,9 @@ function useResizeSensorUpdate(rootRef, emit2, reset) { ...@@ -1573,12 +1573,9 @@ function useResizeSensorUpdate(rootRef, emit2, reset) {
}); });
vue.watch(() => shared.extend({}, size), (value) => emit2("resize", value)); vue.watch(() => shared.extend({}, size), (value) => emit2("resize", value));
return () => { return () => {
const { const rootEl = rootRef.value;
width, size.width = rootEl.offsetWidth;
height size.height = rootEl.offsetHeight;
} = rootRef.value.getBoundingClientRect();
size.width = width;
size.height = height;
reset(); reset();
}; };
} }
...@@ -2605,8 +2602,8 @@ const props$p = { ...@@ -2605,8 +2602,8 @@ const props$p = {
} }
}; };
const FIX_MODES = { const FIX_MODES = {
widthFix: ["width", "height"], widthFix: ["offsetWidth", "height"],
heightFix: ["height", "width"] heightFix: ["offsetHeight", "width"]
}; };
const IMAGE_MODES = { const IMAGE_MODES = {
aspectFit: ["center center", "contain"], aspectFit: ["center center", "contain"],
...@@ -2764,8 +2761,7 @@ function useImageSize(rootRef, props2, state) { ...@@ -2764,8 +2761,7 @@ function useImageSize(rootRef, props2, state) {
return; return;
} }
const rootEl = rootRef.value; const rootEl = rootRef.value;
const rect = rootEl.getBoundingClientRect(); const value = rootEl[names[0]];
const value = rect[names[0]];
if (value) { if (value) {
rootEl.style[names[1]] = fixNumber(value / ratio) + "px"; rootEl.style[names[1]] = fixNumber(value / ratio) + "px";
} }
......
...@@ -5780,12 +5780,9 @@ function useResizeSensorUpdate(rootRef, emit2, reset) { ...@@ -5780,12 +5780,9 @@ function useResizeSensorUpdate(rootRef, emit2, reset) {
}); });
watch(() => extend({}, size), (value) => emit2("resize", value)); watch(() => extend({}, size), (value) => emit2("resize", value));
return () => { return () => {
const { const rootEl = rootRef.value;
width, size.width = rootEl.offsetWidth;
height size.height = rootEl.offsetHeight;
} = rootRef.value.getBoundingClientRect();
size.width = width;
size.height = height;
reset(); reset();
}; };
} }
...@@ -7539,8 +7536,8 @@ const props$w = { ...@@ -7539,8 +7536,8 @@ const props$w = {
} }
}; };
const FIX_MODES = { const FIX_MODES = {
widthFix: ["width", "height"], widthFix: ["offsetWidth", "height"],
heightFix: ["height", "width"] heightFix: ["offsetHeight", "width"]
}; };
const IMAGE_MODES = { const IMAGE_MODES = {
aspectFit: ["center center", "contain"], aspectFit: ["center center", "contain"],
...@@ -7710,8 +7707,7 @@ function useImageSize(rootRef, props2, state2) { ...@@ -7710,8 +7707,7 @@ function useImageSize(rootRef, props2, state2) {
return; return;
} }
const rootEl = rootRef.value; const rootEl = rootRef.value;
const rect = rootEl.getBoundingClientRect(); const value = rootEl[names[0]];
const value = rect[names[0]];
if (value) { if (value) {
rootEl.style[names[1]] = fixNumber(value / ratio) + "px"; rootEl.style[names[1]] = fixNumber(value / ratio) + "px";
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册