From 249bd9e3189879fbc09b97f299e8851e342311c7 Mon Sep 17 00:00:00 2001 From: Huangzhe Date: Tue, 25 Mar 2025 18:40:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=E9=80=89?= =?UTF-8?q?=E6=8E=92=E5=AE=83=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复options 获取的数据源 --- .../Design/components/Questions/Choice.vue | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/views/Design/components/Questions/Choice.vue b/src/views/Design/components/Questions/Choice.vue index c129ecb..2775851 100644 --- a/src/views/Design/components/Questions/Choice.vue +++ b/src/views/Design/components/Questions/Choice.vue @@ -156,12 +156,26 @@ function handleChange(names) { const newOption = names[names.length - 1]; // 如果names 长度小于1,直接返回,不处理 if (names.length < 1) return; - // 如果不存在 options 和 list 属性,直接返回 - if (!element.value.options || !element.value.list) return; - const options = element.value.options[0] ?? element.value.list[0]; - // 如果新增的结果是排它项, 对结果进行处理 - if (options[newOption - 1]?.is_remove_other === 1) { + let options; + + try { + options = element.value.options[0].options ?? element.value.list[0]; + } catch (e) { + options = element.value.options[0]; + } + + // 如果不存在 options 和 list 属性,直接返回 + if (!options) return; + + // 如果 names 里面有其他的排它项,就把排它项的值去除 + for (const option of options) { + if (option.is_remove_other === 1 && newOption !== option.option_index) { + value.value = value.value.filter((item) => item !== option.option_index); + } + } + + if (options[Number(newOption) - 1]?.is_remove_other === 1) { value.value = [newOption]; } }