From 1f09487560f14b7f03c83e45f789a2b1abb615d0 Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 29 Jun 2021 14:44:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20image=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E4=BD=BF=E7=94=A8=20transform=20=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E5=A4=A7=E5=B0=8F=E8=AE=A1=E7=AE=97=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-app-plus/dist/uni-app-view.umd.js | 16 ++++++---------- .../src/components/image/index.tsx | 8 ++++---- .../src/components/resize-sensor/index.tsx | 6 +++--- packages/uni-h5/dist/uni-h5.cjs.js | 16 ++++++---------- packages/uni-h5/dist/uni-h5.es.js | 16 ++++++---------- 5 files changed, 25 insertions(+), 37 deletions(-) diff --git a/packages/uni-app-plus/dist/uni-app-view.umd.js b/packages/uni-app-plus/dist/uni-app-view.umd.js index ec5614398..383821ad8 100644 --- a/packages/uni-app-plus/dist/uni-app-view.umd.js +++ b/packages/uni-app-plus/dist/uni-app-view.umd.js @@ -6152,12 +6152,9 @@ }); watch(() => extend({}, size2), (value) => emit2("resize", value)); return () => { - const { - width, - height - } = rootRef.value.getBoundingClientRect(); - size2.width = width; - size2.height = height; + const rootEl = rootRef.value; + size2.width = rootEl.offsetWidth; + size2.height = rootEl.offsetHeight; reset2(); }; } @@ -6278,8 +6275,8 @@ } }; const FIX_MODES = { - widthFix: ["width", "height"], - heightFix: ["height", "width"] + widthFix: ["offsetWidth", "height"], + heightFix: ["offsetHeight", "width"] }; const IMAGE_MODES = { aspectFit: ["center center", "contain"], @@ -6449,8 +6446,7 @@ return; } const rootEl = rootRef.value; - const rect = rootEl.getBoundingClientRect(); - const value = rect[names[0]]; + const value = rootEl[names[0]]; if (value) { rootEl.style[names[1]] = fixNumber(value / ratio) + "px"; } diff --git a/packages/uni-components/src/components/image/index.tsx b/packages/uni-components/src/components/image/index.tsx index bda17927d..b7491ac52 100644 --- a/packages/uni-components/src/components/image/index.tsx +++ b/packages/uni-components/src/components/image/index.tsx @@ -37,8 +37,8 @@ type ImageState = ReturnType type FixSize = ReturnType['fixSize'] const FIX_MODES = { - widthFix: ['width', 'height'], - heightFix: ['height', 'width'], + widthFix: ['offsetWidth', 'height'], + heightFix: ['offsetHeight', 'width'], } const IMAGE_MODES = { aspectFit: ['center center', 'contain'], @@ -76,6 +76,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
{imgSrc ? : } {FIX_MODES[mode as keyof typeof FIX_MODES] ? ( + // @ts-ignore ) : ( @@ -209,8 +210,7 @@ function useImageSize( return } const rootEl = rootRef.value! - const rect = rootEl.getBoundingClientRect() - const value = rect[names[0] as keyof DOMRect] as number + const value = rootEl[names[0] as 'offsetWidth' | 'offsetHeight'] if (value) { rootEl.style[names[1] as 'height' | 'width'] = fixNumber(value / ratio) + 'px' diff --git a/packages/uni-components/src/components/resize-sensor/index.tsx b/packages/uni-components/src/components/resize-sensor/index.tsx index 779c4174b..ceb880c2a 100644 --- a/packages/uni-components/src/components/resize-sensor/index.tsx +++ b/packages/uni-components/src/components/resize-sensor/index.tsx @@ -49,9 +49,9 @@ function useResizeSensorUpdate( (value: typeof size) => emit('resize', value) ) return () => { - const { width, height } = rootRef.value!.getBoundingClientRect() - size.width = width - size.height = height + const rootEl = rootRef.value! + size.width = rootEl.offsetWidth + size.height = rootEl.offsetHeight reset() } } diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index f315388f1..88221dce3 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -1573,12 +1573,9 @@ function useResizeSensorUpdate(rootRef, emit2, reset) { }); vue.watch(() => shared.extend({}, size), (value) => emit2("resize", value)); return () => { - const { - width, - height - } = rootRef.value.getBoundingClientRect(); - size.width = width; - size.height = height; + const rootEl = rootRef.value; + size.width = rootEl.offsetWidth; + size.height = rootEl.offsetHeight; reset(); }; } @@ -2605,8 +2602,8 @@ const props$p = { } }; const FIX_MODES = { - widthFix: ["width", "height"], - heightFix: ["height", "width"] + widthFix: ["offsetWidth", "height"], + heightFix: ["offsetHeight", "width"] }; const IMAGE_MODES = { aspectFit: ["center center", "contain"], @@ -2764,8 +2761,7 @@ function useImageSize(rootRef, props2, state) { return; } const rootEl = rootRef.value; - const rect = rootEl.getBoundingClientRect(); - const value = rect[names[0]]; + const value = rootEl[names[0]]; if (value) { rootEl.style[names[1]] = fixNumber(value / ratio) + "px"; } diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index fb02b6c9d..40edf0770 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -5780,12 +5780,9 @@ function useResizeSensorUpdate(rootRef, emit2, reset) { }); watch(() => extend({}, size), (value) => emit2("resize", value)); return () => { - const { - width, - height - } = rootRef.value.getBoundingClientRect(); - size.width = width; - size.height = height; + const rootEl = rootRef.value; + size.width = rootEl.offsetWidth; + size.height = rootEl.offsetHeight; reset(); }; } @@ -7539,8 +7536,8 @@ const props$w = { } }; const FIX_MODES = { - widthFix: ["width", "height"], - heightFix: ["height", "width"] + widthFix: ["offsetWidth", "height"], + heightFix: ["offsetHeight", "width"] }; const IMAGE_MODES = { aspectFit: ["center center", "contain"], @@ -7710,8 +7707,7 @@ function useImageSize(rootRef, props2, state2) { return; } const rootEl = rootRef.value; - const rect = rootEl.getBoundingClientRect(); - const value = rect[names[0]]; + const value = rootEl[names[0]]; if (value) { rootEl.style[names[1]] = fixNumber(value / ratio) + "px"; } -- GitLab