Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
水玉婷
ai-wechat
Commits
0f88d2e8
Commit
0f88d2e8
authored
Apr 23, 2026
by
水玉婷
Browse files
feat:修复表格排序bug
parent
d54fa34e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/views/components/TableComponent.vue
View file @
0f88d2e8
...
@@ -65,8 +65,7 @@ const handleTableChange = (pagination: any, filters: any, sorter: any) => {
...
@@ -65,8 +65,7 @@ const handleTableChange = (pagination: any, filters: any, sorter: any) => {
}
}
// 处理排序变化(支持多列排序)
// 处理排序变化(支持多列排序)
if
(
sorter
)
{
if
(
sorter
&&
(
sorter
.
order
||
(
Array
.
isArray
(
sorter
)
&&
sorter
.
some
(
item
=>
item
.
order
))))
{
// 更新排序状态
// 更新排序状态
sortState
.
isSorted
=
true
;
sortState
.
isSorted
=
true
;
...
@@ -81,19 +80,26 @@ const handleTableChange = (pagination: any, filters: any, sorter: any) => {
...
@@ -81,19 +80,26 @@ const handleTableChange = (pagination: any, filters: any, sorter: any) => {
// 应用排序
// 应用排序
if
(
Array
.
isArray
(
sorter
))
{
if
(
Array
.
isArray
(
sorter
))
{
// 多列排序情况:按优先级顺序应用排序
// 多列排序情况:按优先级顺序应用排序
sorter
.
forEach
((
sortItem
)
=>
{
rawData
.
sort
((
a
,
b
)
=>
{
if
(
sortItem
.
or
d
er
)
{
for
(
const
sortItem
of
s
or
t
er
)
{
rawData
.
sort
((
a
,
b
)
=>
{
if
(
sortItem
.
order
)
{
const
aValue
=
getSortableValue
(
a
,
sortItem
.
field
);
const
aValue
=
getSortableValue
(
a
,
sortItem
.
field
);
const
bValue
=
getSortableValue
(
b
,
sortItem
.
field
);
const
bValue
=
getSortableValue
(
b
,
sortItem
.
field
);
let
result
=
0
;
if
(
sortItem
.
order
===
'
ascend
'
)
{
if
(
sortItem
.
order
===
'
ascend
'
)
{
re
turn
aValue
-
bValue
;
re
sult
=
aValue
-
bValue
;
}
else
{
}
else
{
return
bValue
-
aValue
;
result
=
bValue
-
aValue
;
}
// 如果当前列的比较结果不为0,返回结果
if
(
result
!==
0
)
{
return
result
;
}
}
}
);
}
}
}
return
0
;
});
});
}
else
if
(
sorter
.
order
)
{
}
else
if
(
sorter
.
order
)
{
// 单列排序情况
// 单列排序情况
...
@@ -111,6 +117,10 @@ const handleTableChange = (pagination: any, filters: any, sorter: any) => {
...
@@ -111,6 +117,10 @@ const handleTableChange = (pagination: any, filters: any, sorter: any) => {
// 更新排序后的数据
// 更新排序后的数据
sortState
.
sortedData
=
rawData
;
sortState
.
sortedData
=
rawData
;
}
else
if
(
sorter
&&
!
sorter
.
order
&&
!
Array
.
isArray
(
sorter
))
{
// 清除排序状态(用户点击取消排序)
sortState
.
isSorted
=
false
;
sortState
.
sortedData
=
[];
}
}
};
};
...
@@ -278,17 +288,10 @@ const tableColumns = computed(() => {
...
@@ -278,17 +288,10 @@ const tableColumns = computed(() => {
compare
:
(
a
:
any
,
b
:
any
)
=>
{
compare
:
(
a
:
any
,
b
:
any
)
=>
{
// 对于数字字段
// 对于数字字段
if
(
isNumericColumn
(
header
))
{
if
(
isNumericColumn
(
header
))
{
// 对于indexFields字段,使用存储的原始值进行排序
// 统一使用getSortableValue函数获取可排序的值
if
(
isIndexField
&&
a
[
header
]
&&
a
[
header
].
value
!==
undefined
)
{
const
aValue
=
getSortableValue
(
a
,
header
);
const
aValue
=
parseFloat
(
a
[
header
].
value
);
const
bValue
=
getSortableValue
(
b
,
header
);
const
bValue
=
parseFloat
(
b
[
header
].
value
);
return
aValue
-
bValue
;
return
aValue
-
bValue
;
}
else
{
// 其他数字字段直接使用当前字段排序
const
aValue
=
parseFloat
(
a
[
header
]);
const
bValue
=
parseFloat
(
b
[
header
]);
return
aValue
-
bValue
;
}
}
else
{
}
else
{
// 对于文字字段,使用字符串排序
// 对于文字字段,使用字符串排序
const
aValue
=
getStringValue
(
a
,
header
);
const
aValue
=
getStringValue
(
a
,
header
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment