From de2af7931f6f013445e8ea69093d5c40e13bff88 Mon Sep 17 00:00:00 2001 From: alwayrun Date: Tue, 28 May 2024 18:16:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E9=87=8D=E6=9E=84=20s?= =?UTF-8?q?etters=20=E7=BB=84=E4=BB=B6=E4=B8=8B=E5=87=A0=E5=A4=84=20watch?= =?UTF-8?q?=20=E5=88=9D=E5=A7=8B=E5=80=BC=E5=BC=95=E5=8F=91=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E7=9B=91=E5=90=AC=E9=97=AE=E9=A2=98=20(#178)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../materials/setters/widgets/CheckBox.vue | 46 ++++++++++--------- .../setters/widgets/FormdataBackFill.vue | 22 +++++---- .../materials/setters/widgets/InputSetter.vue | 14 +++--- .../setters/widgets/QuestionTime.vue | 7 +-- .../setters/widgets/QuestionTimeHour.vue | 5 +- .../materials/setters/widgets/RadioGroup.vue | 5 +- .../materials/setters/widgets/RadioSetter.vue | 5 +- .../setters/widgets/SelectSetter.vue | 8 ++-- 8 files changed, 60 insertions(+), 52 deletions(-) diff --git a/web/src/materials/setters/widgets/CheckBox.vue b/web/src/materials/setters/widgets/CheckBox.vue index 4fe7df9a..6df14725 100644 --- a/web/src/materials/setters/widgets/CheckBox.vue +++ b/web/src/materials/setters/widgets/CheckBox.vue @@ -38,32 +38,34 @@ const handleCheckboxChange = (value: boolean) => { emit(FORM_CHANGE_EVENT_KEY, { key, value }) } -const watchOptionOrigin = computed(() => props.moduleConfig.optionOrigin) -const watchExtraOptions = computed(() => props.moduleConfig?.extraOptions?.length || []) -const watchValue = computed(() => props.formConfig.value) +watch( + () => props.moduleConfig.optionOrigin, + (newVal) => { + const key = props.formConfig.key + const extraLen = props.moduleConfig?.extraOptions?.length -watch(watchOptionOrigin, (newVal) => { - const key = props.formConfig.key - const extraLen = props.moduleConfig?.extraOptions?.length - - if (key === 'randomSort' && newVal && extraLen === 0) { - emit(FORM_CHANGE_EVENT_KEY, { key: 'randomSort', value: false }) - modelValue.value = false + if (key === 'randomSort' && newVal && extraLen === 0) { + emit(FORM_CHANGE_EVENT_KEY, { key: 'randomSort', value: false }) + modelValue.value = false + } } -}) - -watch(watchExtraOptions, (newVal) => { - const key = props.formConfig.key - const origin = props.moduleConfig?.optionOrigin - - if (key === 'randomSort' && origin && newVal === 0) { - emit(FORM_CHANGE_EVENT_KEY, { key: 'randomSort', value: false }) - modelValue.value = false - } -}) +) watch( - watchValue, + () => props.moduleConfig?.extraOptions?.length || [], + (newVal) => { + const key = props.formConfig.key + const origin = props.moduleConfig?.optionOrigin + + if (key === 'randomSort' && origin && newVal === 0) { + emit(FORM_CHANGE_EVENT_KEY, { key: 'randomSort', value: false }) + modelValue.value = false + } + } +) + +watch( + () => props.formConfig.value, (newVal: boolean) => { if (newVal !== modelValue.value) { modelValue.value == !!newVal diff --git a/web/src/materials/setters/widgets/FormdataBackFill.vue b/web/src/materials/setters/widgets/FormdataBackFill.vue index 06b23f37..69e7e262 100644 --- a/web/src/materials/setters/widgets/FormdataBackFill.vue +++ b/web/src/materials/setters/widgets/FormdataBackFill.vue @@ -62,19 +62,21 @@ const handleSwitchChange = (value: string | null) => { emit(FORM_CHANGE_EVENT_KEY, { key: formdataBackfillHourKey, value: value ? '24' : null }) } -const watchValue = computed(() => props.formConfig.value) -watch(watchValue, (config) => { - const formdataBackfill = config[formdataBackfillKey] - const formdataBackfillHour = !!config[formdataBackfillHourKey] +watch( + () => props.formConfig.value, + (config) => { + const formdataBackfill = config[formdataBackfillKey] + const formdataBackfillHour = !!config[formdataBackfillHourKey] - if (formdataBackfill !== selectModelValue.value) { - selectModelValue.value = formdataBackfill - } + if (formdataBackfill !== selectModelValue.value) { + selectModelValue.value = formdataBackfill + } - if (formdataBackfillHour !== switchModelValue.value) { - switchModelValue.value = formdataBackfillHour + if (formdataBackfillHour !== switchModelValue.value) { + switchModelValue.value = formdataBackfillHour + } } -}) +)