fix(editor): 修复优化性能引起的问题,支持回退撤销对代码关系的更新

This commit is contained in:
parisma 2023-02-17 15:06:21 +08:00 committed by roymondchen
parent 8102aaeb12
commit 010918198a
3 changed files with 16 additions and 6 deletions

View File

@ -87,7 +87,7 @@
</template>
<script lang="ts" setup name="MEditorCodeBlockList">
import { computed, inject, onMounted, reactive, ref, watch } from 'vue';
import { computed, inject, reactive, ref, watch } from 'vue';
import { Close, Edit, Link, View } from '@element-plus/icons-vue';
import { cloneDeep, forIn, isEmpty } from 'lodash-es';
@ -152,10 +152,13 @@ const refreshCodeList = async () => {
});
};
onMounted(() => {
services?.codeBlockService.refreshAllRelations();
refreshCodeList();
});
watch(
() => services?.editorService.get('root'),
() => {
services?.codeBlockService.refreshAllRelations();
refreshCodeList();
},
);
watch(
[() => services?.codeBlockService.getCodeDslSync(), () => services?.codeBlockService.getCombineInfo()],

View File

@ -19,7 +19,7 @@
import { reactive } from 'vue';
import { cloneDeep, forIn, isEmpty, keys, omit, pick, union } from 'lodash-es';
import { CodeBlockContent, CodeBlockDSL, HookType, Id, MNode } from '@tmagic/schema';
import { CodeBlockContent, CodeBlockDSL, HookType, Id, MNode, MPage } from '@tmagic/schema';
import editorService from '../services/editor';
import type { CodeRelation, CodeState, HookData } from '../type';
@ -251,6 +251,12 @@ class CodeBlock extends BaseService {
this.state.relations = this.deleteNodeRelation(node, this.state.relations);
});
});
// 监听历史记录,历史快照为页面整体,需要深层遍历更新
editorService.on('history-change', (page: MPage) => {
const relations: CodeRelation = {};
this.getNodeRelation(page, relations, true);
this.state.relations = relations;
});
}
/**

View File

@ -886,6 +886,7 @@ class Editor extends BaseService {
await this.select(value.nodeId);
this.get('stage')?.select(value.nodeId);
}, 0);
this.emit('history-change', value.data);
}
private async toggleFixedPosition(dist: MNode, src: MNode, root: MApp) {