t-ui icon indicating copy to clipboard operation
t-ui copied to clipboard

t-select-table查询和重置有bug

Open JaeWong-CN opened this issue 7 months ago • 2 comments

控制台输出的是@radioChange事件,输出的选中的对象,可以在视频看出,查询后选中第一个,选中的是空的,再打开选择器选中一次才能选上,有时候重置的时候,选中第一个也是会有bug

https://github.com/user-attachments/assets/fac7971c-6889-48b0-bb92-52f96d22b49e

JaeWong-CN avatar Jun 10 '25 10:06 JaeWong-CN

经过调试我发现是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()
}

JaeWong-CN avatar Jun 11 '25 01:06 JaeWong-CN

可以,就用你这个

wocwin avatar Jun 11 '25 02:06 wocwin