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) }