fl-web-component 2.1.1-beta.0 → 2.1.1-beta.10
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.
- package/dist/fl-web-component.common.js +1301 -826
- package/dist/fl-web-component.common.js.map +1 -1
- package/dist/fl-web-component.css +1 -1
- package/package.json +1 -1
- package/packages/components/com-flcanvas/components/entityFormatting.js +19 -14
- package/packages/components/com-flcanvas/index.vue +350 -302
- package/packages/components/com-graphics/index.vue +559 -80
- package/src/utils/instance-parser.js +5 -0
|
@@ -35,11 +35,17 @@ function downloadPDF(base64, fileName) {
|
|
|
35
35
|
URL.revokeObjectURL(url); // 释放URL对象
|
|
36
36
|
}
|
|
37
37
|
import Konva from 'konva';
|
|
38
|
-
import { Vector2 } from
|
|
38
|
+
import { Vector2 } from 'three';
|
|
39
39
|
import DxfParser from 'dxf-parser';
|
|
40
40
|
import DxfParser2 from '@/utils/dxf-parser/DxfParser';
|
|
41
41
|
import jsPDF from 'jspdf';
|
|
42
|
-
import {
|
|
42
|
+
import {
|
|
43
|
+
formatEntity,
|
|
44
|
+
handleFn,
|
|
45
|
+
centering,
|
|
46
|
+
_GenerateArcVertices,
|
|
47
|
+
_GenerateBulgeVertices,
|
|
48
|
+
} from './components/entityFormatting';
|
|
43
49
|
export default {
|
|
44
50
|
name: 'Fl2dcanvas',
|
|
45
51
|
components: {},
|
|
@@ -72,8 +78,8 @@ export default {
|
|
|
72
78
|
this.konvaStage._resizeDOM();
|
|
73
79
|
}
|
|
74
80
|
});
|
|
75
|
-
|
|
76
81
|
this.$nextTick(() => {
|
|
82
|
+
console.log(this.$refs.svgDraw.clientHeight)
|
|
77
83
|
this.konvaStage = new Konva.Stage({
|
|
78
84
|
className: 'stage',
|
|
79
85
|
container: 'konva-container',
|
|
@@ -94,7 +100,6 @@ export default {
|
|
|
94
100
|
var scaleBy = 1.1;
|
|
95
101
|
//初始化缩放方法
|
|
96
102
|
this.konvaStage.on('wheel', e => {
|
|
97
|
-
console.log(e);
|
|
98
103
|
e.evt.preventDefault();
|
|
99
104
|
var oldScale = this.konvaStage.scaleX();
|
|
100
105
|
var pointer = this.konvaStage.getPointerPosition();
|
|
@@ -156,27 +161,42 @@ export default {
|
|
|
156
161
|
|
|
157
162
|
*/
|
|
158
163
|
|
|
159
|
-
const { scale, x, y } = this.calculateScaleAndPosition(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
);
|
|
164
|
+
// const { scale, x, y } = this.calculateScaleAndPosition(
|
|
165
|
+
// this.bounds,
|
|
166
|
+
// this.konvaStage.width(),
|
|
167
|
+
// this.konvaStage.height(),
|
|
168
|
+
// 0.05 // 5% 边距
|
|
169
|
+
// );
|
|
165
170
|
|
|
166
|
-
this.konvaStage.position({ x: x, y: y });
|
|
167
|
-
this.konvaStage.scale({ x: scale, y: scale });
|
|
171
|
+
// this.konvaStage.position({ x: x, y: y });
|
|
172
|
+
// this.konvaStage.scale({ x: scale, y: scale });
|
|
168
173
|
|
|
169
|
-
this.konvaStage.batchDraw();
|
|
174
|
+
// this.konvaStage.batchDraw();
|
|
175
|
+
this.centerDraw();
|
|
170
176
|
});
|
|
171
177
|
this.konvaStage.on('click', e => {
|
|
172
178
|
let target = this.konvaStage.mouseClickEndShape;
|
|
173
|
-
this.$emit('leftClick', target ? target.attrs : null)
|
|
179
|
+
this.$emit('leftClick', target ? target.attrs : null);
|
|
174
180
|
});
|
|
175
181
|
});
|
|
176
182
|
},
|
|
177
183
|
//销毁方法
|
|
178
184
|
|
|
179
185
|
methods: {
|
|
186
|
+
// 图纸居中展示
|
|
187
|
+
centerDraw() {
|
|
188
|
+
const { scale, x, y } = this.calculateScaleAndPosition(
|
|
189
|
+
this.bounds,
|
|
190
|
+
this.konvaStage.width(),
|
|
191
|
+
this.konvaStage.height(),
|
|
192
|
+
0.05 // 5% 边距
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
this.konvaStage.position({ x: x, y: y });
|
|
196
|
+
this.konvaStage.scale({ x: scale, y: scale });
|
|
197
|
+
|
|
198
|
+
this.konvaStage.batchDraw();
|
|
199
|
+
},
|
|
180
200
|
calculateScaleAndPosition(contentBounds, stageWidth, stageHeight, padding = 0.1) {
|
|
181
201
|
// 1. 计算内容的实际宽高
|
|
182
202
|
const contentWidth = contentBounds.maxX - contentBounds.minX;
|
|
@@ -219,7 +239,6 @@ export default {
|
|
|
219
239
|
|
|
220
240
|
return { scale, x, y };
|
|
221
241
|
},
|
|
222
|
-
|
|
223
242
|
updateBounds(v) {
|
|
224
243
|
if (this.bounds === null) {
|
|
225
244
|
this.bounds = { minX: v.x, maxX: v.x, minY: v.y, maxY: v.y };
|
|
@@ -262,7 +281,7 @@ export default {
|
|
|
262
281
|
nodes[i].destroy();
|
|
263
282
|
}
|
|
264
283
|
}*/
|
|
265
|
-
|
|
284
|
+
this.bounds = null;
|
|
266
285
|
this.konvaLayer.destroyChildren();
|
|
267
286
|
const parser = new DxfParser();
|
|
268
287
|
let dxf = parser.parse(data);
|
|
@@ -274,14 +293,11 @@ export default {
|
|
|
274
293
|
for (let i = 0; i < hatchEntitys.length; i++) {
|
|
275
294
|
let entity = hatchEntitys[i];
|
|
276
295
|
let layerConfig = this.recordLayerConfig[entity.layer];
|
|
277
|
-
let configParams =
|
|
278
|
-
|
|
279
|
-
? layerConfig
|
|
280
|
-
: null;
|
|
281
|
-
let color = configParams ? configParams.color : "#000";
|
|
296
|
+
let configParams = layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
297
|
+
let color = configParams ? configParams.color : '#000';
|
|
282
298
|
let visible = configParams ? configParams.visible : true;
|
|
283
|
-
let name = entity.layer.replace(/\s*/g,
|
|
284
|
-
if (entity.type ==
|
|
299
|
+
let name = entity.layer.replace(/\s*/g, '');
|
|
300
|
+
if (entity.type == 'HATCH') {
|
|
285
301
|
let boundaryLoops = entity.boundaryLoops;
|
|
286
302
|
for (let j = 0; j < boundaryLoops.length; j++) {
|
|
287
303
|
let list = [];
|
|
@@ -298,10 +314,7 @@ export default {
|
|
|
298
314
|
);
|
|
299
315
|
const axisRatio = entity.radius;
|
|
300
316
|
const yR = xR * axisRatio;
|
|
301
|
-
const rotation = Math.atan2(
|
|
302
|
-
majorAxisEndPoint.y,
|
|
303
|
-
majorAxisEndPoint.x
|
|
304
|
-
);
|
|
317
|
+
const rotation = Math.atan2(majorAxisEndPoint.y, majorAxisEndPoint.x);
|
|
305
318
|
|
|
306
319
|
const arcVertices = _GenerateArcVertices({
|
|
307
320
|
vertices: [],
|
|
@@ -330,10 +343,8 @@ export default {
|
|
|
330
343
|
list.push(arcVertices[i].x);
|
|
331
344
|
list.push(-parseFloat(arcVertices[i].y));
|
|
332
345
|
}
|
|
333
|
-
|
|
334
346
|
}
|
|
335
347
|
if (entity.type == 1) {
|
|
336
|
-
|
|
337
348
|
list.push(entity.start.x);
|
|
338
349
|
list.push(-parseFloat(entity.start.y));
|
|
339
350
|
list.push(entity.end.x);
|
|
@@ -350,7 +361,7 @@ export default {
|
|
|
350
361
|
stroke: color,
|
|
351
362
|
customColor: color,
|
|
352
363
|
visible: visible,
|
|
353
|
-
shapeType: 'hatch'
|
|
364
|
+
shapeType: 'hatch',
|
|
354
365
|
});
|
|
355
366
|
this.konvaLayer.add(line);
|
|
356
367
|
}
|
|
@@ -359,20 +370,14 @@ export default {
|
|
|
359
370
|
let loop = boundaryLoops[0];
|
|
360
371
|
if (loop.type == 7) {
|
|
361
372
|
let vertices = [];
|
|
362
|
-
for (
|
|
363
|
-
let vtxIdx = 0;
|
|
364
|
-
vtxIdx < loop.polyline.vertices.length;
|
|
365
|
-
vtxIdx++
|
|
366
|
-
) {
|
|
373
|
+
for (let vtxIdx = 0; vtxIdx < loop.polyline.vertices.length; vtxIdx++) {
|
|
367
374
|
const vtx = loop.polyline.vertices[vtxIdx];
|
|
368
375
|
if ((vtx.bulge ?? 0) == 0) {
|
|
369
376
|
vertices.push(new Vector2(vtx.x, vtx.y));
|
|
370
377
|
} else {
|
|
371
378
|
const prevVtx =
|
|
372
379
|
loop.polyline.vertices[
|
|
373
|
-
vtxIdx == 0
|
|
374
|
-
? loop.polyline.vertices.length - 1
|
|
375
|
-
: vtxIdx - 1
|
|
380
|
+
vtxIdx == 0 ? loop.polyline.vertices.length - 1 : vtxIdx - 1
|
|
376
381
|
];
|
|
377
382
|
if ((prevVtx.bulge ?? 0) == 0) {
|
|
378
383
|
/* Start vertex is not produced by _GenerateBulgeVertices(). */
|
|
@@ -380,16 +385,9 @@ export default {
|
|
|
380
385
|
}
|
|
381
386
|
const nextVtx =
|
|
382
387
|
loop.polyline.vertices[
|
|
383
|
-
vtxIdx == loop.polyline.vertices.length - 1
|
|
384
|
-
? 0
|
|
385
|
-
: vtxIdx + 1
|
|
388
|
+
vtxIdx == loop.polyline.vertices.length - 1 ? 0 : vtxIdx + 1
|
|
386
389
|
];
|
|
387
|
-
vertices = _GenerateBulgeVertices(
|
|
388
|
-
[],
|
|
389
|
-
vtx,
|
|
390
|
-
nextVtx,
|
|
391
|
-
vtx.bulge
|
|
392
|
-
);
|
|
390
|
+
vertices = _GenerateBulgeVertices([], vtx, nextVtx, vtx.bulge);
|
|
393
391
|
}
|
|
394
392
|
}
|
|
395
393
|
let list = [];
|
|
@@ -408,7 +406,7 @@ export default {
|
|
|
408
406
|
stroke: color,
|
|
409
407
|
customColor: color,
|
|
410
408
|
visible: visible,
|
|
411
|
-
shapeType: 'hatch'
|
|
409
|
+
shapeType: 'hatch',
|
|
412
410
|
});
|
|
413
411
|
this.konvaLayer.add(line);
|
|
414
412
|
}
|
|
@@ -445,83 +443,85 @@ export default {
|
|
|
445
443
|
if (this.konvaLayer) this.konvaLayer.add(entity.obj);
|
|
446
444
|
}
|
|
447
445
|
}
|
|
446
|
+
if (group.length > 0) {
|
|
447
|
+
if (group[0]?.stroke) {
|
|
448
|
+
group[0].stroke = '#000';
|
|
449
|
+
}
|
|
450
|
+
let customShape = new Konva.Shape({
|
|
451
|
+
x: 0,
|
|
452
|
+
y: 0,
|
|
453
|
+
strokeWidth: 0.2,
|
|
454
|
+
name: key.replace(/\s*/g, ''),
|
|
455
|
+
entityId: key,
|
|
456
|
+
stroke: group[0].stroke,
|
|
457
|
+
customColor: configParams ? configParams.color : group[0].stroke,
|
|
458
|
+
//visible: configParams ? configParams.visible :true,
|
|
459
|
+
sceneFunc(context, shape) {
|
|
460
|
+
context.beginPath();
|
|
461
|
+
for (let i = 0; i < group.length; i++) {
|
|
462
|
+
let entity = group[i];
|
|
448
463
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
if (entity.type === 'line') {
|
|
468
|
-
context.strokeStyle = entity.stroke;
|
|
469
|
-
let x1 = entity.x1;
|
|
470
|
-
let y1 = entity.y1;
|
|
471
|
-
let x2 = entity.x2;
|
|
472
|
-
let y2 = entity.y2;
|
|
473
|
-
if (x1 != undefined && y1 != undefined && x2 != undefined && y2 != undefined) {
|
|
474
|
-
context.moveTo(x1, -parseFloat(y1));
|
|
475
|
-
context.lineTo(x2, -parseFloat(y2));
|
|
464
|
+
if (entity.type === 'line') {
|
|
465
|
+
context.strokeStyle = entity.stroke;
|
|
466
|
+
let x1 = entity.x1;
|
|
467
|
+
let y1 = entity.y1;
|
|
468
|
+
let x2 = entity.x2;
|
|
469
|
+
let y2 = entity.y2;
|
|
470
|
+
if (x1 != undefined && y1 != undefined && x2 != undefined && y2 != undefined) {
|
|
471
|
+
context.moveTo(x1, -parseFloat(y1));
|
|
472
|
+
context.lineTo(x2, -parseFloat(y2));
|
|
473
|
+
}
|
|
474
|
+
let v1 = {};
|
|
475
|
+
v1.x = x1;
|
|
476
|
+
v1.y = y1;
|
|
477
|
+
let v2 = {};
|
|
478
|
+
v2.x = x2;
|
|
479
|
+
v2.y = y2;
|
|
480
|
+
_this.updateBounds(v1);
|
|
481
|
+
_this.updateBounds(v2);
|
|
476
482
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
v1.y = y1;
|
|
480
|
-
let v2 = {};
|
|
481
|
-
v2.x = x2;
|
|
482
|
-
v2.y = y2;
|
|
483
|
-
_this.updateBounds(v1);
|
|
484
|
-
_this.updateBounds(v2);
|
|
485
|
-
}
|
|
486
|
-
if (entity.type === 'polyline') {
|
|
487
|
-
context.strokeStyle = entity.stroke;
|
|
483
|
+
if (entity.type === 'polyline') {
|
|
484
|
+
context.strokeStyle = entity.stroke;
|
|
488
485
|
|
|
489
|
-
|
|
486
|
+
let flag = false;
|
|
490
487
|
|
|
491
|
-
|
|
488
|
+
let points = entity.points;
|
|
492
489
|
|
|
493
|
-
|
|
490
|
+
let closed = entity.closed;
|
|
494
491
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
492
|
+
for (let j = 0; j < points.length; j++) {
|
|
493
|
+
let index = j % 2;
|
|
494
|
+
if (index === 0) {
|
|
495
|
+
let x = points[j];
|
|
496
|
+
let y = points[j + 1];
|
|
497
|
+
let point = {};
|
|
498
|
+
point.x = x;
|
|
499
|
+
point.y = y;
|
|
500
|
+
_this.updateBounds(point);
|
|
504
501
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
502
|
+
if (j === 0) {
|
|
503
|
+
context.moveTo(x, y);
|
|
504
|
+
} else {
|
|
505
|
+
context.lineTo(x, y);
|
|
506
|
+
}
|
|
509
507
|
}
|
|
510
|
-
}
|
|
511
508
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
509
|
+
if (closed) {
|
|
510
|
+
if (j === points.length - 1) {
|
|
511
|
+
context.lineTo(points[0], points[1]);
|
|
512
|
+
}
|
|
515
513
|
}
|
|
516
514
|
}
|
|
517
515
|
}
|
|
518
516
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
517
|
+
// context.closePath();
|
|
518
|
+
context.fillStrokeShape(shape);
|
|
519
|
+
},
|
|
520
|
+
shapeType: 'shape',
|
|
521
|
+
});
|
|
522
|
+
if (this.konvaLayer) this.konvaLayer.add(customShape);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
525
|
}
|
|
526
526
|
}
|
|
527
527
|
//缩放视口
|
|
@@ -545,18 +545,19 @@ export default {
|
|
|
545
545
|
this.$refs.svgDraw.clientHeight / 2 -
|
|
546
546
|
(Math.ceil(boundingScale.height) / 2 + boundingScale.y);
|
|
547
547
|
|
|
548
|
-
this.konvaStage.scale({
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
});
|
|
552
|
-
this.konvaStage.setX(0);
|
|
553
|
-
this.konvaStage.setY(750); // 750
|
|
554
|
-
|
|
555
|
-
this.activedSvgPan.zoom.x = 0;
|
|
556
|
-
this.activedSvgPan.zoom.y = 750;
|
|
557
|
-
this.activedSvgPan.x = x;
|
|
558
|
-
this.activedSvgPan.y = x;
|
|
548
|
+
// this.konvaStage.scale({
|
|
549
|
+
// x: 2,
|
|
550
|
+
// y: 2,
|
|
551
|
+
// });
|
|
552
|
+
// this.konvaStage.setX(0);
|
|
553
|
+
// this.konvaStage.setY(750); // 750
|
|
554
|
+
|
|
555
|
+
// this.activedSvgPan.zoom.x = 0;
|
|
556
|
+
// this.activedSvgPan.zoom.y = 750;
|
|
557
|
+
// this.activedSvgPan.x = x;
|
|
558
|
+
// this.activedSvgPan.y = x;
|
|
559
559
|
setTimeout(() => {
|
|
560
|
+
this.centerDraw();
|
|
560
561
|
this.$emit('loaded');
|
|
561
562
|
}, 100);
|
|
562
563
|
},
|
|
@@ -598,143 +599,59 @@ export default {
|
|
|
598
599
|
},
|
|
599
600
|
toPdfs(list) {
|
|
600
601
|
let _this = this;
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
let
|
|
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
|
-
for (let i = 0; i < group.length; i++) {
|
|
636
|
-
let entity = group[i];
|
|
637
|
-
if (entity.type === 'line') {
|
|
638
|
-
let x1 = entity.x1;
|
|
639
|
-
let y1 = entity.y1;
|
|
640
|
-
let x2 = entity.x2;
|
|
641
|
-
let y2 = entity.y2;
|
|
642
|
-
let v1 = {};
|
|
643
|
-
v1.x = x1;
|
|
644
|
-
v1.y = y1;
|
|
645
|
-
let v2 = {};
|
|
646
|
-
v2.x = x2;
|
|
647
|
-
v2.y = y2;
|
|
648
|
-
_this.updateBounds1(v1);
|
|
649
|
-
_this.updateBounds1(v2);
|
|
650
|
-
}
|
|
651
|
-
if (entity.type === 'polyline') {
|
|
652
|
-
let flag = false;
|
|
653
|
-
let points = entity.points;
|
|
654
|
-
let closed = entity.closed;
|
|
655
|
-
|
|
656
|
-
for (let j = 0; j < points.length; j++) {
|
|
657
|
-
let index = j % 2;
|
|
658
|
-
if (index === 0) {
|
|
659
|
-
let x = points[j];
|
|
660
|
-
let y = points[j + 1];
|
|
661
|
-
let point = {};
|
|
662
|
-
point.x = x;
|
|
663
|
-
point.y = y;
|
|
664
|
-
_this.updateBounds1(point);
|
|
665
|
-
}
|
|
602
|
+
return new Promise((resolve, reject) => {
|
|
603
|
+
const pdf = new jsPDF('l', 'px', [this.konvaStage.width(), this.konvaStage.height()]);
|
|
604
|
+
const exportPixelRatio = 2; // 可以 2/3/4 自己调
|
|
605
|
+
let index = 0;
|
|
606
|
+
for (let pageIdx = 0; pageIdx < list.length; pageIdx++) {
|
|
607
|
+
let data = list[pageIdx];
|
|
608
|
+
//先绘制图面
|
|
609
|
+
this.konvaLayer.destroyChildren();
|
|
610
|
+
const parser = new DxfParser();
|
|
611
|
+
let dxf = parser.parse(data);
|
|
612
|
+
if (dxf.entities.length > 0) {
|
|
613
|
+
let entities = formatEntity(dxf.entities);
|
|
614
|
+
let layers = dxf.tables.layer.layers;
|
|
615
|
+
//先计算包围
|
|
616
|
+
for (let key in entities) {
|
|
617
|
+
if (entities[key]) {
|
|
618
|
+
let group = [];
|
|
619
|
+
let l = entities[key].length;
|
|
620
|
+
let layerConfig = this.recordLayerConfig[key];
|
|
621
|
+
let configParams =
|
|
622
|
+
layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
623
|
+
for (let i = 0; i < l; i++) {
|
|
624
|
+
let type = entities[key][i].type;
|
|
625
|
+
handleFn(
|
|
626
|
+
type,
|
|
627
|
+
dxf,
|
|
628
|
+
entities[key][i],
|
|
629
|
+
group,
|
|
630
|
+
key,
|
|
631
|
+
configParams,
|
|
632
|
+
this.konvaLayer,
|
|
633
|
+
this.recordLayerConfig
|
|
634
|
+
);
|
|
666
635
|
}
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
636
|
|
|
672
|
-
console.log('bounds1');
|
|
673
|
-
console.log(_this.bounds1);
|
|
674
|
-
|
|
675
|
-
for (let key in entities) {
|
|
676
|
-
if (entities[key]) {
|
|
677
|
-
let group = [];
|
|
678
|
-
let l = entities[key].length;
|
|
679
|
-
let layerConfig = this.recordLayerConfig[key];
|
|
680
|
-
let configParams =
|
|
681
|
-
layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
682
|
-
for (let i = 0; i < l; i++) {
|
|
683
|
-
let type = entities[key][i].type;
|
|
684
|
-
handleFn(
|
|
685
|
-
type,
|
|
686
|
-
dxf,
|
|
687
|
-
entities[key][i],
|
|
688
|
-
group,
|
|
689
|
-
key,
|
|
690
|
-
configParams,
|
|
691
|
-
this.konvaLayer,
|
|
692
|
-
this.recordLayerConfig
|
|
693
|
-
);
|
|
694
|
-
}
|
|
695
|
-
if (!this.konvaLayer) return;
|
|
696
|
-
for (let i = 0; i < group.length; i++) {
|
|
697
|
-
let entity = group[i];
|
|
698
|
-
if (entity.type === 'text') {
|
|
699
|
-
if (this.konvaLayer) this.konvaLayer.add(entity.obj);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
if (group[0].stroke == undefined) {
|
|
704
|
-
console.log(group);
|
|
705
|
-
group[0].stroke = '#000';
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
let customShape = new Konva.Shape({
|
|
709
|
-
x: 0,
|
|
710
|
-
y: 0,
|
|
711
|
-
strokeWidth: 0.2,
|
|
712
|
-
name: key.replace(/\s*/g, ''),
|
|
713
|
-
entityId: key,
|
|
714
|
-
stroke: group[0].stroke,
|
|
715
|
-
customColor: configParams ? configParams.color : '',
|
|
716
|
-
//visible: configParams ? configParams.visible :true,
|
|
717
|
-
sceneFunc(context, shape) {
|
|
718
|
-
context.beginPath();
|
|
719
637
|
for (let i = 0; i < group.length; i++) {
|
|
720
638
|
let entity = group[i];
|
|
721
|
-
|
|
722
639
|
if (entity.type === 'line') {
|
|
723
|
-
context.strokeStyle = entity.stroke;
|
|
724
640
|
let x1 = entity.x1;
|
|
725
641
|
let y1 = entity.y1;
|
|
726
642
|
let x2 = entity.x2;
|
|
727
643
|
let y2 = entity.y2;
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
}
|
|
644
|
+
let v1 = {};
|
|
645
|
+
v1.x = x1;
|
|
646
|
+
v1.y = y1;
|
|
647
|
+
let v2 = {};
|
|
648
|
+
v2.x = x2;
|
|
649
|
+
v2.y = y2;
|
|
650
|
+
_this.updateBounds1(v1);
|
|
651
|
+
_this.updateBounds1(v2);
|
|
732
652
|
}
|
|
733
653
|
if (entity.type === 'polyline') {
|
|
734
|
-
context.strokeStyle = entity.stroke;
|
|
735
|
-
|
|
736
654
|
let flag = false;
|
|
737
|
-
|
|
738
655
|
let points = entity.points;
|
|
739
656
|
let closed = entity.closed;
|
|
740
657
|
|
|
@@ -743,67 +660,159 @@ export default {
|
|
|
743
660
|
if (index === 0) {
|
|
744
661
|
let x = points[j];
|
|
745
662
|
let y = points[j + 1];
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
context.lineTo(x, y);
|
|
751
|
-
}
|
|
663
|
+
let point = {};
|
|
664
|
+
point.x = x;
|
|
665
|
+
point.y = y;
|
|
666
|
+
_this.updateBounds1(point);
|
|
752
667
|
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
753
673
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
674
|
+
for (let key in entities) {
|
|
675
|
+
if (entities[key]) {
|
|
676
|
+
let group = [];
|
|
677
|
+
let l = entities[key].length;
|
|
678
|
+
let layerConfig = this.recordLayerConfig[key];
|
|
679
|
+
let configParams =
|
|
680
|
+
layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
681
|
+
for (let i = 0; i < l; i++) {
|
|
682
|
+
let type = entities[key][i].type;
|
|
683
|
+
handleFn(
|
|
684
|
+
type,
|
|
685
|
+
dxf,
|
|
686
|
+
entities[key][i],
|
|
687
|
+
group,
|
|
688
|
+
key,
|
|
689
|
+
configParams,
|
|
690
|
+
this.konvaLayer,
|
|
691
|
+
this.recordLayerConfig
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
if (!this.konvaLayer) return;
|
|
695
|
+
for (let i = 0; i < group.length; i++) {
|
|
696
|
+
let entity = group[i];
|
|
697
|
+
if (entity.type === 'text') {
|
|
698
|
+
if (this.konvaLayer) this.konvaLayer.add(entity.obj);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
if (group.length > 0) {
|
|
703
|
+
if (group[0]?.stroke) {
|
|
704
|
+
group[0].stroke = '#000';
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
let customShape = new Konva.Shape({
|
|
708
|
+
x: 0,
|
|
709
|
+
y: 0,
|
|
710
|
+
strokeWidth: 0.2,
|
|
711
|
+
name: key.replace(/\s*/g, ''),
|
|
712
|
+
entityId: key,
|
|
713
|
+
stroke: group[0].stroke,
|
|
714
|
+
customColor: configParams ? configParams.color : '',
|
|
715
|
+
//visible: configParams ? configParams.visible :true,
|
|
716
|
+
sceneFunc(context, shape) {
|
|
717
|
+
context.beginPath();
|
|
718
|
+
for (let i = 0; i < group.length; i++) {
|
|
719
|
+
let entity = group[i];
|
|
720
|
+
|
|
721
|
+
if (entity.type === 'line') {
|
|
722
|
+
context.strokeStyle = entity.stroke;
|
|
723
|
+
let x1 = entity.x1;
|
|
724
|
+
let y1 = entity.y1;
|
|
725
|
+
let x2 = entity.x2;
|
|
726
|
+
let y2 = entity.y2;
|
|
727
|
+
if (x1 != undefined && y1 != undefined && x2 != undefined && y2 != undefined) {
|
|
728
|
+
context.moveTo(x1, -parseFloat(y1));
|
|
729
|
+
context.lineTo(x2, -parseFloat(y2));
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
if (entity.type === 'polyline') {
|
|
733
|
+
context.strokeStyle = entity.stroke;
|
|
734
|
+
|
|
735
|
+
let flag = false;
|
|
736
|
+
|
|
737
|
+
let points = entity.points;
|
|
738
|
+
let closed = entity.closed;
|
|
739
|
+
|
|
740
|
+
for (let j = 0; j < points.length; j++) {
|
|
741
|
+
let index = j % 2;
|
|
742
|
+
if (index === 0) {
|
|
743
|
+
let x = points[j];
|
|
744
|
+
let y = points[j + 1];
|
|
745
|
+
|
|
746
|
+
if (j === 0) {
|
|
747
|
+
context.moveTo(x, y);
|
|
748
|
+
} else {
|
|
749
|
+
context.lineTo(x, y);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
if (closed) {
|
|
754
|
+
if (j === points.length - 1) {
|
|
755
|
+
context.lineTo(points[0], points[1]);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
757
759
|
}
|
|
758
760
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
+
// context.closePath();
|
|
762
|
+
context.fillStrokeShape(shape);
|
|
763
|
+
},
|
|
764
|
+
});
|
|
765
|
+
if (this.konvaLayer) this.konvaLayer.add(customShape);
|
|
761
766
|
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
const { scale, x, y } = this.calculateScaleAndPosition(
|
|
771
|
+
_this.bounds1,
|
|
772
|
+
this.konvaStage.width(),
|
|
773
|
+
this.konvaStage.height(),
|
|
774
|
+
0.05 // 5% 边距
|
|
775
|
+
);
|
|
776
|
+
|
|
777
|
+
_this.bounds1 = null;
|
|
778
|
+
|
|
779
|
+
this.konvaStage.position({ x: x, y: y });
|
|
780
|
+
this.konvaStage.scale({ x: scale, y: scale });
|
|
781
|
+
|
|
782
|
+
this.konvaStage.batchDraw();
|
|
783
|
+
//添加成功移动视口位置 pageIdx === 0
|
|
784
|
+
|
|
785
|
+
if (index === 0) {
|
|
786
|
+
pdf.addImage(
|
|
787
|
+
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
788
|
+
0,
|
|
789
|
+
0,
|
|
790
|
+
this.konvaStage.width(),
|
|
791
|
+
this.konvaStage.height()
|
|
792
|
+
);
|
|
793
|
+
} else {
|
|
794
|
+
pdf.addPage();
|
|
795
|
+
pdf.addImage(
|
|
796
|
+
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
797
|
+
0,
|
|
798
|
+
0,
|
|
799
|
+
this.konvaStage.width(),
|
|
800
|
+
this.konvaStage.height()
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
index++
|
|
767
804
|
}
|
|
768
|
-
}
|
|
769
805
|
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
0.05 // 5% 边距
|
|
775
|
-
);
|
|
776
|
-
console.log('test1:');
|
|
777
|
-
console.log(this.bounds1);
|
|
778
|
-
|
|
779
|
-
_this.bounds1 = null;
|
|
780
|
-
|
|
781
|
-
this.konvaStage.position({ x: x, y: y });
|
|
782
|
-
this.konvaStage.scale({ x: scale, y: scale });
|
|
783
|
-
|
|
784
|
-
this.konvaStage.batchDraw();
|
|
785
|
-
//添加成功移动视口位置
|
|
786
|
-
|
|
787
|
-
if (pageIdx == 0) {
|
|
788
|
-
pdf.addImage(
|
|
789
|
-
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
790
|
-
0,
|
|
791
|
-
0,
|
|
792
|
-
this.konvaStage.width(),
|
|
793
|
-
this.konvaStage.height()
|
|
794
|
-
);
|
|
806
|
+
}
|
|
807
|
+
if (index > 0) {
|
|
808
|
+
pdf.save('批量导出.pdf');
|
|
809
|
+
resolve()
|
|
795
810
|
} else {
|
|
796
|
-
|
|
797
|
-
pdf.addImage(
|
|
798
|
-
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
799
|
-
0,
|
|
800
|
-
0,
|
|
801
|
-
this.konvaStage.width(),
|
|
802
|
-
this.konvaStage.height()
|
|
803
|
-
);
|
|
811
|
+
reject('解析数据为空, 请检查数据再进行下载')
|
|
804
812
|
}
|
|
805
|
-
}
|
|
806
|
-
|
|
813
|
+
})
|
|
814
|
+
|
|
815
|
+
|
|
807
816
|
|
|
808
817
|
// var imgData = canvas.toDataURL('image/png');
|
|
809
818
|
//doc.text("Hello world!", 10, 10);
|
|
@@ -818,10 +827,49 @@ export default {
|
|
|
818
827
|
this.konvaLayer = null;
|
|
819
828
|
this.konvaStage = null;
|
|
820
829
|
},
|
|
821
|
-
|
|
822
|
-
|
|
830
|
+
// 更改图纸的色系 区分明暗两种 darkness 暗色系 bright 明亮
|
|
831
|
+
setColorScheme(colorType) {
|
|
832
|
+
// const backgroundColor = colorType === "darkness" ? "#000" : "transparent";
|
|
833
|
+
const color = colorType === 'darkness' ? '#fff' : '#000';
|
|
834
|
+
// konvaStage.container().style.background = backgroundColor;
|
|
835
|
+
this.konvaLayer.children.forEach(item => {
|
|
836
|
+
this.traverseLayer(item, color);
|
|
837
|
+
});
|
|
838
|
+
},
|
|
839
|
+
|
|
840
|
+
traverseLayer(obj, color) {
|
|
841
|
+
if (!obj.attrs.isGroup) {
|
|
842
|
+
if (color === '#fff') {
|
|
843
|
+
let setColor =
|
|
844
|
+
obj.attrs.customColor === '#000' ||
|
|
845
|
+
obj.attrs.customColor === '#000000' ||
|
|
846
|
+
obj.attrs.customColor === 'rgb(0, 0, 0)' ||
|
|
847
|
+
obj.attrs.customColor === 'rgba(0, 0, 0, 1)'
|
|
848
|
+
? color
|
|
849
|
+
: obj.attrs.customColor;
|
|
850
|
+
if (obj.attrs.shapeType === 'hatch' || obj.attrs.shapeType === 'text') {
|
|
851
|
+
obj.setFill(setColor);
|
|
852
|
+
}
|
|
853
|
+
obj.setStroke(setColor);
|
|
854
|
+
obj.attrs.oldCustomColor = obj.attrs.customColor;
|
|
855
|
+
obj.attrs.customColor = setColor;
|
|
856
|
+
} else {
|
|
857
|
+
obj.attrs.customColor = obj.attrs.oldCustomColor;
|
|
858
|
+
if (obj.attrs.shapeType === 'hatch' || obj.attrs.shapeType === 'text') {
|
|
859
|
+
obj.setFill(obj.attrs.customColor);
|
|
860
|
+
}
|
|
861
|
+
obj.setStroke(obj.attrs.customColor);
|
|
862
|
+
}
|
|
863
|
+
} else {
|
|
864
|
+
obj.children.forEach(item => {
|
|
865
|
+
this.traverseLayer(item, color);
|
|
866
|
+
});
|
|
867
|
+
}
|
|
823
868
|
},
|
|
824
869
|
},
|
|
870
|
+
beforeDestroy() {
|
|
871
|
+
this.clearCache();
|
|
872
|
+
},
|
|
825
873
|
};
|
|
826
874
|
</script>
|
|
827
875
|
<style lang="scss" scoped>
|