t-ui
t-ui copied to clipboard
t-select-table查询和重置有bug
控制台输出的是@radioChange事件,输出的选中的对象,可以在视频看出,查询后选中第一个,选中的是空的,再打开选择器选中一次才能选上,有时候重置的时候,选中第一个也是会有bug
https://github.com/user-attachments/assets/fac7971c-6889-48b0-bb92-52f96d22b49e
经过调试我发现是radioClick方法有问题,按视频中操作,我先在一开始选中了第一项,此时radioVal为1,然后我进行搜索,接口过滤后,又选择了第一项,此时radioVal与index都为1,按照您原来方法中的判断,此时误以为是在操作“取消选中第1项”的操作,因此将emitData和emitValue置空了,这个逻辑有点欠缺。以下给出建议的修改代码,我就不提PR了,如果觉得ok可以参考我的建议:
// 单选抛出事件radioChange
radioClick(row, index) {
this.forbidden = !this.forbidden
// 检查defaultValue是否已包含当前行数据
const isCurrentRowSelected = this.defaultValue &&
this.defaultValue[this.keywords.value] === row[this.keywords.value]
// 即使radioVal === index,如果当前行未被选中,也应视为新选择
const shouldEmitSelection = !isCurrentRowSelected || this.radioVal !== index
const emitData = shouldEmitSelection ? { ...row } : {}
const emitValue = shouldEmitSelection ? row[this.keywords.value] : null
if (this.radioVal !== index || !isCurrentRowSelected) {
this.radioVal = index
this.defaultValue = { ...row }
this.isDefaultSelectVal = true
this.defaultSelectValue = []
} else {
this.radioVal = ''
this.defaultValue = {}
this.isDefaultSelectVal = true
this.defaultSelectValue = []
}
this.isForbidden()
this.$emit('radioChange', emitData, emitValue)
this.blur()
}
可以,就用你这个