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']