Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/canvas/src/components/render/RenderMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ export default {
)
},
render() {
// 渲染画布增加根节点,与出码和预览保持一致
const rootChildrenSchema = {
componentName: 'div',
props: schema.props,
children: schema.children
}

return h(
'tiny-i18n-host',
{
Expand All @@ -384,9 +391,7 @@ export default {
ref: 'page',
className: 'design-page'
},
schema.children?.length
? schema.children.map((child) => h(renderer, { schema: child, parent: schema }))
: [h(CanvasEmpty)]
schema.children?.length ? h(renderer, { schema: rootChildrenSchema, parent: schema }) : [h(CanvasEmpty)]
)
}
}
Expand Down
23 changes: 19 additions & 4 deletions packages/controller/src/useProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

import { toRaw, nextTick, shallowReactive, ref } from 'vue'
import { getNode, setState, updateRect } from '@opentiny/tiny-engine-canvas'
import { constants } from '@opentiny/tiny-engine-utils'
import useCanvas from './useCanvas'
import useResource from './useResource'
import useTranslate from './useTranslate'

const { COMPONENT_NAME } = constants
const propsUpdateKey = ref(0)

const otherBaseKey = {
Expand Down Expand Up @@ -150,11 +152,18 @@ const properties = shallowReactive({
parent: null
})

const isPageOrBlock = (schema) => [COMPONENT_NAME.Block, COMPONENT_NAME.Page].includes(schema?.componentName)

const getProps = (schema, parent) => {
// 现在选中的节点和当前节点一样,不需要重新计算
if (schema && properties.schema !== schema) {
// 1 现在选中的节点和当前节点一样,不需要重新计算, 2 默认进来由于scheme和properities.schema相等,因此判断如果是“页面或者区块”需要进入if判断
if (schema && (properties.schema !== schema || isPageOrBlock(schema))) {
const { props, componentName } = schema
const { schema: metaSchema, content, properties } = useResource().getMaterial(componentName)
// 若选中的是page或者 blcok,没有对应schema,ComponentName 给 div 设置根节点属性
const {
schema: metaSchema,
content,
properties
} = useResource().getMaterial(isPageOrBlock(schema) ? 'div' : componentName)
const schemaProps = properties || metaSchema?.properties || content?.schema?.properties || []
const propGroups = [...schemaProps]

Expand Down Expand Up @@ -183,8 +192,14 @@ const setProp = (name, value) => {
}

// 没有父级,或者不在节点上面,要更新内容。就用setState
getNode(properties.schema.id, true).parent || setState(useCanvas().getPageSchema().state)
getNode(properties.schema.id, true)?.parent || setState(useCanvas().getPageSchema().state)
propsUpdateKey.value++

// 更新根节点props不用updateRect
if (!properties.schema.id) {
return
}

nextTick(updateRect)
}

Expand Down
16 changes: 13 additions & 3 deletions packages/design-core/src/DesignCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@

<script>
import { ref, onMounted, watch } from 'vue'
import { CanvasContainer, CanvasFooter, selectNode, getNodePath, updateRect } from '@opentiny/tiny-engine-canvas'
import {
CanvasContainer,
CanvasFooter,
selectNode,
getNodePath,
updateRect,
getSchema
} from '@opentiny/tiny-engine-canvas'
import {
useProperties,
useCanvas,
Expand Down Expand Up @@ -125,8 +132,11 @@ export default {
if (type !== 'clickTree') {
useLayout().closePlugin()
}
useProperties().getProps(node, parent)
useCanvas().setCurrentSchema(node)

const schema = getSchema()
// 如果选中的节点是画布,就设置成默认选中最外层schema
useProperties().getProps(node || schema, parent)
useCanvas().setCurrentSchema(node || schema)
footData.value = getNodePath(node?.id)
toolbars.visiblePopover = false
}
Expand Down