@@ -17,12 +17,7 @@ const createChain = (columns: ColumnConfig[], level: number): TreeNode => {
1717 return node ;
1818} ;
1919
20- export const CascadingInput : React . FC < CascadingInputProps > = ( {
21- value = [ ] ,
22- onChange,
23- columns,
24- line = { } ,
25- } ) => {
20+ export const CascadingInput : React . FC < CascadingInputProps > = ( { value = [ ] , onChange, columns, line = { } } ) => {
2621 const lineStyle = line . style ?? 'curve' ;
2722 const lineColor = line . color ?? '#d9d9d9' ;
2823 const lineWidth = line . width ?? 1.5 ;
@@ -51,7 +46,9 @@ export const CascadingInput: React.FC<CascadingInputProps> = ({
5146 const currentId = path [ 0 ] ;
5247 return nodes . map ( ( node ) => {
5348 if ( node . id === currentId ) {
54- if ( path . length === 1 ) { return { ...node , [ dataIndex ] : val } ; }
49+ if ( path . length === 1 ) {
50+ return { ...node , [ dataIndex ] : val } ;
51+ }
5552 return { ...node , children : updateTreeValue ( node . children || [ ] , path . slice ( 1 ) , val , dataIndex ) } ;
5653 }
5754 return node ;
@@ -79,7 +76,9 @@ export const CascadingInput: React.FC<CascadingInputProps> = ({
7976
8077 const deleteNodeCascade = ( nodes : TreeNode [ ] , path : string [ ] ) : TreeNode [ ] => {
8178 const targetId = path [ 0 ] ;
82- if ( path . length === 1 ) { return nodes . filter ( ( n ) => n . id !== targetId ) ; }
79+ if ( path . length === 1 ) {
80+ return nodes . filter ( ( n ) => n . id !== targetId ) ;
81+ }
8382 return nodes
8483 . map ( ( node ) => {
8584 if ( node . id === targetId ) {
@@ -93,16 +92,17 @@ export const CascadingInput: React.FC<CascadingInputProps> = ({
9392 const handleValueChange = ( path : string [ ] , val : string , dataIndex : string ) =>
9493 onChange ?.( updateTreeValue ( value , path , val , dataIndex ) ) ;
9594
96- const handleAdd = ( path : string [ ] , level : number ) =>
97- onChange ?.( addSiblingNode ( value , path , level ) ) ;
95+ const handleAdd = ( path : string [ ] , level : number ) => onChange ?.( addSiblingNode ( value , path , level ) ) ;
9896
9997 const handleDelete = ( path : string [ ] ) => {
10098 const nextValue = deleteNodeCascade ( value , path ) ;
10199 onChange ?.( nextValue . length === 0 ? [ createChain ( columns , 0 ) ] : nextValue ) ;
102100 } ;
103101
104102 const renderLevel = ( nodes : TreeNode [ ] , level : number , parentPath : string [ ] = [ ] ) : React . ReactNode => {
105- if ( ! columns [ level ] ) { return null ; }
103+ if ( ! columns [ level ] ) {
104+ return null ;
105+ }
106106 const col = columns [ level ] ;
107107 const isLeaf = level === columns . length - 1 ;
108108
@@ -127,38 +127,39 @@ export const CascadingInput: React.FC<CascadingInputProps> = ({
127127 } ) }
128128 { col . hasAdd && (
129129 < div className = "tree-cell-action" >
130- { col . addRender
131- ? col . addRender ( { onClick : ( ) => handleAdd ( currentPath , level ) } )
132- : (
133- < button
134- type = "button"
135- className = "tree-cell-action-btn"
136- onClick = { ( ) => handleAdd ( currentPath , level ) }
137- >
138- 添加
139- </ button >
140- ) }
130+ { col . addRender ? (
131+ col . addRender ( { onClick : ( ) => handleAdd ( currentPath , level ) } )
132+ ) : (
133+ < button
134+ type = "button"
135+ className = "tree-cell-action-btn"
136+ onClick = { ( ) => handleAdd ( currentPath , level ) }
137+ >
138+ 添加
139+ </ button >
140+ ) }
141141 </ div >
142142 ) }
143143 </ div >
144144
145- { ! isLeaf && node . children && node . children . length > 0 &&
145+ { ! isLeaf &&
146+ node . children &&
147+ node . children . length > 0 &&
146148 renderLevel ( node . children , level + 1 , currentPath ) }
147149
148- { isLeaf && (
149- col . deleteRender
150- ? col . deleteRender ( { onClick : ( ) => handleDelete ( currentPath ) } )
151- : (
152- < button
153- type = "button"
154- className = "tree-delete-btn"
155- onClick = { ( ) => handleDelete ( currentPath ) }
156- title = "删除整行"
157- >
158- 删除
159- </ button >
160- )
161- ) }
150+ { isLeaf &&
151+ ( col . deleteRender ? (
152+ col . deleteRender ( { onClick : ( ) => handleDelete ( currentPath ) } )
153+ ) : (
154+ < button
155+ type = "button"
156+ className = "tree-delete-btn"
157+ onClick = { ( ) => handleDelete ( currentPath ) }
158+ title = "删除整行"
159+ >
160+ 删除
161+ </ button >
162+ ) ) }
162163 </ div >
163164 ) ;
164165 } ) }
0 commit comments