fix(editor): 没有页面时,添加页面出错

This commit is contained in:
roymondchen 2022-08-31 15:01:21 +08:00 committed by jia000
parent 13ef262bc2
commit e67cbceb7d
2 changed files with 10 additions and 4 deletions

View File

@ -193,9 +193,15 @@ export default defineComponent({
emits: ['props-panel-mounted', 'update:modelValue'], emits: ['props-panel-mounted', 'update:modelValue'],
setup(props, { emit }) { setup(props, { emit }) {
editorService.on('root-change', () => { editorService.on('root-change', (value) => {
const node = editorService.get<MNode | null>('node') || props.defaultSelected; const node = editorService.get<MNode | null>('node');
node && editorService.select(node); const nodeId = node?.id || props.defaultSelected;
if (nodeId && node !== value) {
editorService.select(nodeId);
} else {
editorService.set('nodes', [value]);
}
emit('update:modelValue', toRaw(editorService.get('root'))); emit('update:modelValue', toRaw(editorService.get('root')));
}); });

View File

@ -400,7 +400,7 @@ class Editor extends BaseService {
await this.select(root.items[0]); await this.select(root.items[0]);
stage?.select(root.items[0].id); stage?.select(root.items[0].id);
} else { } else {
this.set('node', null); this.set('nodes', [root]);
this.set('parent', null); this.set('parent', null);
this.set('page', null); this.set('page', null);
this.set('stage', null); this.set('stage', null);