diff --git a/packages/canvas/src/components/render/RenderMain.js b/packages/canvas/src/components/render/RenderMain.js index 532821b..922b354 100644 --- a/packages/canvas/src/components/render/RenderMain.js +++ b/packages/canvas/src/components/render/RenderMain.js @@ -376,6 +376,13 @@ export default { ) }, render() { + // 渲染画布增加根节点,与出码和预览保持一致 + const rootChildrenSchema = { + componentName: 'div', + props: schema.props, + children: schema.children + } + return h( 'tiny-i18n-host', { @@ -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)] ) } } diff --git a/packages/controller/src/useProperties.js b/packages/controller/src/useProperties.js index 81e132a..44181e5 100644 --- a/packages/controller/src/useProperties.js +++ b/packages/controller/src/useProperties.js @@ -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 = { @@ -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] @@ -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) } diff --git a/packages/design-core/src/DesignCanvas.vue b/packages/design-core/src/DesignCanvas.vue index 21dcb7a..3cafb4d 100644 --- a/packages/design-core/src/DesignCanvas.vue +++ b/packages/design-core/src/DesignCanvas.vue @@ -15,7 +15,14 @@