emacroh5lib 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,917 @@
1
- <template src="./vue-drag-resize.html"></template>
1
+ <!-- <template src="./vue-drag-resize.html"></template>
2
2
  <script src="./vue-drag-resize.ts"></script>
3
- <style src="./vue-drag-resize.css"></style>
3
+ <style src="./vue-drag-resize.css"></style> -->
4
+
5
+
6
+ <template>
7
+ <div class="vdr" :style="positionStyle"
8
+ :class="`${(active || isActive) ? 'active' : 'inactive'} ${contentClass ? contentClass : ''}`"
9
+ @mousedown="bodyDown($event)" @touchstart="bodyDown($event)" @touchend="up($event)">
10
+ <div :style="sizeStyle" class="content-container" ref="container">
11
+ <slot></slot>
12
+ </div>
13
+ <div v-for="stick in sticks" class="vdr-stick"
14
+ :class="['vdr-stick-' + stick, isResizable ? '' : 'not-resizable']"
15
+ @mousedown.stop.prevent="stickDown(stick, $event)" @touchstart.stop.prevent="stickDown(stick, $event)"
16
+ :style="vdrStick(stick)">
17
+ </div>
18
+ </div>
19
+ </template>
20
+
21
+ <script lang="ts">
22
+
23
+
24
+ import { Component, Prop, Vue, Watch } from "vue-property-decorator";
25
+
26
+
27
+ const styleMapping = {
28
+ y: {
29
+ t: 'top',
30
+ m: 'marginTop',
31
+ b: 'bottom',
32
+ },
33
+ x: {
34
+ l: 'left',
35
+ m: 'marginLeft',
36
+ r: 'right',
37
+ },
38
+ };
39
+
40
+ function addEvents(events) {
41
+ events.forEach((cb, eventName) => {
42
+ document.documentElement.addEventListener(eventName, cb);
43
+ });
44
+ }
45
+
46
+ function removeEvents(events) {
47
+ events.forEach((cb, eventName) => {
48
+ document.documentElement.removeEventListener(eventName, cb);
49
+ });
50
+ }
51
+
52
+ @Component({ name: 'DragResizeViewTs' })
53
+ export default class DragResizeViewTs extends Vue {
54
+
55
+ @Prop({
56
+ type: String,
57
+ required: false,
58
+ default: ''
59
+ }) name;
60
+
61
+
62
+ @Prop({ type: Number, default: 8 }) stickSize;
63
+ @Prop({ type: Number, default: 1 }) parentScaleX;
64
+ @Prop({ type: Number, default: 1 }) parentScaleY;
65
+ @Prop({ type: Boolean, default: false, }) isActive;
66
+ @Prop({ type: Boolean, default: false, }) preventActiveBehavior;
67
+ @Prop({ type: Boolean, default: true, }) isDraggable;
68
+ @Prop({ type: Boolean, default: true, }) isResizable;
69
+ @Prop({ type: Boolean, default: false, }) aspectRatio;
70
+ @Prop({
71
+ type: Boolean, default: false,
72
+ }) parentLimitation;
73
+ @Prop({
74
+ type: Boolean, default: false,
75
+ }) snapToGrid;
76
+
77
+ @Prop({
78
+ type: Number,
79
+ default: 50,
80
+ validator(val) {
81
+ return val >= 0;
82
+ },
83
+ }) gridX;
84
+
85
+ @Prop({
86
+ type: Number,
87
+ default: 50,
88
+ validator(val) {
89
+ return val >= 0;
90
+ },
91
+ }) gridY;
92
+
93
+ @Prop({
94
+ type: Number,
95
+ default: 0,
96
+ validator(val) {
97
+ return val >= 0;
98
+ },
99
+ }) parentW;
100
+
101
+ @Prop({
102
+ type: Number,
103
+ default: 0,
104
+ validator(val) {
105
+ return val >= 0;
106
+ },
107
+ }) parentH;
108
+
109
+ @Prop({
110
+ type: [String, Number],
111
+ default: 200,
112
+ validator(val) {
113
+ return (typeof val === 'string') ? val === 'auto' : val >= 0;
114
+ },
115
+ }) w;
116
+
117
+ @Prop({
118
+ type: [String, Number],
119
+ default: 200,
120
+ validator(val) {
121
+ return (typeof val === 'string') ? val === 'auto' : val >= 0;
122
+ },
123
+ }) h;
124
+
125
+ @Prop({
126
+ type: Number,
127
+ default: 50,
128
+ validator(val) {
129
+ return val >= 0;
130
+ },
131
+ }) minw;
132
+
133
+ @Prop({
134
+ type: Number,
135
+ default: 50,
136
+ validator(val) {
137
+ return val >= 0;
138
+ },
139
+ }) minh;
140
+
141
+ @Prop({
142
+ type: Number,
143
+ default: 0,
144
+ validator(val) {
145
+ return typeof val === 'number';
146
+ },
147
+ }) x;
148
+
149
+ @Prop({
150
+ type: Number,
151
+ default: 0,
152
+ validator(val) {
153
+ return typeof val === 'number';
154
+ },
155
+ }) y;
156
+ @Prop({
157
+ type: [String, Number],
158
+ default: 'auto',
159
+ validator(val) {
160
+ return (typeof val === 'string') ? val === 'auto' : val >= 0;
161
+ },
162
+ }) z;
163
+ @Prop({
164
+ type: String,
165
+ default: null,
166
+ }) dragHandle;
167
+
168
+ @Prop({
169
+ type: String,
170
+ default: null,
171
+ }) dragCancel;
172
+
173
+ @Prop({
174
+ type: Array,
175
+ default() {
176
+ return ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml'];
177
+ },
178
+ }) sticks;
179
+
180
+ @Prop({
181
+ type: String,
182
+ default: 'both',
183
+ validator(val) {
184
+ return ['x', 'y', 'both', 'none'].indexOf(val) !== -1;
185
+ },
186
+ }) axis;
187
+
188
+ @Prop({
189
+ type: String,
190
+ required: false,
191
+ default: '',
192
+ }) contentClass;
193
+
194
+ @Prop({
195
+ type: Boolean,
196
+ required: false,
197
+ default: false
198
+ }) isStorage;
199
+
200
+ public emits = ['clicked', 'dragging', 'dragstop', 'resizing', 'resizestop', 'activated', 'deactivated']
201
+
202
+ public fixAspectRatio = null
203
+ public active = false
204
+ public zIndex = 1;
205
+ public parentWidth = 0;
206
+ public parentHeight = 0;
207
+ public left = 0;
208
+ public top = 0;
209
+ public right = 50;
210
+ public bottom = 50;
211
+ public minHeight = 10;
212
+ public stickDrag = false;
213
+ public bodyDrag = false;
214
+ public dimensionsBeforeMove: any;
215
+ public limits: any;
216
+ public currentStick: any;
217
+ public aspectFactor: any;
218
+ public domEvents: any;
219
+ public parentElement: any;
220
+ public _uid: any;
221
+
222
+ beforeCreate() {
223
+ this.stickDrag = false;
224
+ this.bodyDrag = false;
225
+ this.dimensionsBeforeMove = { pointerX: 0, pointerY: 0, x: 0, y: 0, w: 0, h: 0 };
226
+ this.limits = {
227
+ left: { min: null, max: null },
228
+ right: { min: null, max: null },
229
+ top: { min: null, max: null },
230
+ bottom: { min: null, max: null },
231
+ };
232
+
233
+ this.currentStick = null;
234
+ }
235
+
236
+
237
+ mounted() {
238
+ console.log("测试");
239
+
240
+ this.parentElement = this.$el.parentNode;
241
+ this.parentWidth = this.parentW ? this.parentW : this.parentElement.clientWidth;
242
+ this.parentHeight = this.parentH ? this.parentH : this.parentElement.clientHeight;
243
+
244
+
245
+
246
+ this.left = this.x;
247
+ this.top = this.y;
248
+ this.right = this.parentWidth - (this.w === 'auto' ? (this.$refs.container as HTMLElement).scrollWidth : this.w) - this.left;
249
+ this.bottom = this.parentHeight - (this.h === 'auto' ? (this.$refs.container as HTMLElement).scrollHeight : this.h) - this.top;
250
+
251
+ this.domEvents = new Map([
252
+ ['mousemove', this.move],
253
+ ['mouseup', this.up],
254
+ ['mouseleave', this.up],
255
+ ['mousedown', this.deselect],
256
+ ['touchmove', this.move],
257
+ ['touchend', this.up],
258
+ ['touchcancel', this.up],
259
+ ['touchstart', this.up],
260
+ ]);
261
+
262
+ addEvents(this.domEvents);
263
+
264
+ if (this.dragHandle) {
265
+ [...this.$el.querySelectorAll(this.dragHandle)].forEach((dragHandle) => {
266
+ dragHandle.setAttribute('data-drag-handle', this._uid);
267
+ });
268
+ }
269
+
270
+ if (this.dragCancel) {
271
+ [...this.$el.querySelectorAll(this.dragCancel)].forEach((cancelHandle) => {
272
+ cancelHandle.setAttribute('data-drag-cancel', this._uid);
273
+ });
274
+ }
275
+
276
+ if (this.name.trim() !== '' && this.isStorage) {
277
+ let info = JSON.parse(localStorage.getItem("DragResizeView_Info_" + this.name) as string)
278
+ if (info !== null
279
+ && info.left !== null && info.top !== null
280
+ && info.right !== null && info.bottom !== null) {
281
+ this.left = info.left
282
+ this.top = info.top
283
+ this.right = info.right
284
+ this.bottom = info.bottom
285
+ } else {
286
+ localStorage.removeItem("DragResizeView_Info_" + this.name)
287
+ }
288
+ }
289
+ }
290
+
291
+ beforeDestroy() {
292
+ removeEvents(this.domEvents);
293
+ }
294
+
295
+ deselect() {
296
+ if (this.preventActiveBehavior) {
297
+ return;
298
+ }
299
+ this.active = false;
300
+ }
301
+
302
+ move(ev) {
303
+ if (!this.stickDrag && !this.bodyDrag) {
304
+ return;
305
+ }
306
+
307
+ ev.stopPropagation();
308
+
309
+ const pageX = typeof ev.pageX !== 'undefined' ? ev.pageX : ev.touches[0].pageX;
310
+ const pageY = typeof ev.pageY !== 'undefined' ? ev.pageY : ev.touches[0].pageY;
311
+
312
+ const { dimensionsBeforeMove } = this;
313
+
314
+ const delta = {
315
+ x: (dimensionsBeforeMove.pointerX - pageX) / this.parentScaleX,
316
+ y: (dimensionsBeforeMove.pointerY - pageY) / this.parentScaleY,
317
+ };
318
+
319
+ if (this.stickDrag) {
320
+ this.stickMove(delta);
321
+ }
322
+
323
+ if (this.bodyDrag) {
324
+ if (this.axis === 'x') {
325
+ delta.y = 0;
326
+ } else if (this.axis === 'y') {
327
+ delta.x = 0;
328
+ } else if (this.axis === 'none') {
329
+ return;
330
+ }
331
+ this.bodyMove(delta);
332
+ }
333
+ }
334
+
335
+ up(ev) {
336
+ if (this.stickDrag) {
337
+ this.stickUp();
338
+ } else if (this.bodyDrag) {
339
+ this.bodyUp();
340
+ }
341
+
342
+ }
343
+
344
+
345
+ bodyDown(ev) {
346
+ const { target, button } = ev;
347
+
348
+ if (!this.preventActiveBehavior) {
349
+ this.active = true;
350
+ }
351
+
352
+ if (button && button !== 0) {
353
+ return;
354
+ }
355
+
356
+ this.$emit('clicked', ev);
357
+
358
+ if (!this.active) {
359
+ return;
360
+ }
361
+
362
+ if (this.dragHandle && target.getAttribute('data-drag-handle') !== this._uid.toString()) {
363
+ return;
364
+ }
365
+
366
+ if (this.dragCancel && target.getAttribute('data-drag-cancel') === this._uid.toString()) {
367
+ return;
368
+ }
369
+
370
+ if (typeof ev.stopPropagation !== 'undefined') {
371
+ ev.stopPropagation();
372
+ }
373
+
374
+ if (typeof ev.preventDefault !== 'undefined') {
375
+ ev.preventDefault();
376
+ }
377
+
378
+ if (this.isDraggable) {
379
+ this.bodyDrag = true;
380
+ }
381
+
382
+ const pointerX = typeof ev.pageX !== 'undefined' ? ev.pageX : ev.touches[0].pageX;
383
+ const pointerY = typeof ev.pageY !== 'undefined' ? ev.pageY : ev.touches[0].pageY;
384
+
385
+ this.saveDimensionsBeforeMove({ pointerX, pointerY });
386
+
387
+ if (this.parentLimitation) {
388
+ this.limits = this.calcDragLimitation();
389
+ }
390
+ }
391
+
392
+ bodyMove(delta) {
393
+ const { dimensionsBeforeMove, parentWidth, parentHeight, gridX, gridY, width, height } = this;
394
+
395
+ let newTop = dimensionsBeforeMove.top - delta.y;
396
+ let newBottom = dimensionsBeforeMove.bottom + delta.y;
397
+ let newLeft = dimensionsBeforeMove.left - delta.x;
398
+ let newRight = dimensionsBeforeMove.right + delta.x;
399
+
400
+ if (this.snapToGrid) {
401
+ let alignTop = true;
402
+ let alignLeft = true;
403
+
404
+ let diffT = newTop - Math.floor(newTop / gridY) * gridY;
405
+ let diffB = (parentHeight - newBottom) - Math.floor((parentHeight - newBottom) / gridY) * gridY;
406
+ let diffL = newLeft - Math.floor(newLeft / gridX) * gridX;
407
+ let diffR = (parentWidth - newRight) - Math.floor((parentWidth - newRight) / gridX) * gridX;
408
+
409
+ if (diffT > (gridY / 2)) {
410
+ diffT -= gridY;
411
+ }
412
+ if (diffB > (gridY / 2)) {
413
+ diffB -= gridY;
414
+ }
415
+ if (diffL > (gridX / 2)) {
416
+ diffL -= gridX;
417
+ }
418
+ if (diffR > (gridX / 2)) {
419
+ diffR -= gridX;
420
+ }
421
+
422
+ if (Math.abs(diffB) < Math.abs(diffT)) {
423
+ alignTop = false;
424
+ }
425
+ if (Math.abs(diffR) < Math.abs(diffL)) {
426
+ alignLeft = false;
427
+ }
428
+
429
+ newTop -= (alignTop ? diffT : diffB);
430
+ newBottom = parentHeight - height - newTop;
431
+ newLeft -= (alignLeft ? diffL : diffR);
432
+ newRight = parentWidth - width - newLeft;
433
+ }
434
+
435
+ ({
436
+ newLeft: this.left,
437
+ newRight: this.right,
438
+ newTop: this.top,
439
+ newBottom: this.bottom,
440
+ } = this.rectCorrectionByLimit({ newLeft, newRight, newTop, newBottom }));
441
+
442
+ console.log("宽高异常", this.rect);
443
+
444
+ this.$emit('dragging', this.rect);
445
+
446
+ this.storageElementInfo();
447
+ }
448
+
449
+ bodyUp() {
450
+ this.bodyDrag = false;
451
+ this.$emit('dragging', this.rect);
452
+ this.$emit('dragstop', this.rect);
453
+
454
+ this.dimensionsBeforeMove = { pointerX: 0, pointerY: 0, x: 0, y: 0, w: 0, h: 0 };
455
+
456
+ this.limits = {
457
+ left: { min: null, max: null },
458
+ right: { min: null, max: null },
459
+ top: { min: null, max: null },
460
+ bottom: { min: null, max: null },
461
+ };
462
+ }
463
+
464
+ stickDown(stick, ev, force = false) {
465
+ if ((!this.isResizable || !this.active) && !force) {
466
+ return;
467
+ }
468
+
469
+ this.stickDrag = true;
470
+
471
+ const pointerX = typeof ev.pageX !== 'undefined' ? ev.pageX : ev.touches[0].pageX;
472
+ const pointerY = typeof ev.pageY !== 'undefined' ? ev.pageY : ev.touches[0].pageY;
473
+
474
+ this.saveDimensionsBeforeMove({ pointerX, pointerY });
475
+
476
+ this.currentStick = stick;
477
+
478
+ this.limits = this.calcResizeLimits();
479
+ }
480
+
481
+ saveDimensionsBeforeMove({ pointerX, pointerY }) {
482
+ this.dimensionsBeforeMove.pointerX = pointerX;
483
+ this.dimensionsBeforeMove.pointerY = pointerY;
484
+
485
+ this.dimensionsBeforeMove.left = this.left;
486
+ this.dimensionsBeforeMove.right = this.right;
487
+ this.dimensionsBeforeMove.top = this.top;
488
+ this.dimensionsBeforeMove.bottom = this.bottom;
489
+
490
+ this.dimensionsBeforeMove.width = this.width;
491
+ this.dimensionsBeforeMove.height = this.height;
492
+
493
+ this.aspectFactor = this.width / this.height;
494
+ }
495
+
496
+ stickMove(delta) {
497
+ const {
498
+ currentStick,
499
+ dimensionsBeforeMove,
500
+ gridY,
501
+ gridX,
502
+ snapToGrid,
503
+ parentHeight,
504
+ parentWidth,
505
+ } = this;
506
+
507
+ let newTop = dimensionsBeforeMove.top;
508
+ let newBottom = dimensionsBeforeMove.bottom;
509
+ let newLeft = dimensionsBeforeMove.left;
510
+ let newRight = dimensionsBeforeMove.right;
511
+ switch (currentStick[0]) {
512
+ case 'b':
513
+ newBottom = dimensionsBeforeMove.bottom + delta.y;
514
+
515
+ if (snapToGrid) {
516
+ newBottom = parentHeight - Math.round((parentHeight - newBottom) / gridY) * gridY;
517
+ }
518
+
519
+ break;
520
+
521
+ case 't':
522
+ newTop = dimensionsBeforeMove.top - delta.y;
523
+
524
+ if (snapToGrid) {
525
+ newTop = Math.round(newTop / gridY) * gridY;
526
+ }
527
+
528
+ break;
529
+ default:
530
+ break;
531
+ }
532
+
533
+ switch (currentStick[1]) {
534
+ case 'r':
535
+ newRight = dimensionsBeforeMove.right + delta.x;
536
+
537
+ if (snapToGrid) {
538
+ newRight = parentWidth - Math.round((parentWidth - newRight) / gridX) * gridX;
539
+ }
540
+
541
+ break;
542
+
543
+ case 'l':
544
+ newLeft = dimensionsBeforeMove.left - delta.x;
545
+
546
+ if (snapToGrid) {
547
+ newLeft = Math.round(newLeft / gridX) * gridX;
548
+ }
549
+
550
+ break;
551
+ default:
552
+ break;
553
+ }
554
+
555
+ ({
556
+ newLeft,
557
+ newRight,
558
+ newTop,
559
+ newBottom,
560
+ } = this.rectCorrectionByLimit({ newLeft, newRight, newTop, newBottom }));
561
+
562
+ if (this.aspectRatio) {
563
+ ({
564
+ newLeft,
565
+ newRight,
566
+ newTop,
567
+ newBottom,
568
+ } = this.rectCorrectionByAspectRatio({ newLeft, newRight, newTop, newBottom }));
569
+ }
570
+
571
+ this.left = newLeft;
572
+ this.right = newRight;
573
+ this.top = newTop;
574
+ this.bottom = newBottom;
575
+
576
+ this.$emit('resizing', this.rect);
577
+
578
+ this.storageElementInfo()
579
+ }
580
+
581
+ stickUp() {
582
+ this.stickDrag = false;
583
+ this.dimensionsBeforeMove = {
584
+ pointerX: 0,
585
+ pointerY: 0,
586
+ x: 0,
587
+ y: 0,
588
+ w: 0,
589
+ h: 0,
590
+ };
591
+ this.limits = {
592
+ left: { min: null, max: null },
593
+ right: { min: null, max: null },
594
+ top: { min: null, max: null },
595
+ bottom: { min: null, max: null },
596
+ };
597
+
598
+ this.$emit('resizing', this.rect);
599
+ this.$emit('resizestop', this.rect);
600
+ }
601
+
602
+ calcDragLimitation() {
603
+ const { parentWidth, parentHeight } = this;
604
+
605
+ return {
606
+ left: { min: 0, max: parentWidth - this.width },
607
+ right: { min: 0, max: parentWidth - this.width },
608
+ top: { min: 0, max: parentHeight - this.height },
609
+ bottom: { min: 0, max: parentHeight - this.height },
610
+ };
611
+ }
612
+
613
+ calcResizeLimits() {
614
+ const { aspectFactor, width, height, bottom, top, left, right } = this;
615
+ let { minh: minHeight, minw: minWidth } = this;
616
+
617
+ const parentLim = this.parentLimitation ? 0 : null;
618
+
619
+ if (this.aspectRatio) {
620
+ if (minWidth / minHeight > aspectFactor) {
621
+ minHeight = minWidth / aspectFactor;
622
+ } else {
623
+ minWidth = aspectFactor * minHeight;
624
+ }
625
+ }
626
+
627
+ const limits = {
628
+ left: { min: parentLim, max: left + (width - minWidth) },
629
+ right: { min: parentLim, max: right + (width - minWidth) },
630
+ top: { min: parentLim, max: top + (height - minHeight) },
631
+ bottom: { min: parentLim, max: bottom + (height - minHeight) },
632
+ };
633
+
634
+ if (this.aspectRatio) {
635
+ const aspectLimits = {
636
+ left: {
637
+ min: left - (Math.min(top, bottom) * aspectFactor) * 2,
638
+ max: left + ((((height - minHeight) / 2) * aspectFactor) * 2),
639
+ },
640
+ right: {
641
+ min: right - (Math.min(top, bottom) * aspectFactor) * 2,
642
+ max: right + ((((height - minHeight) / 2) * aspectFactor) * 2),
643
+ },
644
+ top: {
645
+ min: top - (Math.min(left, right) / aspectFactor) * 2,
646
+ max: top + ((((width - minWidth) / 2) / aspectFactor) * 2),
647
+ },
648
+ bottom: {
649
+ min: bottom - (Math.min(left, right) / aspectFactor) * 2,
650
+ max: bottom + ((((width - minWidth) / 2) / aspectFactor) * 2),
651
+ },
652
+ };
653
+
654
+ if (this.currentStick[0] === 'm') {
655
+ limits.left = {
656
+ min: Math.max(limits.left.min as number, aspectLimits.left.min),
657
+ max: Math.min(limits.left.max, aspectLimits.left.max),
658
+ };
659
+ limits.right = {
660
+ min: Math.max(limits.right.min as number, aspectLimits.right.min),
661
+ max: Math.min(limits.right.max, aspectLimits.right.max),
662
+ };
663
+
664
+ } else if (this.currentStick[1] === 'm') {
665
+ limits.top = {
666
+ min: Math.max(limits.top.min as number, aspectLimits.top.min),
667
+ max: Math.min(limits.top.max, aspectLimits.top.max),
668
+ };
669
+ limits.bottom = {
670
+ min: Math.max(limits.bottom.min as number, aspectLimits.bottom.min),
671
+ max: Math.min(limits.bottom.max, aspectLimits.bottom.max),
672
+ };
673
+ }
674
+ }
675
+
676
+ return limits;
677
+ }
678
+
679
+ sideCorrectionByLimit(limit, current) {
680
+ let value = current;
681
+
682
+ if (limit.min !== null && current < limit.min) {
683
+ value = limit.min;
684
+ } else if (limit.max !== null && limit.max < current) {
685
+ value = limit.max;
686
+ }
687
+
688
+ return value;
689
+ }
690
+
691
+ rectCorrectionByLimit(rect) {
692
+ const { limits } = this;
693
+ let { newRight, newLeft, newBottom, newTop } = rect;
694
+
695
+ newLeft = this.sideCorrectionByLimit(limits.left, newLeft);
696
+ newRight = this.sideCorrectionByLimit(limits.right, newRight);
697
+ newTop = this.sideCorrectionByLimit(limits.top, newTop);
698
+ newBottom = this.sideCorrectionByLimit(limits.bottom, newBottom);
699
+
700
+ return {
701
+ newLeft,
702
+ newRight,
703
+ newTop,
704
+ newBottom,
705
+ };
706
+ }
707
+
708
+ rectCorrectionByAspectRatio(rect) {
709
+ let { newLeft, newRight, newTop, newBottom } = rect;
710
+ const { parentWidth, parentHeight, currentStick, aspectFactor, dimensionsBeforeMove } = this;
711
+
712
+ let newWidth = parentWidth - newLeft - newRight;
713
+ let newHeight = parentHeight - newTop - newBottom;
714
+
715
+ if (currentStick[1] === 'm') {
716
+ const deltaHeight = newHeight - dimensionsBeforeMove.height;
717
+
718
+ newLeft -= (deltaHeight * aspectFactor) / 2;
719
+ newRight -= (deltaHeight * aspectFactor) / 2;
720
+ } else if (currentStick[0] === 'm') {
721
+ const deltaWidth = newWidth - dimensionsBeforeMove.width;
722
+
723
+ newTop -= (deltaWidth / aspectFactor) / 2;
724
+ newBottom -= (deltaWidth / aspectFactor) / 2;
725
+ } else if (newWidth / newHeight > aspectFactor) {
726
+ newWidth = aspectFactor * newHeight;
727
+
728
+ if (currentStick[1] === 'l') {
729
+ newLeft = parentWidth - newRight - newWidth;
730
+ } else {
731
+ newRight = parentWidth - newLeft - newWidth;
732
+ }
733
+ } else {
734
+ newHeight = newWidth / aspectFactor;
735
+
736
+ if (currentStick[0] === 't') {
737
+ newTop = parentHeight - newBottom - newHeight;
738
+ } else {
739
+ newBottom = parentHeight - newTop - newHeight;
740
+ }
741
+ }
742
+
743
+ return { newLeft, newRight, newTop, newBottom };
744
+ }
745
+
746
+ storageElementInfo() {
747
+
748
+ if (!this.isStorage)
749
+ return
750
+
751
+ if (this.name.trim() === "") {
752
+ throw "unspecified name"
753
+ }
754
+
755
+ const info = { "left": this.rect.left, "top": this.rect.top, "right": this.right, "bottom": this.bottom }
756
+ localStorage.setItem("DragResizeView_Info_" + this.name, JSON.stringify(info))
757
+ }
758
+
759
+ get positionStyle() {
760
+ console.log("绑定");
761
+
762
+ return {
763
+ top: this.top + 'px',
764
+ left: this.left + 'px',
765
+ zIndex: this.zIndex,
766
+ };
767
+ }
768
+
769
+ get sizeStyle() {
770
+ return {
771
+ width: this.w == 'auto' ? 'auto' : this.width + 'px',
772
+ height: this.h == 'auto' ? 'auto' : this.height + 'px'
773
+ };
774
+ }
775
+
776
+
777
+ get vdrStick() {
778
+ return (stick) => {
779
+ const stickStyle = {
780
+ width: `${this.stickSize / this.parentScaleX}px`,
781
+ height: `${this.stickSize / this.parentScaleY}px`,
782
+ };
783
+ stickStyle[styleMapping.y[stick[0]]] = `${this.stickSize / this.parentScaleX / -2}px`;
784
+ stickStyle[styleMapping.x[stick[1]]] = `${this.stickSize / this.parentScaleX / -2}px`;
785
+ return stickStyle;
786
+ };
787
+ }
788
+
789
+ get width() {
790
+ console.log("宽高获取1A", this);
791
+ console.log("宽高获取1", this.parentWidth);
792
+ console.log("宽高获取2", this.left);
793
+ console.log("宽高获取3", this.right);
794
+
795
+ return this.parentWidth - this.left - this.right;
796
+ }
797
+
798
+ get height() {
799
+ return this.parentHeight - this.top - this.bottom;
800
+ }
801
+
802
+ get rect() {
803
+ return {
804
+ left: Math.round(this.left),
805
+ top: Math.round(this.top),
806
+ width: Math.round(this.width),
807
+ height: Math.round(this.height),
808
+ };
809
+ }
810
+
811
+ @Watch('isActive', { immediate: false, deep: false })
812
+ onActive(isActive) {
813
+ if (isActive) {
814
+ this.$emit('activated');
815
+ } else {
816
+ this.$emit('deactivated');
817
+ }
818
+ }
819
+
820
+ @Watch('isActive', { immediate: true, deep: false })
821
+ onIsActive(val) {
822
+ this.active = val;
823
+ }
824
+
825
+ @Watch('z', { immediate: true, deep: false })
826
+ onZ(val) {
827
+ if (val >= 0 || val === 'auto') {
828
+ this.zIndex = val;
829
+ }
830
+ }
831
+
832
+ @Watch('x', { immediate: false, deep: false })
833
+ onX(newVal, oldVal) {
834
+ if (this.stickDrag || this.bodyDrag || (newVal === this.left)) {
835
+ return;
836
+ }
837
+
838
+ const delta = oldVal - newVal;
839
+
840
+ this.bodyDown({ pageX: this.left, pageY: this.top });
841
+ this.bodyMove({ x: delta, y: 0 });
842
+
843
+ this.$nextTick(() => {
844
+ this.bodyUp();
845
+ });
846
+ }
847
+
848
+ @Watch('y', { immediate: false, deep: false })
849
+ onY(newVal, oldVal) {
850
+ if (this.stickDrag || this.bodyDrag || (newVal === this.top)) {
851
+ return;
852
+ }
853
+
854
+ const delta = oldVal - newVal;
855
+
856
+ this.bodyDown({ pageX: this.left, pageY: this.top });
857
+ this.bodyMove({ x: 0, y: delta });
858
+
859
+ this.$nextTick(() => {
860
+ this.bodyUp();
861
+ });
862
+ }
863
+
864
+ @Watch('w', { immediate: false, deep: false })
865
+ onW(newVal, oldVal) {
866
+ if (this.stickDrag || this.bodyDrag || (newVal === this.width)) {
867
+ return;
868
+ }
869
+
870
+ const stick = 'mr';
871
+ const delta = oldVal - newVal;
872
+
873
+ this.stickDown(stick, { pageX: this.right, pageY: this.top + (this.height / 2) }, true);
874
+ this.stickMove({ x: delta, y: 0 });
875
+
876
+ this.$nextTick(() => {
877
+ this.stickUp();
878
+ });
879
+ }
880
+
881
+ @Watch('h', { immediate: false, deep: false })
882
+ onH(newVal, oldVal) {
883
+ if (this.stickDrag || this.bodyDrag || (newVal === this.height)) {
884
+ return;
885
+ }
886
+
887
+ const stick = 'bm';
888
+ const delta = oldVal - newVal;
889
+
890
+ this.stickDown(stick, { pageX: this.left + (this.width / 2), pageY: this.bottom }, true);
891
+ this.stickMove({ x: 0, y: delta });
892
+
893
+ this.$nextTick(() => {
894
+ this.stickUp();
895
+ });
896
+ }
897
+
898
+ @Watch('parentW', { immediate: false, deep: false })
899
+ onParentW(val) {
900
+ this.right = val - this.width - this.left;
901
+ this.parentWidth = val;
902
+ }
903
+
904
+
905
+ @Watch('parentH', { immediate: false, deep: false })
906
+ onParentH(val) {
907
+ this.bottom = val - this.height - this.top;
908
+ this.parentHeight = val;
909
+ }
910
+
911
+ }
912
+
913
+ </script>
914
+
915
+ <style lang="less" scoped>
916
+ @import "index.less";
917
+ </style>