refactor: 图层样式优化

This commit is contained in:
wangjiahao 2023-12-14 19:26:46 +08:00
parent ac7046ed27
commit 5e2f2b183e
7 changed files with 30 additions and 12 deletions

View File

@ -365,7 +365,7 @@ const handleContextMenu = e => {
font-size: 12px;
margin-left: 10px;
position: relative;
min-width: 65px;
min-width: 43px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;

View File

@ -1203,6 +1203,14 @@ const linkageSetOpen = item => {
})
}
const contextMenuShow = computed(() => {
if (curComponent.value) {
return curComponent.value.canvasId === canvasId.value
} else {
return isMainCanvas(canvasId.value)
}
})
const markLineShow = computed(() => isMainCanvas(canvasId.value))
onMounted(() => {
@ -1333,7 +1341,7 @@ defineExpose({
/>
</Shape>
<!-- 右击菜单 -->
<ContextMenu show-position="canvasCore" />
<ContextMenu v-if="contextMenuShow" show-position="canvasCore" />
<!-- 标线 -->
<MarkLine v-if="markLineShow" />
<!-- 选中区域 -->

View File

@ -454,6 +454,17 @@ const handleMouseDownOnShape = e => {
) {
emit('onDragging', e)
}
//Group
element.value.component === 'Group' && groupSizeStyleAdaptor(element.value)
//Group resizegroupStyle
if (isGroupCanvas(canvasId.value)) {
groupStyleRevert(element.value, {
width: parentNode.value.offsetWidth,
height: parentNode.value.offsetHeight
})
}
// tab
if (isFirst) {
isFirst = false

View File

@ -84,8 +84,12 @@ export const composeStore = defineStore('compose', {
}
})
const newId = generateID()
components.forEach(component => {
component.canvasId = 'Group-' + newId
})
const groupComponent = {
id: generateID(),
id: newId,
component: 'Group',
name: '组合',
label: '组合',

View File

@ -2,6 +2,7 @@ import { deepCopy } from './utils'
import { divide, multiply } from 'mathjs'
import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import { storeToRefs } from 'pinia'
import { groupSizeStyleAdaptor } from '@/utils/style'
const dvMainStore = dvMainStoreWithOut()
const { componentData, curComponentIndex, canvasStyleData } = storeToRefs(dvMainStore)
@ -28,14 +29,7 @@ export function changeComponentsSizeWithScale(scale) {
// 计算逻辑 Group 中样式 * groupComponent.groupStyle[sonKey].
if (component.component === 'Group') {
try {
component.propValue.forEach(groupComponent => {
Object.keys(groupComponent.style).forEach(sonKey => {
if (groupComponent.groupStyle[sonKey]) {
groupComponent.style[sonKey] =
component.style[sonKey] * groupComponent.groupStyle[sonKey]
}
})
})
groupSizeStyleAdaptor(component)
} catch (e) {
// 旧Group适配
console.error('group adaptor error:' + e)

View File

@ -4,4 +4,5 @@ export default function decomposeComponent(component, editorRect, parentStyle) {
component.style.left = component.style.left + parentStyle.left
component.style.top = component.style.top + parentStyle.top
component.groupStyle = {}
component.canvasId = 'canvas-main'
}

View File

@ -228,7 +228,7 @@ export function groupSizeStyleAdaptor(groupComponent) {
groupComponent.propValue.forEach(component => {
// 分组还原逻辑
// 当发上分组缩放是,要将内部组件按照比例转换
const styleScale = { ...component.groupStyle }
const styleScale = component.groupStyle
component.style.left = parentStyle.width * styleScale.left
component.style.top = parentStyle.height * styleScale.top
component.style.width = parentStyle.width * styleScale.width