@@ -55,16 +55,16 @@ class ComponentDot {
55
55
insert_data ;
56
56
delete_data ;
57
57
58
- constructor ( name , selected , options ) {
58
+ constructor ( name , selected , select ) {
59
59
this . DOM = document . getElementById ( name ) ;
60
60
let selected_dom = '' ;
61
- let options_dom = '' ;
62
- for ( let i in options ) {
61
+ let select_dom = '' ;
62
+ for ( let i in select ) {
63
63
if ( selected [ i ] ) {
64
- selected_dom += `<div class='btn btn-success btn-sm v-tag' style='margin-right: 4px;margin-bottom: 4px' data-id='${ i } '>${ options [ i ] } </div>` ;
64
+ selected_dom += `<div class='btn btn-success btn-sm v-tag' style='margin-right: 4px;margin-bottom: 4px' data-id='${ i } '>${ select [ i ] } </div>` ;
65
65
continue ;
66
66
}
67
- options_dom += `<div class='btn btn-primary btn-sm v-tag' style='margin-right: 4px;margin-bottom: 4px' data-id='${ i } '>${ options [ i ] } </div>` ;
67
+ select_dom += `<div class='btn btn-primary btn-sm v-tag' style='margin-right: 4px;margin-bottom: 4px' data-id='${ i } '>${ select [ i ] } </div>` ;
68
68
}
69
69
70
70
this . selected_data = Object . keys ( selected ) ;
@@ -77,7 +77,7 @@ class ComponentDot {
77
77
<input id="${ name } -search" type="text" class="form-control" placeholder="搜索名称"></div>
78
78
<div id="${ name } -select" style="width:100%;overflow: auto;border-bottom: 1px solid #ccc;padding: 3px;border-radius: 0 0 0 14px;background: #ffffffbf;">${ selected_dom } </div>
79
79
</div><div id="${ name } -content" style="overflow-y: auto;padding: 3px;background: #e1ffa8bf;">
80
- ${ options_dom } </div></div>
80
+ ${ select_dom } </div></div>
81
81
<input name="${ name } [data]" value='${ select_str } ' type="hidden">
82
82
<input name="${ name } [insert]" value="[]" type="hidden">
83
83
<input name="${ name } [delete]" value="[]" type="hidden">` ;
@@ -131,9 +131,7 @@ class ComponentDot {
131
131
this . select_data . push ( id ) ;
132
132
this . dataDOM . value = JSON . stringify ( this . select_data ) ;
133
133
}
134
- console . log ( this . selected_data . indexOf ( id ) )
135
134
if ( this . selected_data . indexOf ( id ) == - 1 && this . insert_data . indexOf ( id ) == - 1 ) {
136
- console . log ( 9 )
137
135
this . insert_data . push ( id ) ;
138
136
this . insertDOM . value = JSON . stringify ( this . insert_data ) ;
139
137
}
@@ -171,19 +169,19 @@ class ComponentLine {
171
169
NAME ;
172
170
COLUMNS ;
173
171
DATA ;
174
- SETTINGS ;
172
+ OPTIONS ;
175
173
DATA_INPUT ;
176
174
SORTABLE ;
177
175
178
- constructor ( name , columns , data , settings ) {
176
+ constructor ( name , columns , data , options ) {
179
177
this . DOM = document . getElementById ( name ) ;
180
178
this . NAME = name ;
181
179
this . COLUMNS = columns ;
182
180
this . DATA = data ;
183
- this . SETTINGS = Object . assign ( {
181
+ this . OPTIONS = Object . assign ( {
184
182
sortable : true ,
185
183
delete : true ,
186
- } , settings || { } ) ;
184
+ } , options || { } ) ;
187
185
/*head foot*/
188
186
let foot = this . makeHead ( ) ;
189
187
/*hidden data container*/
@@ -263,12 +261,12 @@ class ComponentLine {
263
261
let td = document . createElement ( 'td' ) ;
264
262
object . operateButton ( td ) ;
265
263
tr . appendChild ( td ) ;
266
- tbody . setAttribute ( 'style' , 'display:block;height:100%;overflow-y:scroll' ) ;
267
264
tbody . appendChild ( tr ) ;
268
265
records . push ( record ) ;
269
266
object . DATA = records ;
270
267
object . DATA_INPUT . value = JSON . stringify ( records ) ;
271
268
} ) ;
269
+ tbody . setAttribute ( 'style' , 'display:block;height:100%;overflow-y:scroll' ) ;
272
270
tbody . setAttribute ( 'sortable-list' , 'sortable-list' ) ;
273
271
this . TBODY_DOM = tbody ;
274
272
this . TABLE_DOM . appendChild ( tbody ) ;
@@ -311,7 +309,11 @@ class ComponentLine {
311
309
object . DATA . push ( insert ) ;
312
310
object . DATA_INPUT . value = JSON . stringify ( object . DATA ) ;
313
311
object . TBODY_DOM . scrollTop = object . TBODY_DOM . scrollHeight ;
314
- object . SORTABLE . resetContainer ( ) ;
312
+ if ( object . DATA . length == 2 ) {
313
+ object . SORTABLE = new ComponentSortable ( object . TBODY_DOM ) ;
314
+ } else if ( object . DATA . length > 2 ) {
315
+ object . SORTABLE . action ( ) ;
316
+ }
315
317
} , false ) ;
316
318
this . DOM . getElementsByClassName ( 'JsonTableInsert' ) [ 0 ] . appendChild ( i ) ;
317
319
}
@@ -349,15 +351,15 @@ class ComponentLine {
349
351
350
352
operateButton ( td ) {
351
353
var object = this ;
352
- if ( this . SETTINGS . sortable ) {
354
+ if ( this . OPTIONS . sortable ) {
353
355
let M = document . createElement ( 'i' ) ;
354
356
M . setAttribute ( 'class' , 'fa fa-arrows' ) ;
355
357
M . setAttribute ( 'style' , 'cursor: pointer;margin-right:5px;' ) ;
356
358
M . setAttribute ( 'sortable-handle' , 'sortable-handle' ) ;
357
359
td . appendChild ( M ) ;
358
360
}
359
361
360
- if ( this . SETTINGS . delete ) {
362
+ if ( this . OPTIONS . delete ) {
361
363
let D = document . createElement ( 'i' ) ;
362
364
D . setAttribute ( 'class' , 'fa fa-trash' ) ;
363
365
D . setAttribute ( 'style' , 'cursor: pointer' ) ;
@@ -374,6 +376,7 @@ class ComponentLine {
374
376
tbody . childNodes [ node ] . setAttribute ( 'data-key' , node ) ;
375
377
}
376
378
}
379
+ object . SORTABLE . action ( ) ;
377
380
} , false ) ;
378
381
td . appendChild ( D ) ;
379
382
}
@@ -383,7 +386,7 @@ class ComponentLine {
383
386
sortAble ( ) {
384
387
var object = this ;
385
388
setTimeout ( function ( ) {
386
- object . SORTABLE = new Sortable ( object . TBODY_DOM ) ;
389
+ object . SORTABLE = new ComponentSortable ( object . TBODY_DOM ) ;
387
390
} ) ;
388
391
}
389
392
}
@@ -395,7 +398,7 @@ class ComponentPlane {
395
398
URL ;
396
399
XHR_URL ;
397
400
METHOD ;
398
- SETTINGS ;
401
+ OPTIONS ;
399
402
CALLBACK ;
400
403
_loadingSvg = `<svg version="1.1" style='width: 100%;height:100px' xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
401
404
width="40px" height="40px" viewBox="0 0 40 40" enable-background="new 0 0 40 40" xml:space="preserve">
@@ -406,12 +409,15 @@ class ComponentPlane {
406
409
C22.32,8.481,24.301,9.057,26.013,10.047z"><animateTransform attributeType="xml"attributeName="transform"
407
410
type="rotate"from="0 20 20"to="360 20 20"dur="0.5s"repeatCount="indefinite"/></path></svg>` ;
408
411
409
- constructor ( url , xhr_url = '' , method = 'POST' , callback = null , settings = [ ] ) {
412
+ constructor ( url , xhr_url = '' , method = 'POST' , callback = null , options = { } ) {
410
413
this . URL = url ;
411
414
this . XHR_URL = xhr_url ;
412
415
this . METHOD = method ;
413
416
this . CALLBACK = callback ;
414
- this . SETTINGS = settings ;
417
+ this . OPTIONS = Object . assign ( {
418
+ W : 0.8 ,
419
+ H : 0.8 ,
420
+ } , options ) ;
415
421
416
422
this . makeModal ( ) ;
417
423
this . makeContent ( ) ;
@@ -428,7 +434,7 @@ class ComponentPlane {
428
434
let mod_dialog = document . createElement ( "div" ) ;
429
435
mod_dialog . setAttribute ( 'class' , 'modal-dialog modal-lg' ) ;
430
436
mod_dialog . setAttribute ( 'role' , 'document' ) ;
431
- mod_dialog . style = `width:${ window . innerWidth * 0.8 } px` ;
437
+ mod_dialog . style = `width:${ window . innerWidth * this . OPTIONS . W } px` ;
432
438
/*modal_content*/
433
439
let modal_content = document . createElement ( "div" ) ;
434
440
modal_content . className = "modal-content" ;
@@ -448,7 +454,8 @@ class ComponentPlane {
448
454
} , false ) ;
449
455
let modal_body = document . createElement ( 'div' ) ;
450
456
modal_body . className = "modal-body" ;
451
- modal_body . style = 'background-color:#f4f4f4;padding:0;overflow-y:auto;max-height:' + window . innerHeight * 0.8 + 'px;min-height:' + window . innerHeight * 0.4 + 'px;' ;
457
+ modal_body . style = 'background-color:#f4f4f4;padding:0;overflow-y:auto;max-height:' +
458
+ window . innerHeight * this . OPTIONS . H + 'px;min-height:' + window . innerHeight * this . OPTIONS . H / 2 + 'px;' ;
452
459
453
460
this . MODEL_BODY_DOM = modal_body ;
454
461
/*create modal*/
@@ -516,7 +523,8 @@ class ComponentPlane {
516
523
}
517
524
}
518
525
519
- class Sortable {
526
+ /*拖拽排序控件*/
527
+ class ComponentSortable {
520
528
list_height ;
521
529
constructor ( list , options ) {
522
530
this . list = ( typeof list === 'string' )
@@ -533,27 +541,20 @@ class Sortable {
533
541
animationEasing : 'ease-out' ,
534
542
} , options || { } ) ;
535
543
544
+ this . resetContainer ( ) ;
536
545
this . dragStart = this . dragStart . bind ( this ) ;
537
546
this . dragMove = this . dragMove . bind ( this ) ;
538
547
this . dragEnd = this . dragEnd . bind ( this ) ;
539
- if ( this . items [ this . items . length - 1 ] . offsetTop > this . list . offsetHeight ) {
540
- this . list_height = this . list . scrollHeight ;
541
- } else {
542
- this . list_height = this . items [ this . items . length - 1 ] . offsetTop ;
543
- }
544
548
this . list . addEventListener ( 'touchstart' , this . dragStart , false ) ;
545
549
this . list . addEventListener ( 'mousedown' , this . dragStart , false ) ;
546
550
}
547
551
548
552
resetContainer ( ) {
549
- this . items = Array . from ( this . list . children ) ;
550
553
if ( this . items [ this . items . length - 1 ] . offsetTop > this . list . offsetHeight ) {
551
554
this . list_height = this . list . scrollHeight ;
552
555
} else {
553
556
this . list_height = this . items [ this . items . length - 1 ] . offsetTop ;
554
557
}
555
- this . list . addEventListener ( 'touchstart' , this . dragStart , false ) ;
556
- this . list . addEventListener ( 'mousedown' , this . dragStart , false ) ;
557
558
}
558
559
559
560
dragStart ( e ) {
@@ -574,7 +575,7 @@ class Sortable {
574
575
if ( ! this . handle ) return ;
575
576
this . list . style . position = 'relative' ;
576
577
this . item . classList . add ( 'is-dragging' )
577
-
578
+ if ( ! this . items [ 1 ] ) return ;
578
579
this . itemHeight = this . items [ 1 ] . offsetTop ;
579
580
this . listHeight = this . list_height ;
580
581
this . startTouchY = this . getDragY ( e ) ;
0 commit comments