@@ -127,13 +127,19 @@ function parseTableHtml(
127
127
}
128
128
const tdList = $elem . find ( 'tr' ) [ 0 ] ?. children || [ ]
129
129
const colgroupElments : HTMLCollection = $elem . find ( 'colgroup' ) [ 0 ] ?. children || null
130
+ // @ts -ignore
131
+ const colLength = children [ children . length - 1 ] . children . length
130
132
131
- if ( tdList . length > 0 ) {
133
+ if ( colgroupElments && colgroupElments . length === colLength ) {
134
+ tableELement . columnWidths = Array . from ( colgroupElments ) . map ( ( col : any ) => {
135
+ return parseInt ( col . getAttribute ( 'width' ) , 10 )
136
+ } )
137
+ } else if ( tdList . length > 0 ) {
132
138
const columnWidths : number [ ] = [ ]
133
139
134
140
Array . from ( tdList ) . forEach ( td => {
135
141
const colSpan = parseInt ( $ ( td ) . attr ( 'colSpan' ) || '1' , 10 ) // 获取 colSpan,默认为 1
136
- const width = parseInt ( getStyleValue ( $ ( td ) , 'width' ) || '90' , 10 ) // 获取 width,默认为 180
142
+ const width = parseInt ( getStyleValue ( $ ( td ) , 'width' ) || '90' , 10 ) // 获取 width,默认为 90
137
143
138
144
// 根据 colSpan 的值来填充 columnWidths 数组
139
145
columnWidths . push ( width )
@@ -142,10 +148,6 @@ function parseTableHtml(
142
148
}
143
149
} )
144
150
tableELement . columnWidths = columnWidths
145
- } else if ( colgroupElments ) {
146
- tableELement . columnWidths = Array . from ( colgroupElments ) . map ( ( col : any ) => {
147
- return parseInt ( col . getAttribute ( 'width' ) , 10 )
148
- } )
149
151
}
150
152
return tableELement
151
153
}
0 commit comments