From 5dbdcc52c81d1e67838df301debcd752c14dcbef Mon Sep 17 00:00:00 2001 From: xjs Date: Wed, 23 Apr 2025 09:49:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=A4=9A=E9=80=89?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=8F=AF=E4=BB=A5=E5=8D=95=E9=80=89=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/check-group/Checkbox.vue | 2 +- .../components/check-group/CheckboxGroup.vue | 9 ++++++--- src/pages-sub/components/check-group/Checkbox.vue | 2 +- src/pages-sub/components/check-group/CheckboxGroup.vue | 9 ++++++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/pages-evaluation-sub/components/check-group/Checkbox.vue b/src/pages-evaluation-sub/components/check-group/Checkbox.vue index 39d7bcf..918bb13 100644 --- a/src/pages-evaluation-sub/components/check-group/Checkbox.vue +++ b/src/pages-evaluation-sub/components/check-group/Checkbox.vue @@ -68,7 +68,7 @@ const isDisabled = computed(() => { return ( props.disabled || checkboxGroup.disabled.value || - (max > 0 && !isChecked.value && selectedCount >= max) + (max > 1 && !isChecked.value && selectedCount >= max) ) }) diff --git a/src/pages-evaluation-sub/components/check-group/CheckboxGroup.vue b/src/pages-evaluation-sub/components/check-group/CheckboxGroup.vue index c1194e8..1c8e836 100644 --- a/src/pages-evaluation-sub/components/check-group/CheckboxGroup.vue +++ b/src/pages-evaluation-sub/components/check-group/CheckboxGroup.vue @@ -31,17 +31,20 @@ const innerValue = computed(() => props.modelValue) const toggleOption = (option: { label: string; value: string | number }) => { const currentValue = innerValue.value const index = currentValue.indexOf(option.value) - const newValue = [...currentValue] + let newValue = [...currentValue] if (index === -1) { - if (props.max && currentValue.length >= props.max) { + if (props.max === 1) { + newValue = [option.value] + } else if (props.max && currentValue.length >= props.max) { uni.showToast({ title: `最多只能选择${props.max}项`, icon: 'none', }) return + } else { + newValue.push(option.value) } - newValue.push(option.value) } else { newValue.splice(index, 1) } diff --git a/src/pages-sub/components/check-group/Checkbox.vue b/src/pages-sub/components/check-group/Checkbox.vue index 39d7bcf..918bb13 100644 --- a/src/pages-sub/components/check-group/Checkbox.vue +++ b/src/pages-sub/components/check-group/Checkbox.vue @@ -68,7 +68,7 @@ const isDisabled = computed(() => { return ( props.disabled || checkboxGroup.disabled.value || - (max > 0 && !isChecked.value && selectedCount >= max) + (max > 1 && !isChecked.value && selectedCount >= max) ) }) diff --git a/src/pages-sub/components/check-group/CheckboxGroup.vue b/src/pages-sub/components/check-group/CheckboxGroup.vue index c1194e8..1c8e836 100644 --- a/src/pages-sub/components/check-group/CheckboxGroup.vue +++ b/src/pages-sub/components/check-group/CheckboxGroup.vue @@ -31,17 +31,20 @@ const innerValue = computed(() => props.modelValue) const toggleOption = (option: { label: string; value: string | number }) => { const currentValue = innerValue.value const index = currentValue.indexOf(option.value) - const newValue = [...currentValue] + let newValue = [...currentValue] if (index === -1) { - if (props.max && currentValue.length >= props.max) { + if (props.max === 1) { + newValue = [option.value] + } else if (props.max && currentValue.length >= props.max) { uni.showToast({ title: `最多只能选择${props.max}项`, icon: 'none', }) return + } else { + newValue.push(option.value) } - newValue.push(option.value) } else { newValue.splice(index, 1) }