@@ -118,54 +118,46 @@ export default function Table<T extends { [key: string]: V }, V>(props: TablePro
118
118
setLocationWidth ( computed ( ) ) ;
119
119
}
120
120
} ;
121
- const deepClumnsLocation = (
122
- params : Array < TableColumns < T > | number > ,
123
- fistIndex : number ,
124
- leftOrRight : 'left' | 'right' ,
125
- isReverse : boolean ,
126
- ) => {
121
+ const deepClumnsLocation = ( params : Array < TableColumns < T > | number > , fistIndex : number ) => {
127
122
let initialValue = 0 ,
128
- lastIndex = isReverse ? 0 : params . length - 1 ,
123
+ headerIndex = 0 ,
129
124
deepParams : Array < TableColumns < T > | number > = [ ] ;
130
- params . forEach ( ( ) => {
131
- let abs = Math . abs ( lastIndex ) ;
132
- const i = `${ fistIndex } ${ abs } ` ;
133
- if ( isReverse ) {
134
- lastIndex += 1 ;
135
- } else {
136
- lastIndex -= 1 ;
137
- }
138
- if ( typeof params [ abs ] === 'number' ) {
139
- initialValue = ( params [ abs ] as number ) + initialValue ;
140
- deepParams . push ( params [ abs ] ) ;
125
+ params . forEach ( ( _ , index ) => {
126
+ const i = `${ fistIndex } ${ headerIndex } ` ;
127
+ if ( typeof params [ index ] === 'number' ) {
128
+ initialValue = ( params [ index ] as number ) + initialValue ;
129
+ deepParams . push ( params [ index ] ) ;
141
130
return ;
142
131
}
143
132
if ( finalLocationWidth . current [ i ] ) {
144
- finalLocationWidth . current [ i ] [ leftOrRight ] = initialValue ;
133
+ finalLocationWidth . current [ i ] . left = initialValue ;
145
134
initialValue = finalLocationWidth . current [ i ] . width + initialValue ;
135
+ if ( Array . isArray ( ( params [ index ] as TableColumns < T > ) . children ) ) {
136
+ deepParams . push ( ...( params [ index ] as TableColumns < T > ) . children ! ) ;
137
+ } else {
138
+ deepParams . push ( finalLocationWidth . current [ i ] . width ) ;
139
+ }
146
140
}
147
- if ( Array . isArray ( ( params [ abs ] as TableColumns < T > ) . children ) ) {
148
- deepParams . push ( ...( params [ abs ] as TableColumns < T > ) . children ! ) ;
149
- return ;
141
+ headerIndex += 1 ;
142
+ } ) ;
143
+ ( initialValue = 0 ) , ( headerIndex = header [ fistIndex ] . length - 1 ) ;
144
+ for ( let index = params . length - 1 ; index >= 0 ; index -- ) {
145
+ const i = `${ fistIndex } ${ headerIndex } ` ;
146
+ if ( typeof params [ index ] === 'number' ) {
147
+ initialValue = ( params [ index ] as number ) + initialValue ;
148
+ continue ;
150
149
}
151
150
if ( finalLocationWidth . current [ i ] ) {
152
- deepParams . push ( finalLocationWidth . current [ i ] . width ) ;
153
- } else {
154
- const parent = header . find ( ( it ) => it . find ( ( it ) => it . key === ( params [ abs ] as TableColumns < T > ) . key ) ) || [ ] ;
155
- const sub = parent . findIndex ( ( it ) => it . key === ( params [ abs ] as TableColumns < T > ) . key ) ;
156
- if ( finalLocationWidth . current [ `${ i [ 0 ] } ${ sub } ` ] ) {
157
- // 合并单元格
158
- deepParams . push ( finalLocationWidth . current [ `${ i [ 0 ] } ${ sub } ` ] . width ) ;
159
- }
151
+ finalLocationWidth . current [ i ] . right = initialValue ;
152
+ initialValue = finalLocationWidth . current [ i ] . width + initialValue ;
160
153
}
161
- } ) ;
162
- if ( deepParams . filter ( ( it ) => typeof it !== 'number' ) . length )
163
- deepClumnsLocation ( deepParams , fistIndex + 1 , leftOrRight , isReverse ) ;
154
+ headerIndex -= 1 ;
155
+ }
156
+ if ( deepParams . filter ( ( it ) => typeof it !== 'number' ) . length ) deepClumnsLocation ( deepParams , fistIndex + 1 ) ;
164
157
} ;
165
158
166
159
const computed = ( ) => {
167
- deepClumnsLocation ( columns , 0 , 'left' , true ) ;
168
- deepClumnsLocation ( columns , 0 , 'right' , false ) ;
160
+ deepClumnsLocation ( columns , 0 ) ;
169
161
return finalLocationWidth . current ;
170
162
} ;
171
163
useEffect ( ( ) => {
@@ -296,6 +288,7 @@ export default function Table<T extends { [key: string]: V }, V>(props: TablePro
296
288
} , [ scroll ] ) ;
297
289
const cls = [ prefixCls , className , bordered ? `${ prefixCls } -bordered` : null ] . filter ( Boolean ) . join ( ' ' ) . trim ( ) ;
298
290
const { header, render, ellipsis } = getLevelItems ( self . selfColumns ) ;
291
+
299
292
return (
300
293
< React . Fragment >
301
294
< div className = { cls } { ...other } style = { { ...other . style , ...style . div } } >
0 commit comments