fix(editor): 设置高亮节点操作一定要在刷新展开状态之后,否则可能导致设置的高亮无效

#404
This commit is contained in:
parisma 2022-10-14 18:08:31 +08:00 committed by jia000
parent 40410292d7
commit 2c31caf34f

View File

@ -66,7 +66,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, inject, ref, watch } from 'vue'; import { computed, inject, nextTick, ref, watch } from 'vue';
import { Search } from '@element-plus/icons-vue'; import { Search } from '@element-plus/icons-vue';
import KeyController from 'keycon'; import KeyController from 'keycon';
import { throttle } from 'lodash-es'; import { throttle } from 'lodash-es';
@ -207,34 +207,28 @@ const filterTextChangeHandler = (val: string) => {
tree.value?.filter(val); tree.value?.filter(val);
}; };
// //
const expandNodes = () => { const expandNodes = async () => {
if (!tree.value) return;
await nextTick();
tree.value &&
Object.entries(tree.value.getStore().nodesMap).forEach(([id, node]: [string, any]) => {
if (node.expanded && node.data.items) {
expandedKeys.set(id, id);
}
});
expandedKeys.forEach((key) => { expandedKeys.forEach((key) => {
if (!tree.value) return; if (!tree.value) return;
tree.value.getNode(key)?.expand(); tree.value.getNode(key)?.expand();
}); });
}; };
watch([() => editorService?.get('nodes'), tree], ([nodes]) => { watch(
if (!tree.value || !editorService || !nodes) return; () => editorService?.get<MNode[]>('nodes'),
selectedNodes.value = nodes as unknown as MNode[]; (nodes) => {
selectedNodes.value = nodes ?? [];
const parent = editorService.get('parent'); },
if (!parent?.id) return; );
const treeNode = tree.value.getNode(parent.id);
treeNode?.updateChildren();
setTimeout(() => {
tree.value &&
Object.entries(tree.value.getStore().nodesMap).forEach(([id, node]: [string, any]) => {
if (node.expanded && node.data.items) {
expandedKeys.set(id, id);
}
});
expandNodes();
});
});
// //
const setTreeKeyStatus = () => { const setTreeKeyStatus = () => {
@ -253,7 +247,16 @@ const setTreeKeyStatus = () => {
} }
}; };
watch(selectedIds, () => { watch([selectedIds, tree], async () => {
if (!tree.value || !editorService) return;
const parent = editorService.get('parent');
if (!parent?.id) return;
const treeNode = tree.value.getNode(parent.id);
treeNode?.updateChildren();
await expandNodes();
//
setTreeKeyStatus(); setTreeKeyStatus();
}); });