From 684c61536f6d1d76881e43d51ab773d7120893ae Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Thu, 8 Aug 2024 19:05:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=95=B0=E6=8D=AE=E5=A4=A7=E5=B1=8F):=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=A7=E5=B1=8F=E6=94=AF=E6=8C=81=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E4=BC=B8=E7=BC=A9=E6=96=B9=E5=BC=8F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/changeComponentsSizeWithScale.ts | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/core/core-frontend/src/utils/changeComponentsSizeWithScale.ts b/core/core-frontend/src/utils/changeComponentsSizeWithScale.ts index 950d8916ca..1bd6efdd84 100644 --- a/core/core-frontend/src/utils/changeComponentsSizeWithScale.ts +++ b/core/core-frontend/src/utils/changeComponentsSizeWithScale.ts @@ -8,16 +8,24 @@ const dvMainStore = dvMainStoreWithOut() const { componentData, curComponentIndex, canvasStyleData } = storeToRefs(dvMainStore) const needToChangeAttrs = ['top', 'left', 'width', 'height', 'fontSize', 'letterSpacing'] +const needToChangeDirectionAttrs = { + width: ['left', 'width', 'fontSize', 'letterSpacing'], + height: ['top', 'height'] +} export function changeSizeWithScale(scale) { return changeComponentsSizeWithScale(scale) } -export function changeComponentsSizeWithScale(scale) { +export function changeSizeWithDirectionScale(scale, direction) { + return changeComponentsSizeWithScale(scale, needToChangeDirectionAttrs[direction]) +} + +export function changeComponentsSizeWithScale(scale, changeAttrs = needToChangeAttrs) { const componentDataCopy = deepCopy(componentData.value) componentDataCopy.forEach(component => { Object.keys(component.style).forEach(key => { - if (needToChangeAttrs.includes(key)) { + if (changeAttrs.includes(key)) { if (key === 'fontSize' && component.style[key] === '') return // 根据原来的比例获取样式原来的尺寸 // 再用原来的尺寸 * 现在的比例得出新的尺寸 @@ -52,21 +60,35 @@ export function changeComponentsSizeWithScale(scale) { }) } -export function changeRefComponentsSizeWithScale(componentDataRef, canvasStyleDataRef, scale) { +export function changeRefComponentsSizeWithScale( + componentDataRef, + canvasStyleDataRef, + scaleWidth, + scaleHeight +) { componentDataRef.forEach(component => { Object.keys(component.style).forEach(key => { - if (needToChangeAttrs.includes(key)) { - if (key === 'fontSize' && component.style[key] === '') return + if (key === 'fontSize' && component.style[key] === '') return + if (needToChangeDirectionAttrs.width.includes(key)) { // 根据原来的比例获取样式原来的尺寸 // 再用原来的尺寸 * 现在的比例得出新的尺寸 component.style[key] = format( getOriginStyle(component.style[key], canvasStyleDataRef.scale), - scale + scaleWidth + ) + } else if (needToChangeDirectionAttrs.height.includes(key)) { + // 根据原来的比例获取样式原来的尺寸 + // 再用原来的尺寸 * 现在的比例得出新的尺寸 + component.style[key] = format( + getOriginStyle(component.style[key], canvasStyleDataRef.scale), + scaleHeight ) } }) }) - canvasStyleDataRef.scale = scale + canvasStyleDataRef.scale = scaleWidth + canvasStyleDataRef.scaleWidth = scaleWidth + canvasStyleDataRef.scaleHeight = scaleHeight } const needToChangeAttrs2 = ['width', 'height', 'fontSize']