From f8d7eaea5ed13b2d7a8978c212705bbd130e9d3b Mon Sep 17 00:00:00 2001 From: parisma Date: Wed, 26 Oct 2022 19:00:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/editor/src/fields/CodeSelect.vue | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/editor/src/fields/CodeSelect.vue b/packages/editor/src/fields/CodeSelect.vue index 0272dfc6..b73b848b 100644 --- a/packages/editor/src/fields/CodeSelect.vue +++ b/packages/editor/src/fields/CodeSelect.vue @@ -78,19 +78,19 @@ const selectConfig = computed(() => { const fieldKey = ref(''); const multiple = ref(true); let lastTagSnapshot = cloneDeep(props.model[props.name]) || []; -let shouldWatch = true; -// 管理端和editor有表现不一致的地方,管理端切换组件表单不会重新渲染,因此增加shouldWatch控制lastTagSnapshot的记录 +// 管理端和editor有表现不一致的地方,管理端切换组件表单不会重新渲染,通过setTimeout确保lastTagSnapshot的准确性 watch( () => props.model[props.name], (selectValue) => { - if (shouldWatch) { + setTimeout(() => { lastTagSnapshot = cloneDeep(selectValue) || []; - } + }); }, ); watchEffect(async () => { + if (!props.model[props.name]) return; const combineNames = await Promise.all( props.model[props.name].map(async (id: string) => { const { name = '' } = (await services?.codeBlockService.getCodeContentById(id)) || {}; @@ -101,11 +101,9 @@ watchEffect(async () => { }); const changeHandler = async (value: any) => { - shouldWatch = false; let codeIds = value; if (typeof value === 'string') { multiple.value = false; - lastTagSnapshot = [lastTagSnapshot]; codeIds = value ? [value] : []; } await setCombineRelation(codeIds); @@ -124,11 +122,8 @@ const setCombineRelation = async (codeIds: string[]) => { opFlag = codeIds.length < lastTagSnapshot.length ? CodeSelectOp.DELETE : CodeSelectOp.ADD; diffValues = xor(codeIds, lastTagSnapshot) as string[]; } - // 记录绑定关系 await services?.codeBlockService.setCombineRelation(id, diffValues, opFlag, props.prop); - lastTagSnapshot = codeIds; - shouldWatch = true; }; const viewHandler = async () => {