vbenjs / vue-vben-admin

A modern vue admin. It is based on Vue3, vite and TypeScript. It's fast!
https://vben.vvbin.cn/
MIT License
22.88k stars 6.24k forks source link

fix: dataindex为数组时排序错误,数组列排到最后 #3937

Open wangruiStart opened 4 days ago

wangruiStart commented 4 days ago

General

✏️ Mark the necessary items without changing the structure of the PR template.

Type

ℹ️ What types of changes does your code introduce?

👉 Put an x in the boxes that apply

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

👉 Put an x in the boxes that apply.

likui628 commented 3 days ago

没明白此PR解决了什么问题,能不能说明下

wangruiStart commented 3 days ago

没明白此PR解决了什么问题,能不能说明下

当table的dataIndex是数组时,之前的逻辑会判断 title,但是判断逻辑写的有问题,应该是typeof title.导致最后的columnOptions的value是空字符串。进而导致tableColumnsUpdate方法中const colIdx = columns.findIndex((o) => o.key === opt.value);colIdx找不到,所有dataindex为数组的列都会被插到最后,改变了原有配置的columns的顺序

Allure-eve commented 2 days ago

这个代码错误好低级,在我使用这样的dataIndex的时候 排序功能就失效

   {
      title: '歌手',
      dataIndex: ['artist', 'name'],
      width: 200,
    },

经过我的排查 发现 src/components/Table/src/components/settings/ColumnSetting.vue:547行以及上面的542行的label 都有该错误

错误非常低级

options.push({
  label:
    typeof col.title === "string"
      ? col.title
      : col.customTitle === "string" // ???? 只有当col.customTitle 的值为string的时候才去使用col.customTitle 吗 typeof呢 我请问
        ? col.customTitle
        : "",
  value:
    typeof col.dataIndex === "string"
      ? col.dataIndex
      : col.title === "string" // ???? 只有当col.title的值为string的时候才去使用col.title吗 typeof呢 我请问
        ? col.title
        : "",
  column: {
    defaultHidden: col.defaultHidden,
  },
  fixed: col.fixed,
});
doraemonxxx commented 1 day ago

I think we can close this PR? The issue was solved in dd1b16acdcf4b02daf48e998e3af44619a8cb403

EDITED

wangruiStart commented 1 day ago

I think we can close this PR? The was solved in 64a4992

This error pertains to the fix in the Ant Design Vue Table component, not the Vxe-Table component.