-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrangeControl.vue
1338 lines (1282 loc) · 56.4 KB
/
rangeControl.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<template>
<div
@click="activeColorItem=[]"
:style="{
'max-width': maxWidth=='auto'?'auto':maxWidth+'px',
'max-height': maxHeight=='auto'?'auto':maxHeight+'px',
}"
:key="rangeKey"
ref="weekRangeWrap"
@mouseleave="wrapMouseOut"
@scroll="weekRangeWrapScroll"
class="week-range-wrap">
<!-- 顶部 -->
<div
v-show="showhDataHead"
class="title-text"
:style="{top: headTop + 'px'}"
:class="{opac: opacityTitle}">
<div class="title-v0">{{opt.vhTitle}}</div>
<div
class="title-data"
:class="{
'title-data-center': opt.titleTextAlign == 'center'
}"
:style="{
width: opt.unitWidth + 'px',
}"
v-for="(hItem, hIndex) in hDataComp"
:key="hIndex + 'title-vvv'">
<span class="span-text" v-show="hIndex % (opt.rangeCount || 1)==0">
{{hItem}}{{opt.hDataUnit}}
</span>
<!-- 最后一个文本 -->
<span class="span-last" v-if="hDataComp.length - 1 == hIndex && opt.lastTitle != ''">
{{opt.lastTitle}}
</span>
</div>
</div>
<!-- 绘图区域 -->
<div style="position: relative;" v-if="combineAllLine == false">
<!-- 撑出滚动条 -->
<div :style="{height: (vDataComp.length * 50 + 10) + 'px'}"></div>
<template v-for="line in vDataComp.length">
<div class="week-wrap"
style="position: absolute; left: 0px; z-index: 1999; margin-top: 0px;"
v-if="isRender(((line - 1) * 50 + 10), vDataComp.length * 50 + 10)"
:style="{top: ((line - 1) * 50 + 10) + 'px'}"
@mouseover="lineMouseOver(line - 1)"
@click.stop="lineClick(line - 1)"
:key="line+'vDataComp'">
<!-- 左侧列(每行) -->
<div class="title-v nowrap">
<span :title="vDataComp[line - 1]">
{{vDataComp[line - 1]}}
</span>
<div v-show="opt.allHideDrag == false && disabled == false && showOperationBtn" class="operation-btn">
<div class="operation">
<!-- 复制到上一行 -->
<div class="copy-up-icon" v-show="line != 1" @click="copyToPrev(line-1)" title="复制到上一行">
<i class="el-icon-top"></i>
</div>
<!-- 恢复按钮 -->
<div class="reset-icon" @click="resetLine(line-1)" title="恢复">
<i class="el-icon-refresh-left"></i>
</div>
<!-- 复制到下一行 -->
<div class="copy-down-icon" v-show="line != res.length" @click="copyToNext(line-1)" title="复制到下一行">
<i class="el-icon-bottom"></i>
</div>
</div>
</div>
</div>
<!-- 绘图区域(每行) -->
<div :ref="'wrap' + line" class="title-data2-wrap">
<!-- 背景格子 -->
<div
class="title-data2"
:class="{
last: hIndex == hDataComp.length - 1
}"
:style="{width: opt.unitWidth + 'px'}"
v-for="(hItem, hIndex) in hDataComp"
:key="hIndex+'hDataComp'">
</div>
<template v-if="res[line - 1]">
<!-- 颜色格子 (正常)-->
<template v-for="(colorItem, colorItemIndex) in res[line - 1].data">
<div
class="colorItem"
v-if="res[line - 1].data[colorItemIndex]"
:style="{
width: res[line - 1].data[colorItemIndex].len * opt.unitWidth + 'px',
left: res[line - 1].data[colorItemIndex].left * opt.unitWidth + 'px',
background: res[line - 1].data[colorItemIndex].color? res[line - 1].data[colorItemIndex].color:opt.color[res[line - 1].data[colorItemIndex].colorIndex],
opacity: res[line - 1].data[colorItemIndex].code == 'rangeBlank'? 0: 1
}"
:class="{
last: colorItemIndex == res[line - 1].data.length - 1 && res[line - 1].data.length > 1,
first: colorItemIndex == 0 && res[line - 1].data.length > 1
}"
@click="colorItemActive(line - 1, colorItemIndex)"
:key="'colorItem' + colorItemIndex + 'colorItemComp250'">
<!-- 选中激活的状态 -->
<div v-show="activeColorItem[0] == line - 1 && activeColorItem[1] == colorItemIndex">
<div class="active-status-left-top"></div>
<div class="active-status-right-top"></div>
<div class="active-status-left-bottom"></div>
<div class="active-status-right-bottom"></div>
</div>
<!-- 颜色块顶部显示值 -->
<span
v-show="disabled? res[line - 1].data[colorItemIndex].len != 0: true"
class="tip"
:style="{color: res[line - 1].data[colorItemIndex].color?res[line - 1].data[colorItemIndex].color:opt.color[res[line - 1].data[colorItemIndex].colorIndex]}">
{{
colorItemTopValueFn(
res[line - 1],
colorItemIndex
)
}}
</span>
<!-- 颜色块内部显示文本 -->
<span :title="colorItemTextFn(res[line - 1], colorItemIndex).title" class="text nowrap">
<span v-html="colorItemTextFn(res[line - 1], colorItemIndex).text"></span>
</span>
</div>
</template>
<!-- 拖拽线条 -->
<template v-for="(colorItem, colorItemIndex) in res[line - 1].data">
<div
v-show="
!opt.allHideDrag
&&
(colorItemIndex == 0? !opt.hideFirstLeftDrag: true)
&&
disabled == false
"
v-if="res[line - 1].data[colorItemIndex]"
:key="'colorItem' + colorItemIndex + '-line250'"
class="right-drag"
:ref="'line-'+(line-1)+colorItemIndex"
@click.stop
@mousedown.stop.prevent="
drag(
line - 1,
colorItemIndex,
$refs['wrap' + line],
$refs['line-'+(line-1)+colorItemIndex],
$event
)
"
:style="{
'z-index': 250 + colorItemIndex,
left: res[line - 1].data[colorItemIndex].left * opt.unitWidth - 5 + 'px',
height: 40/(fixDragLine['line_'+(line-1)]['colorIndex_'+colorItemIndex+'_repeat'].repeat) + 'px',
top: (40*(fixDragLine['line_'+(line-1)]['colorIndex_'+colorItemIndex+'_repeat'].topIndex)/(fixDragLine['line_'+(line-1)]['colorIndex_'+colorItemIndex+'_repeat'].repeat)) + 'px',
}">
<!-- 重合时的小色块 -->
<span
v-show="fixDragLine['line_'+(line-1)]['colorIndex_'+colorItemIndex+'_repeat'].repeat != 1"
class="red-btn"
:style="{
background: res[line - 1].data[colorItemIndex].color?res[line - 1].data[colorItemIndex].color:opt.color[res[line - 1].data[colorItemIndex].colorIndex],
}">
</span>
<!-- 中间细竖线 -->
<span :style="{background: res[line - 1].data[colorItemIndex].color?res[line - 1].data[colorItemIndex].color:opt.color[res[line - 1].data[colorItemIndex].colorIndex]}" class="drag-line"></span>
</div>
</template>
<!-- 最后一根、拖拽线条 -->
<template v-if="res[line - 1].data[res[line - 1].data.length - 1]">
<div class="right-drag"
:ref="'line'+line+'-last'"
v-show="!opt.allHideDrag && disabled == false"
@click.stop
@mousedown.stop.prevent="
dragLast(
line - 1,
res[line - 1].data.length - 1,
$refs['wrap' + line],
$refs['line'+line+'-last'],
$event
)
"
:style="{
'z-index': 250 + 100,
left: (+res[line - 1].data[res[line - 1].data.length - 1].left + +res[line - 1].data[res[line - 1].data.length - 1].len) * opt.unitWidth - 5 + 'px',
height: 40/(fixDragLine['line_'+(line-1)]['colorIndex_last_repeat'].repeat) + 'px',
top: (40*(fixDragLine['line_'+(line-1)]['colorIndex_last_repeat'].topIndex)/(fixDragLine['line_'+(line-1)]['colorIndex_last_repeat'].repeat)) + 'px',
}">
<!-- 重合时的小色块 -->
<span
v-show="fixDragLine['line_'+(line-1)]['colorIndex_last_repeat'].repeat != 1"
:style="{
background: '#fff',
}"
class="red-btn">
</span>
<!-- 中间细竖线 -->
<span style="background: #fff" class="drag-line"></span>
</div>
</template>
</template>
</div>
</div>
</template>
<!-- 垂直时间指示线 -->
<div class="v-tip-line" :style="{left: tipLineLeft+'px', top: (0 + +headTop) + 'px'}" v-show="opacityTitle">
<span>
{{tipLineData}}
</span>
</div>
</div>
<!-- 合并成一行的绘图区域 -->
<div style="position: relative;" v-if="combineAllLine">
<div class="week-wrap" key="合并航">
<!-- 左侧列(每行) -->
<div class="title-v nowrap">
<span> </span>
</div>
<!-- 绘图区域(每行) -->
<div class="title-data2-wrap">
<!-- 背景格子 -->
<div
class="title-data2"
:class="{
last: hIndex == hDataComp.length - 1
}"
:style="{width: opt.unitWidth + 'px'}"
v-for="(hItem, hIndex) in hDataComp"
:key="hIndex+'hDataComp'">
</div>
<!-- 每行的颜色格子(合并到一行)-->
<template v-for="(linecolorItem, linecolorItemIndex) in res">
<template v-for="(colorItem, colorItemIndex) in linecolorItem.data">
<div
class="colorItem"
:style="{
width: colorItem.len * opt.unitWidth + 'px',
left: colorItem.left * opt.unitWidth + 'px',
background: colorItem.color?colorItem.color:opt.color[colorItem.colorIndex],
opacity: colorItem.code == 'rangeBlank'? 0: 1,
top: 40 * colorItem.combine.top + 'px',
height: 40 * colorItem.combine.height + 'px',
zIndex: 250 + colorItem.combine.zIndex*1 ,
}"
:key="'colorItem' + colorItemIndex + linecolorItemIndex + 'colorItemComp250'">
</div>
</template>
</template>
</div>
</div>
</div>
</div>
</template>
<script>
/** 【事件】
* add
* remove
* drag
* colorItemActive
* wrapMouseOut
* lineMouseOver
* lineClick
*/
/*
【颜色块的数据格式】
{
// 图形数据相关
name: colorItem[j].name,
code: colorItem[j].code, //其中 code="rangeBlank" 表示是空白的占位色块
len: 0,
colorIndex: 0,
//图形色块内部id
id: 0,
// extraData字段放入业务数据、额外数据
extraData: {}
}
*/
export default {
name: "rangeControl",
props: {
disabled: {
default: false,
},
maxWidth: {
default: 'auto',
},
maxHeight: {
default: 'auto',
},
/** 每行合并显示的配置
* { //编码
code_1: {
top: 0,//比例
height: 1,//比例
zIndex: 1
},
code_5: {
top: 0,
height: 1,
zIndex: 1
},
code_2: {
top: 0.2,
height: 0.6,
zIndex: 2
},
code_4: {
top: 0.2,
height: 0.6,
zIndex: 3
},
code_3: {
top: 0.2,
height: 0.6,
zIndex: 3
},
}
* */
combineAllLine: {
default: false,
},
showOperationBtn: {
default: true,
},
showhDataHead: {
default: true,
},
//颜色块内部显示文本
colorItemTextFn: {
type: Function,
default: (curLine, curLineIndex)=>{
if(curLine.data[curLineIndex]){
return {
text: curLine.data[curLineIndex].name,
title: curLine.data[curLineIndex].name,
};
}else{
return {
text: '',
title: '',
};
}
}
},
//颜色块上面显示值
colorItemTopValueFn: {
type: Function,
default: (curLine, curLineIndex)=>{
if(curLine.data[curLineIndex]){
return curLine.data[curLineIndex].len;
}else{
return '';
}
}
},
//拖拽时,指示线顶部提示文本
tipTextFn: {
type: Function,
default: (rangeData, curLine, colorIndex, isLast=false)=>{
if(rangeData[curLine].data[colorIndex]){
return rangeData[curLine].data[colorIndex].left;
}else{
return ''
}
}
},
},
data() {
return {
headTop: 0,
scrollLeft: 0,
browerType: '',
// 垂直指示线
opacityTitle: false,
tipLineLeft: 0,
tipLineData: '',
// 原始图形数据
_res: [],
// 实时图形数据
res: [],
// 实时选中的激活色块
activeColorItem: [],
rangeKey: 0,
opt: {},
};
},
computed: {
hDataComp(){
var d = this.opt.hData || []
return d;
},
vDataComp(){
var d = this.opt.vData || []
return d;
},
//拖拽线合并处理
fixDragLine(){
var res = this.jsonClone(this.res);
var dragLineMap = {};
for(var i=0; i<res.length; i++){
dragLineMap['line_'+i] = {};
var lastRepeat = 1, lastTopIndex = 0;
for(var j=0; j<res[i].data.length; j++){
dragLineMap['line_'+i]['colorIndex_'+j+'_repeat'] = {
repeat: 1,
topIndex: 0
};
var line_col = dragLineMap['line_'+i]['colorIndex_'+j+'_repeat'];
var repeatArr = [j];
for(var k=0; k<res[i].data.length; k++){
if(k != j && (res[i].data[k].left*10).toFixed(0) == (res[i].data[j].left*10).toFixed(0)){
line_col.repeat = line_col.repeat + 1;
repeatArr.push(k);
}
}
repeatArr.sort();
// 该行repeatArr中的最大拖拽线和最右拖拽线是否重合
if(res[i].data.length != 0 && repeatArr.includes(res[i].data.length - 1)){
var colRightIndex = repeatArr[repeatArr.length - 1];
if(res[i].data[colRightIndex].len == 0){
line_col.repeat = line_col.repeat + 1;
lastRepeat = line_col.repeat;
repeatArr.push(999999999);
lastTopIndex = repeatArr.length - 1;
}
}
for(var m=0; m<repeatArr.length; m++){
if(repeatArr[m] == j){
line_col.topIndex = m;
break ;
}
}
}
if(res[i].data.length != 0){
dragLineMap['line_'+i]['colorIndex_last_repeat'] = {
repeat: lastRepeat,
topIndex: lastTopIndex
}
}
}
return dragLineMap;
},
},
mounted() {
var vm = this;
var agent = window.navigator.userAgent.toLowerCase();
if (agent.indexOf('chrome') > 0) {
this.browerType = 'chrome'
} else if (agent.indexOf('firefox') > 0) {
this.browerType = 'firefox'
} else if (agent.indexOf('trident') > 0) {
this.browerType = 'ie'
} else if (agent.indexOf('edge') > 0) {
this.browerType = 'edge'
} else {
this.browerType = 'other'
};
},
methods: {
isRender(top, fullHeight){
if(this.maxHeight == 'auto' || (fullHeight - 120) <= this.maxHeight){
return true;
}
//上下 各120 像素
//this.headTop | fullHeight | this.maxHeight
var see_h_top = this.headTop - 120;
var see_h_bottom = +this.headTop + +this.maxHeight + 120;
if(top >= see_h_top && top <= see_h_bottom) return true;
return false;
},
weekRangeWrapScroll(e){
if(this.maxHeight != 'auto'){
var weekRangeWrap = this.$refs.weekRangeWrap;
this.headTop = weekRangeWrap.scrollTop;
this.scrollLeft = weekRangeWrap.scrollLeft;
}
},
jsonClone(d){
return JSON.parse(JSON.stringify(d))
},
//根据len,重新生成left
setDragLeftPos(data){
var d = this.jsonClone(data);
for(var i=0; i<d.length; i++){
for(var j=0; j<d[i].data.length; j++){
var fullLeft = +d[i].start;
var sumLeft = 0;
for(var k=0; k<j; k++){
sumLeft += +d[i].data[k].len;
}
d[i].data[j].left = fullLeft + sumLeft;
}
};
return d;
},
//初始化图形
init(data, options, scrollPos){
var defaultOpt = {
// 左上角标题
vhTitle: '时间',
// 横向时间数据
hData: ['hData1','hData2','hData3','hData4','hData5','hData6','hData7','hData8','hData9','hData10'],
hDataUnit: '',
// 纵向文本数据
vData: ['vData1','vData2','vData3','vData4','vData5'],
//内置10种颜色序列
color: ['#71cf73', '#badf5f', '#0adddd', '#5797f0','#ffcb75', '#e59332', '#ff8040', '#9f5000', '#8826e3', '#f13f31', 'rgba(255,255,255,.1)'],
// 分段间隔显示
rangeCount: 1,
// 每单位像素
unitWidth: 30,
//允许0.5单位
isHalf: true,
//隐藏第一个左边的拖拽
hideFirstLeftDrag: false,
//隐藏全部拖拽
allHideDrag: false,
// 是否松散型拖拽(拖拽到其他色块时是否停止,还是一起移动)
looseDrag: true,
//顶部横向标题的显示位置 ( left、 center )
titleTextAlign: 'left',
//顶部横向最右侧的额外标题(一般用于连续时间末尾显示)
lastTitle: '',
};
if(options){
var opt = this.jsonClone(options)
this.opt = {...defaultOpt, ...opt}
}else{
this.opt = defaultOpt;
};
//设置唯一序列id、默认颜色索引
if(data){
for(var i=0; i<data.length; i++){
for(var j=0; j<data[i].data.length; j++){
var c = data[i].data[j];
if(c.id == undefined){
c.id = j;
}
if(c.colorIndex == undefined){
if(j > this.opt.color.length - 1){
c.colorIndex = this.opt.color.length - 1;
}else{
c.colorIndex = j;
}
}
}
}
};
if(data && this.combineAllLine == false){
this.res = this.setDragLeftPos(this.jsonClone(data));
}else if(data && this.combineAllLine){
this.res = this.setCombine(
this.setDragLeftPos(this.jsonClone(data))
);
};
if(scrollPos){
this.$nextTick(()=>{
this.$refs.weekRangeWrap.scrollTop = scrollPos.top
this.$refs.weekRangeWrap.scrollLeft = scrollPos.left
})
}
this._res = this.jsonClone(this.res)
this.rangeKey = Date.now();
},
//添加一项
addColorItem(name, index,
{
/**
* 图形相关
*/
code = '',
colorIndex = 0, //颜色索引,表示什么颜色
lineNum = -1, //默认-1,表示插入全部的行
defaultLen = 0, //默认色块的长度
/**
* 额外数据
*/
extraData = {} //业务数据
}={}
){
var res = this.jsonClone(this.res);
//插入该项
if(!code) code = name;
if(lineNum == -1){
for(var i=0; i<res.length; i++){
res[i].data.splice(index-1, 0, {
name,
code,
colorIndex,
len: defaultLen,
extraData,
})
};
}else{
for(var i=0; i<res.length; i++){
if(i == lineNum){
res[i].data.splice(index-1, 0, {
name,
code,
colorIndex,
len: defaultLen,
extraData,
})
break ;
}
};
};
//重设id索引
for(var i=0; i<res.length; i++){
for(var j=0; j<res[i].data.length; j++){
var c = res[i].data[j];
c.id = j;
}
};
//设置位置
this.res = this.setDragLeftPos(res);
//重置原始记录
this._res = this.jsonClone(this.res);
this.$emit('add', this.jsonClone(this.res));
},
//删除一项
removeColorItem(index, lineNum = -1){
var res = this.jsonClone(this.res);
//删除该项
if(lineNum == -1){
for(var i=0; i<res.length; i++){
res[i].data.splice(index, 1)
};
}else{
for(var i=0; i<res.length; i++){
if(lineNum == i){
res[i].data.splice(index, 1);
break ;
}
};
}
//重新设置索引
for(var i=0; i<res.length; i++){
for(var j=0; j<res[i].data.length; j++){
var c = res[i].data[j];
c.id = j;
}
};
//设置位置
this.res = this.setDragLeftPos(res);
//重置原始记录
this._res = this.jsonClone(this.res)
this.$emit('remove', this.jsonClone(this.res));
},
drag(dataLine, colorItemIndex, wrapEl, lineEl, e){
var res2 = this.jsonClone(this.res)
if(wrapEl instanceof Array) wrapEl = wrapEl[0];
if(lineEl instanceof Array) lineEl = lineEl[0];
const initClientX = e.clientX;
const wrapWidth = wrapEl.offsetWidth;
let x = null;
//指示线
this.opacityTitle = true;
this.tipLineLeft = +lineEl.offsetLeft + 84;
this.tipLineData = this.tipTextFn(this.res, dataLine, colorItemIndex);
document.onmousemove = e2 => {
var res = this.jsonClone(res2)
e2.preventDefault();
x = e2.clientX - initClientX;
var disCount;
if(this.opt.isHalf){
var count = (x/this.opt.unitWidth).toFixed(1);
var zhenshu = (count*1).toFixed(0);
if(count - zhenshu >= 0.5){
disCount = +zhenshu + 1
}else if(count - zhenshu >= 0.1){
disCount = +zhenshu + 0.5
}else{
disCount = +zhenshu
}
}else{
disCount = Math.round(x/this.opt.unitWidth);
}
if(colorItemIndex == 0){
//第1个
var start = res[dataLine].start;
var len = res[dataLine].data[0].len;
var new_start = +start + +disCount;
var new_len = +len - +disCount;
if(new_start < 0){
//小于0
res[dataLine].start = 0;
res[dataLine].data[0].len = +len + +start;
}else if(new_start > +start + +len){
if(this.opt.looseDrag){
if(new_start > this.opt.hData.length){
res[dataLine].start = this.opt.hData.length
for(var i=0; i<res[dataLine].data.length; i++){
res[dataLine].data[i].len = 0
}
}else{
res[dataLine].start = new_start;
res[dataLine].data[0].len = 0;
for(var i=0; i<res[dataLine].data.length; i++){
if(i != 0){
var otherLeft = res[dataLine].data[i].left;
var otherLen = res[dataLine].data[i].len;
if(+otherLeft + +otherLen <= new_start){
res[dataLine].data[i].len = 0
}else if(otherLeft < new_start){
res[dataLine].data[i].len = otherLen - (new_start - otherLeft)
}
}
}
}
}else{
//大于加len
res[dataLine].start = +start + +len;
res[dataLine].data[0].len = 0;
}
}else{
res[dataLine].start = new_start;
res[dataLine].data[0].len = new_len;
}
}else{
//不是第1个
if(this.opt.looseDrag){
var start = res[dataLine].start;
var curLeft = res[dataLine].data[colorItemIndex].left;
var curLen = res[dataLine].data[colorItemIndex].len;
var totalLen = this.opt.hData.length;
if(+curLeft + +disCount <= res[dataLine].start){
//左侧所有项len都被拉成0
for(var i=0; i<colorItemIndex; i++){
res[dataLine].data[i].len = 0;
}
if(+curLeft + +disCount > 0){
res[dataLine].start = +curLeft + +disCount;
res[dataLine].data[colorItemIndex].len = curLeft - res[dataLine].start + +res[dataLine].data[colorItemIndex].len
}else{
res[dataLine].start = 0;
res[dataLine].data[colorItemIndex].len = +curLen + +curLeft;
}
} else if(+curLeft + +disCount >= totalLen){
//右侧所有项len都被拉成0
for(
var i=res[dataLine].data.length-1;
i>=colorItemIndex;
i--
){
res[dataLine].data[i].len = 0;
}
res[dataLine].data[colorItemIndex - 1].len = totalLen - res[dataLine].data[colorItemIndex - 1].left;
}else{
if(disCount < 0){
// 左偏移方向
var curItemLeft = +curLeft + +disCount,
combineNum = null;
if(curItemLeft > res[dataLine].start){
for(var i=0; i<colorItemIndex; i++){
if(res[dataLine].data[i].left < curItemLeft && +res[dataLine].data[i].left + +res[dataLine].data[i].len >= curItemLeft){
combineNum = i;
break ;
}
}
if(combineNum !== null){
for(var i=combineNum+1; i<colorItemIndex; i++){
res[dataLine].data[i].len = 0;
}
res[dataLine].data[combineNum].len = curItemLeft - res[dataLine].data[combineNum].left;
res[dataLine].data[colorItemIndex].len = +res[dataLine].data[colorItemIndex].len + +curLeft - curItemLeft;
}else{
res[dataLine].data[colorItemIndex].len = res[dataLine].data[colorItemIndex].len - disCount;
res[dataLine].data[colorItemIndex - 1].len = res[dataLine].data[colorItemIndex - 1].len + disCount;
}
}else{
//左方向均置为len=0
for(var i=0; i<colorItemIndex; i++){
res[dataLine].data[i].len = 0;
}
if(curItemLeft > 0){
res[dataLine].data.start = curItemLeft;
res[dataLine].data[colorItemIndex].len = curLeft - curItemLeft + +curLen;
}else{
res[dataLine].data.start = 0;
res[dataLine].data[colorItemIndex].len = +curLeft + +curLen;
}
}
}else if(disCount > 0){
// 右偏移方向
//专门指disCount在某项内部时,那项的索引
var fixedItemIndex = null, allRightZero = false;
for(
var i=colorItemIndex;
i<res[dataLine].data.length;
i++
){
var curItem = res[dataLine].data[i];
if(
// 在某项内部穿梭时
+curItem.left + +curItem.len > +curLeft + +disCount
&&
+curLeft + +disCount > curItem.left
){
fixedItemIndex = i;
// 之前已完全过去的项的len置为0
for(
var j=colorItemIndex;
j<i;
j++
){
res[dataLine].data[j].len = 0;
}
break ;
}else if(
// 到达某项边缘非内部位置时
+curLeft + +disCount == +curItem.left + +curItem.len
){
fixedItemIndex = null;
// 中间过去的项的len置为0
for(
var j=colorItemIndex;
j<=i;
j++
){
res[dataLine].data[j].len = 0;
}
break ;
}else if(
+curLeft + +disCount >= +res[dataLine].data[res[dataLine].data.length - 1].left + +res[dataLine].data[res[dataLine].data.length - 1].len
){
allRightZero = true;
break ;
}
}
if(allRightZero){
for(
var j=colorItemIndex;
j<res[dataLine].data.length;
j++
){
res[dataLine].data[j].len = 0;
}
}else{
if(fixedItemIndex != null){
res[dataLine].data[fixedItemIndex].len =
res[dataLine].data[fixedItemIndex].len - (+curLeft + +disCount - res[dataLine].data[fixedItemIndex].left);
}
}
// 被拖拽项的左侧那一项
res[dataLine].data[colorItemIndex - 1].len = +res[dataLine].data[colorItemIndex - 1].len + +disCount;
}
}
}else{
var prev_len = res[dataLine].data[colorItemIndex - 1].len;
var len = res[dataLine].data[colorItemIndex].len;
var prev_new_len = +prev_len + +disCount;
var new_len = +len - +disCount;
if(prev_new_len < 0){
res[dataLine].data[colorItemIndex - 1].len = 0;
res[dataLine].data[colorItemIndex].len = +prev_len + +len;
}else if(new_len < 0){
res[dataLine].data[colorItemIndex - 1].len = +prev_len + +len;
res[dataLine].data[colorItemIndex].len = 0;
}else{
res[dataLine].data[colorItemIndex - 1].len = prev_new_len;
res[dataLine].data[colorItemIndex].len = new_len;
}
}
}
this.res = this.setDragLeftPos(res);
//指示线
this.tipLineLeft = +lineEl.offsetLeft + 84;
this.tipLineData = this.tipTextFn(this.res, dataLine, colorItemIndex)
this.$emit('drag', this.jsonClone(this.res));
};
document.onmouseup = e2 => {
e2.preventDefault();
this.opacityTitle = false;
document.onmousemove = null;
document.onmouseup = null;
};
},
dragLast(dataLine, colorItemLength, wrapEl, lineEl, e){
var res2 = this.jsonClone(this.res)
if(wrapEl instanceof Array) wrapEl = wrapEl[0];
if(lineEl instanceof Array) lineEl = lineEl[0];
const initClientX = e.clientX;
const wrapWidth = wrapEl.offsetWidth;
let x = null;
//指示线
this.opacityTitle = true;
this.tipLineLeft = +lineEl.offsetLeft + 84;
this.tipLineData = this.tipTextFn(res2, dataLine, colorItemLength, true);
document.onmousemove = e2 => {
var res = this.jsonClone(res2)
e2.preventDefault();
x = e2.clientX - initClientX;
var disCount;
if(this.opt.isHalf){
var count = (x/this.opt.unitWidth).toFixed(1);
var zhenshu = (count*1).toFixed(0);
if(count - zhenshu >= 0.5){
disCount = +zhenshu + 1
}else if(count - zhenshu >= 0.1){
disCount = +zhenshu + 0.5
}else{
disCount = +zhenshu
}
}else{
disCount = Math.round(x/this.opt.unitWidth);
}
if(this.opt.looseDrag){
var start = res[dataLine].start;
var curLen = res[dataLine].data[colorItemLength].len;
var curLeft = res[dataLine].data[colorItemLength].left;
if(disCount > 0){
if(+disCount + +curLen + +curLeft >= this.opt.hData.length){
res[dataLine].data[colorItemLength].len = this.opt.hData.length - curLeft;
}else{
res[dataLine].data[colorItemLength].len = +curLen + +disCount;
}
}else if(disCount < 0){
if(-disCount >= +res[dataLine].data[colorItemLength].left + +res[dataLine].data[colorItemLength].len - res[dataLine].start){
var new_start = +res[dataLine].data[colorItemLength].left + +res[dataLine].data[colorItemLength].len + disCount;
if(new_start<0){
res[dataLine].start = 0;
}else{
res[dataLine].start = new_start;
}
for(var i=0; i<res[dataLine].data.length; i++){
res[dataLine].data[i].len = 0;
}
}else{
var colorItemIndex = null, colorItemLeftIen;
for(var i=0; i<res[dataLine].data.length; i++){
var disCountLeft = +res[dataLine].data[colorItemLength].left + +res[dataLine].data[colorItemLength].len + disCount;
if(
disCountLeft >= res[dataLine].data[i].left
&&
disCountLeft < +res[dataLine].data[i].left + +res[dataLine].data[i].len
){
colorItemIndex = i;
colorItemLeftIen = disCountLeft - res[dataLine].data[colorItemIndex].left;
res[dataLine].data[i].len = colorItemLeftIen;
break ;
};
};
if(colorItemIndex != null){
for(var i=colorItemIndex+1; i<res[dataLine].data.length; i++){
res[dataLine].data[i].len = 0;
}
};