@@ -17,8 +17,9 @@ export class CreateTableComponent {
1717 applyData : DesignerApplyData ;
1818
1919 applyTableName : string ;
20- applyColumns : DesignerColumn [ ] = [ ] ;
21- applyCheckedColumns = new Set < string > ;
20+ applyColumns : Array < DesignerColumn > = new Array < DesignerColumn > ;
21+ applyCheckedColumns : Set < string > = new Set < string > ;
22+ applyLastCheckedColumn : string = null ;
2223 dataType = [
2324 'varchar' ,
2425 'int' ,
@@ -51,20 +52,37 @@ export class CreateTableComponent {
5152 }
5253 }
5354
54- handlerPlusColumn ( ) {
55+ handlerGenerateColumn ( ) : DesignerColumn {
5556 const milliseconds = new Date ( ) . getTime ( ) ;
5657 const random = ( Math . random ( ) * milliseconds ) . toFixed ( 0 ) ;
5758 const id = StringUtils . format ( '{0}_{1}' , [ milliseconds , random ] ) ;
5859 const column = new DesignerColumn ( ) ;
5960 column . id = id ;
60- this . applyColumns = [ ...this . applyColumns , column ] ;
61+ return column ;
62+ }
63+
64+ handlerPlusColumn ( ) {
65+ this . applyColumns = [ ...this . applyColumns , this . handlerGenerateColumn ( ) ] ;
66+ }
67+
68+ handlerPlusPreColumn ( ) {
69+ if ( this . applyCheckedColumns . size > 0 ) {
70+ // If contained selected columns are added to the previous row of the column by default
71+ const index = this . applyColumns . findIndex ( item => this . applyLastCheckedColumn === item . id ) ;
72+ this . applyColumns . splice ( index , 0 , this . handlerGenerateColumn ( ) ) ;
73+ this . applyColumns = [ ...this . applyColumns ] ;
74+ } else {
75+ // If not selected, the column is added to the first row by default
76+ this . applyColumns = [ this . handlerGenerateColumn ( ) , ...this . applyColumns ] ;
77+ }
6178 }
6279
6380 handlerMinusColumn ( ) {
6481 this . applyColumns = this . applyColumns . filter ( column => ! this . applyCheckedColumns . has ( column . id ) ) ;
6582 }
6683
6784 handlerColumnChecked ( column : string , checked : boolean ) {
85+ this . applyLastCheckedColumn = column ;
6886 if ( checked ) {
6987 this . applyCheckedColumns . add ( column ) ;
7088 } else {
0 commit comments