Skip to content

Commit bc335bd

Browse files
author
hikki
committed
1.5
1 parent 92b9e95 commit bc335bd

File tree

2 files changed

+27
-38
lines changed

2 files changed

+27
-38
lines changed

resources/assets/component.js

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class ComponentLine {
193193
/*foot*/
194194
this.makeFoot(foot);
195195
/*sort*/
196-
this.sortAble();
196+
this.sortable();
197197
}
198198

199199
makeHead() {
@@ -308,7 +308,6 @@ class ComponentLine {
308308
object.DATA.push(insert);
309309
object.DATA_INPUT.value = JSON.stringify(object.DATA);
310310
object.TBODY_DOM.scrollTop = object.TBODY_DOM.scrollHeight;
311-
object.SORTABLE.resetListHeight();
312311
},false);
313312
this.DOM.getElementsByClassName('JsonTableInsert')[0].appendChild(i);
314313
}
@@ -371,18 +370,21 @@ class ComponentLine {
371370
tbody.childNodes[node].setAttribute('data-key', node);
372371
}
373372
}
374-
375-
object.SORTABLE.resetListHeight();
376373
}, false);
377374
td.appendChild(D);
378375
}
379376
td.style = 'width:50px';
380377
}
381378

382-
sortAble(){
379+
sortable(){
383380
var object = this;
384-
setTimeout(function () {
385-
object.SORTABLE = new ComponentSortable(object.TBODY_DOM);
381+
this.SORTABLE = new ComponentSortable(this.TBODY_DOM,function (sort) {
382+
let data = [];
383+
sort.forEach(function (k) {
384+
data.push(object.DATA[k]);
385+
});
386+
object.DATA = data;
387+
object.DATA_INPUT.value = JSON.stringify(object.DATA);
386388
});
387389
}
388390
}
@@ -519,41 +521,36 @@ class ComponentPlane {
519521
}
520522

521523
class ComponentSortable {
522-
list_height;
523-
constructor(list, options) {
524+
constructor(list, callback=null) {
524525
this.list = (typeof list === 'string')
525526
? document.querySelector(list)
526527
: list;
527-
this.options = Object.assign({
528+
this.options = {
528529
animationSpeed: 200,
529530
animationEasing: 'ease-out',
530-
}, options || {});
531-
531+
};
532+
this.callback = callback;
532533
this.animation = false;
533-
this.resetListHeight();
534534
this.dragStart = this.dragStart.bind(this);
535535
this.dragMove = this.dragMove.bind(this);
536536
this.dragEnd = this.dragEnd.bind(this);
537537
this.list.addEventListener('touchstart', this.dragStart, false);
538538
this.list.addEventListener('mousedown', this.dragStart, false);
539539
}
540540

541-
resetListHeight(){
541+
reset(){
542542
this.items = Array.from(this.list.children);
543-
if(this.items.length<1)return;
544543
if(this.items[this.items.length-1].offsetTop > this.list.offsetHeight){
545-
this.list_height = this.list.scrollHeight;
544+
this.listHeight = this.list.scrollHeight;
546545
}else {
547-
this.list_height = this.items[this.items.length-1].offsetTop;
546+
this.listHeight = this.items[this.items.length-1].offsetTop;
548547
}
549548
}
550549

551550
dragStart(e) {
551+
this.reset();
552552
if (this.animation) return;
553553
if(this.items.length<2)return;
554-
if (e.type === 'mousedown' && e.which !== 1) return;
555-
if (e.type === 'touchstart' && e.touches.length > 1) return;
556-
557554
this.handle = null;
558555

559556
let el = e.target;
@@ -567,9 +564,7 @@ class ComponentSortable {
567564
if (!this.handle) return;
568565
this.list.style.position = 'relative';
569566
this.item.classList.add('is-dragging')
570-
if(!this.items[1])return;
571567
this.itemHeight = this.items[1].offsetTop;
572-
this.listHeight = this.list_height;
573568
this.startTouchY = this.getDragY(e);
574569
this.startTop = this.item.offsetTop;
575570

@@ -583,13 +578,6 @@ class ComponentSortable {
583578
item.style.zIndex = (item == this.item) ? 2 : 1;
584579
});
585580

586-
setTimeout(() => {
587-
this.items.forEach(item => {
588-
if (this.item == item) return;
589-
item.style.transition = `transform ${this.options.animationSpeed}ms ${this.options.animationEasing}`;
590-
})
591-
});
592-
593581
this.positions = this.items.map((item, index) => index);
594582
this.position = Math.round((this.startTop / this.listHeight) * this.items.length);
595583

@@ -611,10 +599,10 @@ class ComponentSortable {
611599
this.swapElements(this.positions, this.position, index);
612600
this.position = index;
613601
});
614-
615602
this.items.forEach((item, index) => {
616603
if (item == this.item) return;
617604
item.style.transform = `translateY(${this.positions.indexOf(index) * this.itemHeight}px)`;
605+
item.style.transition = `transform ${this.options.animationSpeed}ms ${this.options.animationEasing}`;
618606
});
619607

620608
e.preventDefault();
@@ -625,8 +613,8 @@ class ComponentSortable {
625613
if(this.items.length<2)return;
626614
this.item.style.transition = `all ${this.options.animationSpeed}ms ${this.options.animationEasing}`;
627615
this.item.style.transform = `translateY(${this.position * this.itemHeight}px)`;
628-
629616
this.item.classList.remove('is-dragging');
617+
if(typeof this.callback == 'function') this.callback(this.positions);
630618

631619
setTimeout(() => {
632620
this.list.style.position = '';
@@ -641,9 +629,11 @@ class ComponentSortable {
641629
item.style.zIndex = '';
642630
});
643631

644-
this.positions.map(i => this.list.appendChild(this.items[i]));
645-
this.items = Array.from(this.list.children);
646-
632+
this.positions.map(i => {
633+
if(this.items[i]) {
634+
this.list.appendChild(this.items[i]);
635+
}
636+
});
647637
this.animation = false;
648638
}, this.options.animationSpeed);
649639

src/DLPViewer.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function makeComponentDot(Form $form, string $column, string $titl
5353
* @param Form $form
5454
* @param string $column 数据字段名
5555
* @param string $title 名称
56-
* @param array $data 数据
56+
* @param string $data json数据
5757
* @param array $settings 配置项[setting,...]
5858
* $settings = [
5959
* 'columns'=>[
@@ -70,7 +70,7 @@ public static function makeComponentDot(Form $form, string $column, string $titl
7070
* ] array 多列操作设置 (选填)
7171
* ]
7272
*/
73-
public static function makeComponentLine(Form $form, string $column, string $title, array $data = [], array $settings = [])
73+
public static function makeComponentLine(Form $form, string $column, string $title, string $data, array $settings = [])
7474
{
7575
$strict = isset($settings['strict']) && $settings['strict'] ? true : false;
7676
$width = isset($settings['width']) ? $settings['width'] : '100%';
@@ -79,9 +79,8 @@ public static function makeComponentLine(Form $form, string $column, string $tit
7979
if (!isset($settings['columns'])) return;
8080
$columns = $settings['columns'];
8181
if ($strict) {
82+
$data = (array)json_decode($data, true);
8283
$data = DLPHelper::safeJson($data);
83-
} else {
84-
$data = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
8584
}
8685
$columns = json_encode($columns, JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS);
8786
Admin::script(<<<EOF

0 commit comments

Comments
 (0)