fl-web-component 2.1.1-beta.2 → 2.1.1-beta.21
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 +11172 -951
- 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 +52 -43
- package/packages/components/com-flcanvas/index.vue +360 -326
- package/packages/components/com-graphics/index.vue +946 -164
- package/packages/utils/StreamLoader.js +1 -1
- package/packages/utils/StreamLoaderParser.worker.js +20 -20
- package/src/utils/instance-parser.js +69 -64
|
@@ -35,11 +35,19 @@ 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 _ from 'lodash'
|
|
43
|
+
import {
|
|
44
|
+
formatEntity,
|
|
45
|
+
handleFn,
|
|
46
|
+
centering,
|
|
47
|
+
_GenerateArcVertices,
|
|
48
|
+
_GenerateBulgeVertices,
|
|
49
|
+
decimalToRGBHex
|
|
50
|
+
} from './components/entityFormatting';
|
|
43
51
|
export default {
|
|
44
52
|
name: 'Fl2dcanvas',
|
|
45
53
|
components: {},
|
|
@@ -72,7 +80,6 @@ export default {
|
|
|
72
80
|
this.konvaStage._resizeDOM();
|
|
73
81
|
}
|
|
74
82
|
});
|
|
75
|
-
|
|
76
83
|
this.$nextTick(() => {
|
|
77
84
|
this.konvaStage = new Konva.Stage({
|
|
78
85
|
className: 'stage',
|
|
@@ -94,7 +101,6 @@ export default {
|
|
|
94
101
|
var scaleBy = 1.1;
|
|
95
102
|
//初始化缩放方法
|
|
96
103
|
this.konvaStage.on('wheel', e => {
|
|
97
|
-
console.log(e);
|
|
98
104
|
e.evt.preventDefault();
|
|
99
105
|
var oldScale = this.konvaStage.scaleX();
|
|
100
106
|
var pointer = this.konvaStage.getPointerPosition();
|
|
@@ -156,27 +162,44 @@ export default {
|
|
|
156
162
|
|
|
157
163
|
*/
|
|
158
164
|
|
|
159
|
-
const { scale, x, y } = this.calculateScaleAndPosition(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
);
|
|
165
|
+
// const { scale, x, y } = this.calculateScaleAndPosition(
|
|
166
|
+
// this.bounds,
|
|
167
|
+
// this.konvaStage.width(),
|
|
168
|
+
// this.konvaStage.height(),
|
|
169
|
+
// 0.05 // 5% 边距
|
|
170
|
+
// );
|
|
165
171
|
|
|
166
|
-
this.konvaStage.position({ x: x, y: y });
|
|
167
|
-
this.konvaStage.scale({ x: scale, y: scale });
|
|
172
|
+
// this.konvaStage.position({ x: x, y: y });
|
|
173
|
+
// this.konvaStage.scale({ x: scale, y: scale });
|
|
168
174
|
|
|
169
|
-
this.konvaStage.batchDraw();
|
|
175
|
+
// this.konvaStage.batchDraw();
|
|
176
|
+
this.centerDraw();
|
|
170
177
|
});
|
|
171
178
|
this.konvaStage.on('click', e => {
|
|
172
179
|
let target = this.konvaStage.mouseClickEndShape;
|
|
173
|
-
this.$emit('leftClick', target ? target.attrs : null)
|
|
180
|
+
this.$emit('leftClick', target ? target.attrs : null);
|
|
174
181
|
});
|
|
175
182
|
});
|
|
176
183
|
},
|
|
177
184
|
//销毁方法
|
|
178
185
|
|
|
179
186
|
methods: {
|
|
187
|
+
// 图纸居中展示
|
|
188
|
+
centerDraw() {
|
|
189
|
+
if (this.bounds) {
|
|
190
|
+
const { scale, x, y } = this.calculateScaleAndPosition(
|
|
191
|
+
this.bounds,
|
|
192
|
+
this.konvaStage.width(),
|
|
193
|
+
this.konvaStage.height(),
|
|
194
|
+
0.05 // 5% 边距
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
this.konvaStage.position({ x: x, y: y });
|
|
198
|
+
this.konvaStage.scale({ x: scale, y: scale });
|
|
199
|
+
|
|
200
|
+
this.konvaStage.batchDraw();
|
|
201
|
+
}
|
|
202
|
+
},
|
|
180
203
|
calculateScaleAndPosition(contentBounds, stageWidth, stageHeight, padding = 0.1) {
|
|
181
204
|
// 1. 计算内容的实际宽高
|
|
182
205
|
const contentWidth = contentBounds.maxX - contentBounds.minX;
|
|
@@ -219,7 +242,6 @@ export default {
|
|
|
219
242
|
|
|
220
243
|
return { scale, x, y };
|
|
221
244
|
},
|
|
222
|
-
|
|
223
245
|
updateBounds(v) {
|
|
224
246
|
if (this.bounds === null) {
|
|
225
247
|
this.bounds = { minX: v.x, maxX: v.x, minY: v.y, maxY: v.y };
|
|
@@ -255,34 +277,37 @@ export default {
|
|
|
255
277
|
//思路是计算居中包围盒,然后排除脏数据。
|
|
256
278
|
loadDxf(data) {
|
|
257
279
|
let _this = this;
|
|
258
|
-
|
|
259
|
-
/* if(this.layer!=null){
|
|
260
|
-
let nodes=this.layer.find(".item");
|
|
261
|
-
for(let i=0;i<nodes.length;i++){
|
|
262
|
-
nodes[i].destroy();
|
|
263
|
-
}
|
|
264
|
-
}*/
|
|
265
|
-
|
|
280
|
+
this.bounds = null;
|
|
266
281
|
this.konvaLayer.destroyChildren();
|
|
267
282
|
const parser = new DxfParser();
|
|
268
283
|
let dxf = parser.parse(data);
|
|
284
|
+
// 在这里处理数据为空的时候
|
|
285
|
+
if (dxf.entities.length === 0) {
|
|
286
|
+
this.$emit('error', {
|
|
287
|
+
type: 'entityEmpty'
|
|
288
|
+
})
|
|
289
|
+
return
|
|
290
|
+
}
|
|
269
291
|
const parser2 = new DxfParser2();
|
|
270
292
|
let dxf2 = parser2.parseSync(data);
|
|
271
|
-
|
|
272
|
-
let hatchEntitys = dxf2.entities;
|
|
293
|
+
let hatchEntitys = dxf2.entities.filter(item => item.type === 'HATCH');
|
|
273
294
|
// 处理HATCH部分
|
|
274
295
|
for (let i = 0; i < hatchEntitys.length; i++) {
|
|
275
296
|
let entity = hatchEntitys[i];
|
|
276
297
|
let layerConfig = this.recordLayerConfig[entity.layer];
|
|
277
|
-
let configParams =
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
298
|
+
let configParams = layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
299
|
+
let entityColor = entity.color;
|
|
300
|
+
let rgb = entityColor ? decimalToRGBHex(entityColor) : {hex: '#FFFFFF'};
|
|
301
|
+
let hex = rgb.hex;
|
|
302
|
+
if (hex == '#FFFFFF') {
|
|
303
|
+
hex = '#000';
|
|
304
|
+
}
|
|
305
|
+
let color = configParams ? configParams.color : hex;
|
|
282
306
|
let visible = configParams ? configParams.visible : true;
|
|
283
|
-
let name = entity.layer.replace(/\s*/g,
|
|
284
|
-
if (entity.type ==
|
|
285
|
-
|
|
307
|
+
let name = entity.layer.replace(/\s*/g, '');
|
|
308
|
+
// if (entity.type == 'HATCH') {
|
|
309
|
+
let boundaryLoops = entity.boundaryLoops;
|
|
310
|
+
if (boundaryLoops && boundaryLoops.length > 0) {
|
|
286
311
|
for (let j = 0; j < boundaryLoops.length; j++) {
|
|
287
312
|
let list = [];
|
|
288
313
|
let edges = boundaryLoops[j].edges;
|
|
@@ -298,10 +323,7 @@ export default {
|
|
|
298
323
|
);
|
|
299
324
|
const axisRatio = entity.radius;
|
|
300
325
|
const yR = xR * axisRatio;
|
|
301
|
-
const rotation = Math.atan2(
|
|
302
|
-
majorAxisEndPoint.y,
|
|
303
|
-
majorAxisEndPoint.x
|
|
304
|
-
);
|
|
326
|
+
const rotation = Math.atan2(majorAxisEndPoint.y, majorAxisEndPoint.x);
|
|
305
327
|
|
|
306
328
|
const arcVertices = _GenerateArcVertices({
|
|
307
329
|
vertices: [],
|
|
@@ -330,10 +352,8 @@ export default {
|
|
|
330
352
|
list.push(arcVertices[i].x);
|
|
331
353
|
list.push(-parseFloat(arcVertices[i].y));
|
|
332
354
|
}
|
|
333
|
-
|
|
334
355
|
}
|
|
335
356
|
if (entity.type == 1) {
|
|
336
|
-
|
|
337
357
|
list.push(entity.start.x);
|
|
338
358
|
list.push(-parseFloat(entity.start.y));
|
|
339
359
|
list.push(entity.end.x);
|
|
@@ -350,7 +370,7 @@ export default {
|
|
|
350
370
|
stroke: color,
|
|
351
371
|
customColor: color,
|
|
352
372
|
visible: visible,
|
|
353
|
-
shapeType: 'hatch'
|
|
373
|
+
shapeType: 'hatch',
|
|
354
374
|
});
|
|
355
375
|
this.konvaLayer.add(line);
|
|
356
376
|
}
|
|
@@ -359,20 +379,14 @@ export default {
|
|
|
359
379
|
let loop = boundaryLoops[0];
|
|
360
380
|
if (loop.type == 7) {
|
|
361
381
|
let vertices = [];
|
|
362
|
-
for (
|
|
363
|
-
let vtxIdx = 0;
|
|
364
|
-
vtxIdx < loop.polyline.vertices.length;
|
|
365
|
-
vtxIdx++
|
|
366
|
-
) {
|
|
382
|
+
for (let vtxIdx = 0; vtxIdx < loop.polyline.vertices.length; vtxIdx++) {
|
|
367
383
|
const vtx = loop.polyline.vertices[vtxIdx];
|
|
368
384
|
if ((vtx.bulge ?? 0) == 0) {
|
|
369
385
|
vertices.push(new Vector2(vtx.x, vtx.y));
|
|
370
386
|
} else {
|
|
371
387
|
const prevVtx =
|
|
372
388
|
loop.polyline.vertices[
|
|
373
|
-
vtxIdx == 0
|
|
374
|
-
? loop.polyline.vertices.length - 1
|
|
375
|
-
: vtxIdx - 1
|
|
389
|
+
vtxIdx == 0 ? loop.polyline.vertices.length - 1 : vtxIdx - 1
|
|
376
390
|
];
|
|
377
391
|
if ((prevVtx.bulge ?? 0) == 0) {
|
|
378
392
|
/* Start vertex is not produced by _GenerateBulgeVertices(). */
|
|
@@ -380,16 +394,9 @@ export default {
|
|
|
380
394
|
}
|
|
381
395
|
const nextVtx =
|
|
382
396
|
loop.polyline.vertices[
|
|
383
|
-
vtxIdx == loop.polyline.vertices.length - 1
|
|
384
|
-
? 0
|
|
385
|
-
: vtxIdx + 1
|
|
397
|
+
vtxIdx == loop.polyline.vertices.length - 1 ? 0 : vtxIdx + 1
|
|
386
398
|
];
|
|
387
|
-
vertices = _GenerateBulgeVertices(
|
|
388
|
-
[],
|
|
389
|
-
vtx,
|
|
390
|
-
nextVtx,
|
|
391
|
-
vtx.bulge
|
|
392
|
-
);
|
|
399
|
+
vertices = _GenerateBulgeVertices([], vtx, nextVtx, vtx.bulge);
|
|
393
400
|
}
|
|
394
401
|
}
|
|
395
402
|
let list = [];
|
|
@@ -408,13 +415,14 @@ export default {
|
|
|
408
415
|
stroke: color,
|
|
409
416
|
customColor: color,
|
|
410
417
|
visible: visible,
|
|
411
|
-
shapeType: 'hatch'
|
|
418
|
+
shapeType: 'hatch',
|
|
412
419
|
});
|
|
413
420
|
this.konvaLayer.add(line);
|
|
414
421
|
}
|
|
415
422
|
}
|
|
416
423
|
}
|
|
417
424
|
}
|
|
425
|
+
// }
|
|
418
426
|
}
|
|
419
427
|
//加载图纸
|
|
420
428
|
let entities = formatEntity(dxf.entities);
|
|
@@ -435,7 +443,8 @@ export default {
|
|
|
435
443
|
key,
|
|
436
444
|
configParams,
|
|
437
445
|
this.konvaLayer,
|
|
438
|
-
|
|
446
|
+
dxf.tables.lineType.lineTypes
|
|
447
|
+
// this.recordLayerConfig
|
|
439
448
|
);
|
|
440
449
|
}
|
|
441
450
|
if (!this.konvaLayer) return;
|
|
@@ -445,84 +454,94 @@ export default {
|
|
|
445
454
|
if (this.konvaLayer) this.konvaLayer.add(entity.obj);
|
|
446
455
|
}
|
|
447
456
|
}
|
|
448
|
-
|
|
449
|
-
if (
|
|
450
|
-
|
|
451
|
-
group[0].stroke = '#000';
|
|
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
|
-
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;
|
|
488
|
-
|
|
489
|
-
let flag = false;
|
|
490
|
-
|
|
491
|
-
let points = entity.points;
|
|
492
|
-
|
|
493
|
-
let closed = entity.closed;
|
|
494
|
-
|
|
495
|
-
for (let j = 0; j < points.length; j++) {
|
|
496
|
-
let index = j % 2;
|
|
497
|
-
if (index === 0) {
|
|
498
|
-
let x = points[j];
|
|
499
|
-
let y = points[j + 1];
|
|
500
|
-
let point = {};
|
|
501
|
-
point.x = x;
|
|
502
|
-
point.y = y;
|
|
503
|
-
_this.updateBounds(point);
|
|
504
|
-
|
|
505
|
-
if (j === 0) {
|
|
506
|
-
context.moveTo(x, y);
|
|
507
|
-
} else {
|
|
508
|
-
context.lineTo(x, y);
|
|
457
|
+
let shapeGroup = group.filter(item => item.type !== 'text')
|
|
458
|
+
if (shapeGroup.length > 0) {
|
|
459
|
+
// if (group[0]?.stroke) {
|
|
460
|
+
// group[0].stroke = '#000';
|
|
461
|
+
// }
|
|
462
|
+
// 根据颜色分组
|
|
463
|
+
let colorGroup = _.groupBy(shapeGroup, 'stroke');
|
|
464
|
+
for (const colorKey in colorGroup) {
|
|
465
|
+
let entityColorGroup = colorGroup[colorKey]
|
|
466
|
+
let customShape = new Konva.Shape({
|
|
467
|
+
x: 0,
|
|
468
|
+
y: 0,
|
|
469
|
+
strokeWidth: 0.2,
|
|
470
|
+
name: key.replace(/\s*/g, ''),
|
|
471
|
+
entityId: key,
|
|
472
|
+
stroke: colorKey,
|
|
473
|
+
customColor: configParams ? configParams.color : colorKey,
|
|
474
|
+
//visible: configParams ? configParams.visible :true,
|
|
475
|
+
sceneFunc(context, shape) {
|
|
476
|
+
context.beginPath();
|
|
477
|
+
for (let i = 0; i < entityColorGroup.length; i++) {
|
|
478
|
+
let entity = entityColorGroup[i];
|
|
479
|
+
if (entity.type === 'line') {
|
|
480
|
+
context.strokeStyle = entity.stroke;
|
|
481
|
+
let x1 = entity.x1;
|
|
482
|
+
let y1 = entity.y1;
|
|
483
|
+
let x2 = entity.x2;
|
|
484
|
+
let y2 = entity.y2;
|
|
485
|
+
if (x1 != undefined && y1 != undefined && x2 != undefined && y2 != undefined) {
|
|
486
|
+
context.moveTo(x1, -parseFloat(y1));
|
|
487
|
+
context.lineTo(x2, -parseFloat(y2));
|
|
509
488
|
}
|
|
489
|
+
let v1 = {};
|
|
490
|
+
v1.x = x1;
|
|
491
|
+
v1.y = y1;
|
|
492
|
+
let v2 = {};
|
|
493
|
+
v2.x = x2;
|
|
494
|
+
v2.y = y2;
|
|
495
|
+
_this.updateBounds(v1);
|
|
496
|
+
_this.updateBounds(v2);
|
|
510
497
|
}
|
|
498
|
+
if (entity.type === 'polyline') {
|
|
499
|
+
context.strokeStyle = entity.stroke;
|
|
500
|
+
|
|
501
|
+
let flag = false;
|
|
502
|
+
|
|
503
|
+
let points = entity.points;
|
|
504
|
+
|
|
505
|
+
let closed = entity.closed;
|
|
506
|
+
|
|
507
|
+
for (let j = 0; j < points.length; j++) {
|
|
508
|
+
let index = j % 2;
|
|
509
|
+
if (index === 0) {
|
|
510
|
+
let x = points[j];
|
|
511
|
+
let y = points[j + 1];
|
|
512
|
+
let point = {};
|
|
513
|
+
point.x = x;
|
|
514
|
+
point.y = y;
|
|
515
|
+
_this.updateBounds(point);
|
|
516
|
+
|
|
517
|
+
if (j === 0) {
|
|
518
|
+
context.moveTo(x, y);
|
|
519
|
+
} else {
|
|
520
|
+
context.lineTo(x, y);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
511
523
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
524
|
+
if (closed) {
|
|
525
|
+
if (j === points.length - 1) {
|
|
526
|
+
context.lineTo(points[0], points[1]);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (entity.lineType === 'DASH') {
|
|
531
|
+
context.setLineDash(entity.dash)
|
|
515
532
|
}
|
|
516
533
|
}
|
|
517
534
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
535
|
+
// context.closePath();
|
|
536
|
+
context.fillStrokeShape(shape);
|
|
537
|
+
},
|
|
538
|
+
shapeType: 'shape',
|
|
539
|
+
});
|
|
540
|
+
if (this.konvaLayer) this.konvaLayer.add(customShape);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
}
|
|
544
|
+
|
|
526
545
|
}
|
|
527
546
|
}
|
|
528
547
|
//缩放视口
|
|
@@ -546,18 +565,19 @@ export default {
|
|
|
546
565
|
this.$refs.svgDraw.clientHeight / 2 -
|
|
547
566
|
(Math.ceil(boundingScale.height) / 2 + boundingScale.y);
|
|
548
567
|
|
|
549
|
-
this.konvaStage.scale({
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
});
|
|
553
|
-
this.konvaStage.setX(0);
|
|
554
|
-
this.konvaStage.setY(750); // 750
|
|
555
|
-
|
|
556
|
-
this.activedSvgPan.zoom.x = 0;
|
|
557
|
-
this.activedSvgPan.zoom.y = 750;
|
|
558
|
-
this.activedSvgPan.x = x;
|
|
559
|
-
this.activedSvgPan.y = x;
|
|
568
|
+
// this.konvaStage.scale({
|
|
569
|
+
// x: 2,
|
|
570
|
+
// y: 2,
|
|
571
|
+
// });
|
|
572
|
+
// this.konvaStage.setX(0);
|
|
573
|
+
// this.konvaStage.setY(750); // 750
|
|
574
|
+
|
|
575
|
+
// this.activedSvgPan.zoom.x = 0;
|
|
576
|
+
// this.activedSvgPan.zoom.y = 750;
|
|
577
|
+
// this.activedSvgPan.x = x;
|
|
578
|
+
// this.activedSvgPan.y = x;
|
|
560
579
|
setTimeout(() => {
|
|
580
|
+
this.centerDraw();
|
|
561
581
|
this.$emit('loaded');
|
|
562
582
|
}, 100);
|
|
563
583
|
},
|
|
@@ -599,143 +619,59 @@ export default {
|
|
|
599
619
|
},
|
|
600
620
|
toPdfs(list) {
|
|
601
621
|
let _this = this;
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
let
|
|
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
|
-
for (let i = 0; i < group.length; i++) {
|
|
637
|
-
let entity = group[i];
|
|
638
|
-
if (entity.type === 'line') {
|
|
639
|
-
let x1 = entity.x1;
|
|
640
|
-
let y1 = entity.y1;
|
|
641
|
-
let x2 = entity.x2;
|
|
642
|
-
let y2 = entity.y2;
|
|
643
|
-
let v1 = {};
|
|
644
|
-
v1.x = x1;
|
|
645
|
-
v1.y = y1;
|
|
646
|
-
let v2 = {};
|
|
647
|
-
v2.x = x2;
|
|
648
|
-
v2.y = y2;
|
|
649
|
-
_this.updateBounds1(v1);
|
|
650
|
-
_this.updateBounds1(v2);
|
|
651
|
-
}
|
|
652
|
-
if (entity.type === 'polyline') {
|
|
653
|
-
let flag = false;
|
|
654
|
-
let points = entity.points;
|
|
655
|
-
let closed = entity.closed;
|
|
656
|
-
|
|
657
|
-
for (let j = 0; j < points.length; j++) {
|
|
658
|
-
let index = j % 2;
|
|
659
|
-
if (index === 0) {
|
|
660
|
-
let x = points[j];
|
|
661
|
-
let y = points[j + 1];
|
|
662
|
-
let point = {};
|
|
663
|
-
point.x = x;
|
|
664
|
-
point.y = y;
|
|
665
|
-
_this.updateBounds1(point);
|
|
666
|
-
}
|
|
622
|
+
return new Promise((resolve, reject) => {
|
|
623
|
+
const pdf = new jsPDF('l', 'px', [this.konvaStage.width(), this.konvaStage.height()]);
|
|
624
|
+
const exportPixelRatio = 2; // 可以 2/3/4 自己调
|
|
625
|
+
let index = 0;
|
|
626
|
+
for (let pageIdx = 0; pageIdx < list.length; pageIdx++) {
|
|
627
|
+
let data = list[pageIdx];
|
|
628
|
+
//先绘制图面
|
|
629
|
+
this.konvaLayer.destroyChildren();
|
|
630
|
+
const parser = new DxfParser();
|
|
631
|
+
let dxf = parser.parse(data);
|
|
632
|
+
if (dxf.entities.length > 0) {
|
|
633
|
+
let entities = formatEntity(dxf.entities);
|
|
634
|
+
let layers = dxf.tables.layer.layers;
|
|
635
|
+
//先计算包围
|
|
636
|
+
for (let key in entities) {
|
|
637
|
+
if (entities[key]) {
|
|
638
|
+
let group = [];
|
|
639
|
+
let l = entities[key].length;
|
|
640
|
+
let layerConfig = this.recordLayerConfig[key];
|
|
641
|
+
let configParams =
|
|
642
|
+
layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
643
|
+
for (let i = 0; i < l; i++) {
|
|
644
|
+
let type = entities[key][i].type;
|
|
645
|
+
handleFn(
|
|
646
|
+
type,
|
|
647
|
+
dxf,
|
|
648
|
+
entities[key][i],
|
|
649
|
+
group,
|
|
650
|
+
key,
|
|
651
|
+
configParams,
|
|
652
|
+
this.konvaLayer,
|
|
653
|
+
this.recordLayerConfig
|
|
654
|
+
);
|
|
667
655
|
}
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
console.log('bounds1');
|
|
674
|
-
console.log(_this.bounds1);
|
|
675
|
-
|
|
676
|
-
for (let key in entities) {
|
|
677
|
-
if (entities[key]) {
|
|
678
|
-
let group = [];
|
|
679
|
-
let l = entities[key].length;
|
|
680
|
-
let layerConfig = this.recordLayerConfig[key];
|
|
681
|
-
let configParams =
|
|
682
|
-
layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
683
|
-
for (let i = 0; i < l; i++) {
|
|
684
|
-
let type = entities[key][i].type;
|
|
685
|
-
handleFn(
|
|
686
|
-
type,
|
|
687
|
-
dxf,
|
|
688
|
-
entities[key][i],
|
|
689
|
-
group,
|
|
690
|
-
key,
|
|
691
|
-
configParams,
|
|
692
|
-
this.konvaLayer,
|
|
693
|
-
this.recordLayerConfig
|
|
694
|
-
);
|
|
695
|
-
}
|
|
696
|
-
if (!this.konvaLayer) return;
|
|
697
|
-
for (let i = 0; i < group.length; i++) {
|
|
698
|
-
let entity = group[i];
|
|
699
|
-
if (entity.type === 'text') {
|
|
700
|
-
if (this.konvaLayer) this.konvaLayer.add(entity.obj);
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
if (group[0].stroke == undefined) {
|
|
705
|
-
console.log(group);
|
|
706
|
-
group[0].stroke = '#000';
|
|
707
|
-
}
|
|
708
656
|
|
|
709
|
-
let customShape = new Konva.Shape({
|
|
710
|
-
x: 0,
|
|
711
|
-
y: 0,
|
|
712
|
-
strokeWidth: 0.2,
|
|
713
|
-
name: key.replace(/\s*/g, ''),
|
|
714
|
-
entityId: key,
|
|
715
|
-
stroke: group[0].stroke,
|
|
716
|
-
customColor: configParams ? configParams.color : '',
|
|
717
|
-
//visible: configParams ? configParams.visible :true,
|
|
718
|
-
sceneFunc(context, shape) {
|
|
719
|
-
context.beginPath();
|
|
720
657
|
for (let i = 0; i < group.length; i++) {
|
|
721
658
|
let entity = group[i];
|
|
722
|
-
|
|
723
659
|
if (entity.type === 'line') {
|
|
724
|
-
context.strokeStyle = entity.stroke;
|
|
725
660
|
let x1 = entity.x1;
|
|
726
661
|
let y1 = entity.y1;
|
|
727
662
|
let x2 = entity.x2;
|
|
728
663
|
let y2 = entity.y2;
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
664
|
+
let v1 = {};
|
|
665
|
+
v1.x = x1;
|
|
666
|
+
v1.y = y1;
|
|
667
|
+
let v2 = {};
|
|
668
|
+
v2.x = x2;
|
|
669
|
+
v2.y = y2;
|
|
670
|
+
_this.updateBounds1(v1);
|
|
671
|
+
_this.updateBounds1(v2);
|
|
733
672
|
}
|
|
734
673
|
if (entity.type === 'polyline') {
|
|
735
|
-
context.strokeStyle = entity.stroke;
|
|
736
|
-
|
|
737
674
|
let flag = false;
|
|
738
|
-
|
|
739
675
|
let points = entity.points;
|
|
740
676
|
let closed = entity.closed;
|
|
741
677
|
|
|
@@ -744,67 +680,159 @@ export default {
|
|
|
744
680
|
if (index === 0) {
|
|
745
681
|
let x = points[j];
|
|
746
682
|
let y = points[j + 1];
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
context.lineTo(x, y);
|
|
752
|
-
}
|
|
683
|
+
let point = {};
|
|
684
|
+
point.x = x;
|
|
685
|
+
point.y = y;
|
|
686
|
+
_this.updateBounds1(point);
|
|
753
687
|
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
for (let key in entities) {
|
|
695
|
+
if (entities[key]) {
|
|
696
|
+
let group = [];
|
|
697
|
+
let l = entities[key].length;
|
|
698
|
+
let layerConfig = this.recordLayerConfig[key];
|
|
699
|
+
let configParams =
|
|
700
|
+
layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
701
|
+
for (let i = 0; i < l; i++) {
|
|
702
|
+
let type = entities[key][i].type;
|
|
703
|
+
handleFn(
|
|
704
|
+
type,
|
|
705
|
+
dxf,
|
|
706
|
+
entities[key][i],
|
|
707
|
+
group,
|
|
708
|
+
key,
|
|
709
|
+
configParams,
|
|
710
|
+
this.konvaLayer,
|
|
711
|
+
this.recordLayerConfig
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
if (!this.konvaLayer) return;
|
|
715
|
+
for (let i = 0; i < group.length; i++) {
|
|
716
|
+
let entity = group[i];
|
|
717
|
+
if (entity.type === 'text') {
|
|
718
|
+
if (this.konvaLayer) this.konvaLayer.add(entity.obj);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
if (group.length > 0) {
|
|
723
|
+
if (group[0]?.stroke) {
|
|
724
|
+
group[0].stroke = '#000';
|
|
725
|
+
}
|
|
754
726
|
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
727
|
+
let customShape = new Konva.Shape({
|
|
728
|
+
x: 0,
|
|
729
|
+
y: 0,
|
|
730
|
+
strokeWidth: 0.2,
|
|
731
|
+
name: key.replace(/\s*/g, ''),
|
|
732
|
+
entityId: key,
|
|
733
|
+
stroke: group[0].stroke,
|
|
734
|
+
customColor: configParams ? configParams.color : '',
|
|
735
|
+
//visible: configParams ? configParams.visible :true,
|
|
736
|
+
sceneFunc(context, shape) {
|
|
737
|
+
context.beginPath();
|
|
738
|
+
for (let i = 0; i < group.length; i++) {
|
|
739
|
+
let entity = group[i];
|
|
740
|
+
|
|
741
|
+
if (entity.type === 'line') {
|
|
742
|
+
context.strokeStyle = entity.stroke;
|
|
743
|
+
let x1 = entity.x1;
|
|
744
|
+
let y1 = entity.y1;
|
|
745
|
+
let x2 = entity.x2;
|
|
746
|
+
let y2 = entity.y2;
|
|
747
|
+
if (x1 != undefined && y1 != undefined && x2 != undefined && y2 != undefined) {
|
|
748
|
+
context.moveTo(x1, -parseFloat(y1));
|
|
749
|
+
context.lineTo(x2, -parseFloat(y2));
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
if (entity.type === 'polyline') {
|
|
753
|
+
context.strokeStyle = entity.stroke;
|
|
754
|
+
|
|
755
|
+
let flag = false;
|
|
756
|
+
|
|
757
|
+
let points = entity.points;
|
|
758
|
+
let closed = entity.closed;
|
|
759
|
+
|
|
760
|
+
for (let j = 0; j < points.length; j++) {
|
|
761
|
+
let index = j % 2;
|
|
762
|
+
if (index === 0) {
|
|
763
|
+
let x = points[j];
|
|
764
|
+
let y = points[j + 1];
|
|
765
|
+
|
|
766
|
+
if (j === 0) {
|
|
767
|
+
context.moveTo(x, y);
|
|
768
|
+
} else {
|
|
769
|
+
context.lineTo(x, y);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
if (closed) {
|
|
774
|
+
if (j === points.length - 1) {
|
|
775
|
+
context.lineTo(points[0], points[1]);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
758
779
|
}
|
|
759
780
|
}
|
|
760
|
-
|
|
761
|
-
|
|
781
|
+
// context.closePath();
|
|
782
|
+
context.fillStrokeShape(shape);
|
|
783
|
+
},
|
|
784
|
+
});
|
|
785
|
+
if (this.konvaLayer) this.konvaLayer.add(customShape);
|
|
762
786
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
},
|
|
766
|
-
});
|
|
767
|
-
if (this.konvaLayer) this.konvaLayer.add(customShape);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
770
789
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
console.log('test1:');
|
|
778
|
-
console.log(this.bounds1);
|
|
790
|
+
const { scale, x, y } = this.calculateScaleAndPosition(
|
|
791
|
+
_this.bounds1,
|
|
792
|
+
this.konvaStage.width(),
|
|
793
|
+
this.konvaStage.height(),
|
|
794
|
+
0.05 // 5% 边距
|
|
795
|
+
);
|
|
779
796
|
|
|
780
|
-
|
|
797
|
+
_this.bounds1 = null;
|
|
781
798
|
|
|
782
|
-
|
|
783
|
-
|
|
799
|
+
this.konvaStage.position({ x: x, y: y });
|
|
800
|
+
this.konvaStage.scale({ x: scale, y: scale });
|
|
784
801
|
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
802
|
+
this.konvaStage.batchDraw();
|
|
803
|
+
//添加成功移动视口位置 pageIdx === 0
|
|
804
|
+
|
|
805
|
+
if (index === 0) {
|
|
806
|
+
pdf.addImage(
|
|
807
|
+
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
808
|
+
0,
|
|
809
|
+
0,
|
|
810
|
+
this.konvaStage.width(),
|
|
811
|
+
this.konvaStage.height()
|
|
812
|
+
);
|
|
813
|
+
} else {
|
|
814
|
+
pdf.addPage();
|
|
815
|
+
pdf.addImage(
|
|
816
|
+
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
817
|
+
0,
|
|
818
|
+
0,
|
|
819
|
+
this.konvaStage.width(),
|
|
820
|
+
this.konvaStage.height()
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
index++
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
}
|
|
827
|
+
if (index > 0) {
|
|
828
|
+
pdf.save('批量导出.pdf');
|
|
829
|
+
resolve()
|
|
796
830
|
} else {
|
|
797
|
-
|
|
798
|
-
pdf.addImage(
|
|
799
|
-
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
800
|
-
0,
|
|
801
|
-
0,
|
|
802
|
-
this.konvaStage.width(),
|
|
803
|
-
this.konvaStage.height()
|
|
804
|
-
);
|
|
831
|
+
reject('解析数据为空, 请检查数据再进行下载')
|
|
805
832
|
}
|
|
806
|
-
}
|
|
807
|
-
|
|
833
|
+
})
|
|
834
|
+
|
|
835
|
+
|
|
808
836
|
|
|
809
837
|
// var imgData = canvas.toDataURL('image/png');
|
|
810
838
|
//doc.text("Hello world!", 10, 10);
|
|
@@ -822,32 +850,38 @@ export default {
|
|
|
822
850
|
// 更改图纸的色系 区分明暗两种 darkness 暗色系 bright 明亮
|
|
823
851
|
setColorScheme(colorType) {
|
|
824
852
|
// const backgroundColor = colorType === "darkness" ? "#000" : "transparent";
|
|
825
|
-
const color = colorType ===
|
|
853
|
+
const color = colorType === 'darkness' ? '#fff' : '#000';
|
|
826
854
|
// konvaStage.container().style.background = backgroundColor;
|
|
827
|
-
this.konvaLayer.children.forEach(
|
|
855
|
+
this.konvaLayer.children.forEach(item => {
|
|
828
856
|
this.traverseLayer(item, color);
|
|
829
857
|
});
|
|
830
858
|
},
|
|
831
|
-
|
|
859
|
+
|
|
832
860
|
traverseLayer(obj, color) {
|
|
833
861
|
if (!obj.attrs.isGroup) {
|
|
834
862
|
if (color === '#fff') {
|
|
835
|
-
|
|
863
|
+
let setColor =
|
|
864
|
+
obj.attrs.customColor === '#000' ||
|
|
865
|
+
obj.attrs.customColor === '#000000' ||
|
|
866
|
+
obj.attrs.customColor === 'rgb(0, 0, 0)' ||
|
|
867
|
+
obj.attrs.customColor === 'rgba(0, 0, 0, 1)'
|
|
868
|
+
? color
|
|
869
|
+
: obj.attrs.customColor;
|
|
836
870
|
if (obj.attrs.shapeType === 'hatch' || obj.attrs.shapeType === 'text') {
|
|
837
871
|
obj.setFill(setColor);
|
|
838
872
|
}
|
|
839
873
|
obj.setStroke(setColor);
|
|
840
|
-
obj.attrs.oldCustomColor = obj.attrs.customColor
|
|
841
|
-
obj.attrs.customColor = setColor
|
|
874
|
+
obj.attrs.oldCustomColor = obj.attrs.customColor;
|
|
875
|
+
obj.attrs.customColor = setColor;
|
|
842
876
|
} else {
|
|
843
|
-
obj.attrs.customColor = obj.attrs.oldCustomColor
|
|
877
|
+
obj.attrs.customColor = obj.attrs.oldCustomColor;
|
|
844
878
|
if (obj.attrs.shapeType === 'hatch' || obj.attrs.shapeType === 'text') {
|
|
845
879
|
obj.setFill(obj.attrs.customColor);
|
|
846
880
|
}
|
|
847
881
|
obj.setStroke(obj.attrs.customColor);
|
|
848
882
|
}
|
|
849
883
|
} else {
|
|
850
|
-
obj.children.forEach(
|
|
884
|
+
obj.children.forEach(item => {
|
|
851
885
|
this.traverseLayer(item, color);
|
|
852
886
|
});
|
|
853
887
|
}
|
|
@@ -855,7 +889,7 @@ export default {
|
|
|
855
889
|
},
|
|
856
890
|
beforeDestroy() {
|
|
857
891
|
this.clearCache();
|
|
858
|
-
}
|
|
892
|
+
},
|
|
859
893
|
};
|
|
860
894
|
</script>
|
|
861
895
|
<style lang="scss" scoped>
|