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; font-size: 12px;
margin-left: 10px; margin-left: 10px;
position: relative; position: relative;
min-width: 65px; min-width: 43px;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; 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)) const markLineShow = computed(() => isMainCanvas(canvasId.value))
onMounted(() => { onMounted(() => {
@ -1333,7 +1341,7 @@ defineExpose({
/> />
</Shape> </Shape>
<!-- 右击菜单 --> <!-- 右击菜单 -->
<ContextMenu show-position="canvasCore" /> <ContextMenu v-if="contextMenuShow" show-position="canvasCore" />
<!-- 标线 --> <!-- 标线 -->
<MarkLine v-if="markLineShow" /> <MarkLine v-if="markLineShow" />
<!-- 选中区域 --> <!-- 选中区域 -->

View File

@ -454,6 +454,17 @@ const handleMouseDownOnShape = e => {
) { ) {
emit('onDragging', 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 // tab
if (isFirst) { if (isFirst) {
isFirst = false 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 = { const groupComponent = {
id: generateID(), id: newId,
component: 'Group', component: 'Group',
name: '组合', name: '组合',
label: '组合', label: '组合',

View File

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

View File

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