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
8b8f892f
Commit
8b8f892f
authored
Feb 10, 2026
by
水玉婷
Browse files
feat:修复当表格只有两列时不均分问题
parent
6631789f
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/views/components/TableComponent.vue
View file @
8b8f892f
...
...
@@ -236,6 +236,21 @@ const getColumnAlign = (header: string) => {
// 获取列宽度
const
getColumnWidth
=
(
header
:
string
)
=>
{
// 获取当前表格的列数
const
headers
=
processedTableData
.
value
.
length
>
0
?
Object
.
keys
(
processedTableData
.
value
[
0
])
:
[];
const
columnCount
=
headers
.
length
;
// 当只有两列时,强制设置固定宽度实现均分
if
(
columnCount
===
2
)
{
return
'
50%
'
;
// 每列占50%宽度
}
// 当列数较少时(小于等于4列),让列宽自动均分
if
(
columnCount
<=
4
)
{
return
undefined
;
// 返回undefined让antd-table自动计算宽度
}
// 列数较多时,使用固定宽度
if
(
isNumericColumn
(
header
))
{
return
120
;
}
else
if
(
isTrendColumn
(
header
))
{
...
...
@@ -319,6 +334,12 @@ const getTableScroll = () => {
border-collapse
:
collapse
;
background-color
:
white
;
table-layout
:
auto
;
/* 当只有两列时,强制使用固定布局实现均分 */
&:has(
th
:
nth-child
(
2
):
last-child
)
{
table-layout
:
fixed
;
width
:
100%
;
}
}
.data-table
{
...
...
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