feat: 优化多选组件可以单选切换的逻辑
parent
c1d895582c
commit
5dbdcc52c8
|
|
@ -68,7 +68,7 @@ const isDisabled = computed(() => {
|
||||||
return (
|
return (
|
||||||
props.disabled ||
|
props.disabled ||
|
||||||
checkboxGroup.disabled.value ||
|
checkboxGroup.disabled.value ||
|
||||||
(max > 0 && !isChecked.value && selectedCount >= max)
|
(max > 1 && !isChecked.value && selectedCount >= max)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,17 +31,20 @@ const innerValue = computed(() => props.modelValue)
|
||||||
const toggleOption = (option: { label: string; value: string | number }) => {
|
const toggleOption = (option: { label: string; value: string | number }) => {
|
||||||
const currentValue = innerValue.value
|
const currentValue = innerValue.value
|
||||||
const index = currentValue.indexOf(option.value)
|
const index = currentValue.indexOf(option.value)
|
||||||
const newValue = [...currentValue]
|
let newValue = [...currentValue]
|
||||||
|
|
||||||
if (index === -1) {
|
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({
|
uni.showToast({
|
||||||
title: `最多只能选择${props.max}项`,
|
title: `最多只能选择${props.max}项`,
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
} else {
|
||||||
newValue.push(option.value)
|
newValue.push(option.value)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
newValue.splice(index, 1)
|
newValue.splice(index, 1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ const isDisabled = computed(() => {
|
||||||
return (
|
return (
|
||||||
props.disabled ||
|
props.disabled ||
|
||||||
checkboxGroup.disabled.value ||
|
checkboxGroup.disabled.value ||
|
||||||
(max > 0 && !isChecked.value && selectedCount >= max)
|
(max > 1 && !isChecked.value && selectedCount >= max)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,17 +31,20 @@ const innerValue = computed(() => props.modelValue)
|
||||||
const toggleOption = (option: { label: string; value: string | number }) => {
|
const toggleOption = (option: { label: string; value: string | number }) => {
|
||||||
const currentValue = innerValue.value
|
const currentValue = innerValue.value
|
||||||
const index = currentValue.indexOf(option.value)
|
const index = currentValue.indexOf(option.value)
|
||||||
const newValue = [...currentValue]
|
let newValue = [...currentValue]
|
||||||
|
|
||||||
if (index === -1) {
|
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({
|
uni.showToast({
|
||||||
title: `最多只能选择${props.max}项`,
|
title: `最多只能选择${props.max}项`,
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
} else {
|
||||||
newValue.push(option.value)
|
newValue.push(option.value)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
newValue.splice(index, 1)
|
newValue.splice(index, 1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue