fl-web-component 2.1.1-beta.5 → 2.1.1-beta.7
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 +234 -220
- 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 +8 -8
- package/packages/components/com-flcanvas/index.vue +245 -233
- package/packages/components/com-graphics/index.vue +34 -34
- package/src/utils/instance-parser.js +16 -16
|
@@ -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 };
|
|
@@ -270,18 +289,16 @@ export default {
|
|
|
270
289
|
let dxf2 = parser2.parseSync(data);
|
|
271
290
|
|
|
272
291
|
let hatchEntitys = dxf2.entities;
|
|
292
|
+
console.log(dxf2.entities)
|
|
273
293
|
// 处理HATCH部分
|
|
274
294
|
for (let i = 0; i < hatchEntitys.length; i++) {
|
|
275
295
|
let entity = hatchEntitys[i];
|
|
276
296
|
let layerConfig = this.recordLayerConfig[entity.layer];
|
|
277
|
-
let configParams =
|
|
278
|
-
|
|
279
|
-
? layerConfig
|
|
280
|
-
: null;
|
|
281
|
-
let color = configParams ? configParams.color : "#000";
|
|
297
|
+
let configParams = layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
298
|
+
let color = configParams ? configParams.color : '#000';
|
|
282
299
|
let visible = configParams ? configParams.visible : true;
|
|
283
|
-
let name = entity.layer.replace(/\s*/g,
|
|
284
|
-
if (entity.type ==
|
|
300
|
+
let name = entity.layer.replace(/\s*/g, '');
|
|
301
|
+
if (entity.type == 'HATCH') {
|
|
285
302
|
let boundaryLoops = entity.boundaryLoops;
|
|
286
303
|
for (let j = 0; j < boundaryLoops.length; j++) {
|
|
287
304
|
let list = [];
|
|
@@ -298,10 +315,7 @@ export default {
|
|
|
298
315
|
);
|
|
299
316
|
const axisRatio = entity.radius;
|
|
300
317
|
const yR = xR * axisRatio;
|
|
301
|
-
const rotation = Math.atan2(
|
|
302
|
-
majorAxisEndPoint.y,
|
|
303
|
-
majorAxisEndPoint.x
|
|
304
|
-
);
|
|
318
|
+
const rotation = Math.atan2(majorAxisEndPoint.y, majorAxisEndPoint.x);
|
|
305
319
|
|
|
306
320
|
const arcVertices = _GenerateArcVertices({
|
|
307
321
|
vertices: [],
|
|
@@ -330,10 +344,8 @@ export default {
|
|
|
330
344
|
list.push(arcVertices[i].x);
|
|
331
345
|
list.push(-parseFloat(arcVertices[i].y));
|
|
332
346
|
}
|
|
333
|
-
|
|
334
347
|
}
|
|
335
348
|
if (entity.type == 1) {
|
|
336
|
-
|
|
337
349
|
list.push(entity.start.x);
|
|
338
350
|
list.push(-parseFloat(entity.start.y));
|
|
339
351
|
list.push(entity.end.x);
|
|
@@ -350,7 +362,7 @@ export default {
|
|
|
350
362
|
stroke: color,
|
|
351
363
|
customColor: color,
|
|
352
364
|
visible: visible,
|
|
353
|
-
shapeType: 'hatch'
|
|
365
|
+
shapeType: 'hatch',
|
|
354
366
|
});
|
|
355
367
|
this.konvaLayer.add(line);
|
|
356
368
|
}
|
|
@@ -359,20 +371,14 @@ export default {
|
|
|
359
371
|
let loop = boundaryLoops[0];
|
|
360
372
|
if (loop.type == 7) {
|
|
361
373
|
let vertices = [];
|
|
362
|
-
for (
|
|
363
|
-
let vtxIdx = 0;
|
|
364
|
-
vtxIdx < loop.polyline.vertices.length;
|
|
365
|
-
vtxIdx++
|
|
366
|
-
) {
|
|
374
|
+
for (let vtxIdx = 0; vtxIdx < loop.polyline.vertices.length; vtxIdx++) {
|
|
367
375
|
const vtx = loop.polyline.vertices[vtxIdx];
|
|
368
376
|
if ((vtx.bulge ?? 0) == 0) {
|
|
369
377
|
vertices.push(new Vector2(vtx.x, vtx.y));
|
|
370
378
|
} else {
|
|
371
379
|
const prevVtx =
|
|
372
380
|
loop.polyline.vertices[
|
|
373
|
-
vtxIdx == 0
|
|
374
|
-
? loop.polyline.vertices.length - 1
|
|
375
|
-
: vtxIdx - 1
|
|
381
|
+
vtxIdx == 0 ? loop.polyline.vertices.length - 1 : vtxIdx - 1
|
|
376
382
|
];
|
|
377
383
|
if ((prevVtx.bulge ?? 0) == 0) {
|
|
378
384
|
/* Start vertex is not produced by _GenerateBulgeVertices(). */
|
|
@@ -380,16 +386,9 @@ export default {
|
|
|
380
386
|
}
|
|
381
387
|
const nextVtx =
|
|
382
388
|
loop.polyline.vertices[
|
|
383
|
-
vtxIdx == loop.polyline.vertices.length - 1
|
|
384
|
-
? 0
|
|
385
|
-
: vtxIdx + 1
|
|
389
|
+
vtxIdx == loop.polyline.vertices.length - 1 ? 0 : vtxIdx + 1
|
|
386
390
|
];
|
|
387
|
-
vertices = _GenerateBulgeVertices(
|
|
388
|
-
[],
|
|
389
|
-
vtx,
|
|
390
|
-
nextVtx,
|
|
391
|
-
vtx.bulge
|
|
392
|
-
);
|
|
391
|
+
vertices = _GenerateBulgeVertices([], vtx, nextVtx, vtx.bulge);
|
|
393
392
|
}
|
|
394
393
|
}
|
|
395
394
|
let list = [];
|
|
@@ -408,7 +407,7 @@ export default {
|
|
|
408
407
|
stroke: color,
|
|
409
408
|
customColor: color,
|
|
410
409
|
visible: visible,
|
|
411
|
-
shapeType: 'hatch'
|
|
410
|
+
shapeType: 'hatch',
|
|
412
411
|
});
|
|
413
412
|
this.konvaLayer.add(line);
|
|
414
413
|
}
|
|
@@ -447,7 +446,6 @@ export default {
|
|
|
447
446
|
}
|
|
448
447
|
|
|
449
448
|
if (group[0].stroke == undefined) {
|
|
450
|
-
console.log(group);
|
|
451
449
|
group[0].stroke = '#000';
|
|
452
450
|
}
|
|
453
451
|
let customShape = new Konva.Shape({
|
|
@@ -558,6 +556,7 @@ export default {
|
|
|
558
556
|
this.activedSvgPan.x = x;
|
|
559
557
|
this.activedSvgPan.y = x;
|
|
560
558
|
setTimeout(() => {
|
|
559
|
+
this.centerDraw();
|
|
561
560
|
this.$emit('loaded');
|
|
562
561
|
}, 100);
|
|
563
562
|
},
|
|
@@ -599,143 +598,60 @@ export default {
|
|
|
599
598
|
},
|
|
600
599
|
toPdfs(list) {
|
|
601
600
|
let _this = this;
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
let
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
let
|
|
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
|
-
}
|
|
601
|
+
return new Promise((resolve, reject) => {
|
|
602
|
+
const pdf = new jsPDF('l', 'px', [this.konvaStage.width(), this.konvaStage.height()]);
|
|
603
|
+
const exportPixelRatio = 2; // 可以 2/3/4 自己调
|
|
604
|
+
let index = 0;
|
|
605
|
+
for (let pageIdx = 0; pageIdx < list.length; pageIdx++) {
|
|
606
|
+
let data = list[pageIdx];
|
|
607
|
+
//先绘制图面
|
|
608
|
+
this.konvaLayer.destroyChildren();
|
|
609
|
+
const parser = new DxfParser();
|
|
610
|
+
let dxf = parser.parse(data);
|
|
611
|
+
|
|
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
|
+
);
|
|
667
635
|
}
|
|
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
636
|
|
|
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
637
|
for (let i = 0; i < group.length; i++) {
|
|
721
638
|
let entity = group[i];
|
|
722
|
-
|
|
723
639
|
if (entity.type === 'line') {
|
|
724
|
-
context.strokeStyle = entity.stroke;
|
|
725
640
|
let x1 = entity.x1;
|
|
726
641
|
let y1 = entity.y1;
|
|
727
642
|
let x2 = entity.x2;
|
|
728
643
|
let y2 = entity.y2;
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
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);
|
|
733
652
|
}
|
|
734
653
|
if (entity.type === 'polyline') {
|
|
735
|
-
context.strokeStyle = entity.stroke;
|
|
736
|
-
|
|
737
654
|
let flag = false;
|
|
738
|
-
|
|
739
655
|
let points = entity.points;
|
|
740
656
|
let closed = entity.closed;
|
|
741
657
|
|
|
@@ -744,67 +660,157 @@ export default {
|
|
|
744
660
|
if (index === 0) {
|
|
745
661
|
let x = points[j];
|
|
746
662
|
let y = points[j + 1];
|
|
663
|
+
let point = {};
|
|
664
|
+
point.x = x;
|
|
665
|
+
point.y = y;
|
|
666
|
+
_this.updateBounds1(point);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
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
|
+
}
|
|
747
701
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
702
|
+
if (group[0].stroke == undefined) {
|
|
703
|
+
group[0].stroke = '#000';
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
let customShape = new Konva.Shape({
|
|
707
|
+
x: 0,
|
|
708
|
+
y: 0,
|
|
709
|
+
strokeWidth: 0.2,
|
|
710
|
+
name: key.replace(/\s*/g, ''),
|
|
711
|
+
entityId: key,
|
|
712
|
+
stroke: group[0].stroke,
|
|
713
|
+
customColor: configParams ? configParams.color : '',
|
|
714
|
+
//visible: configParams ? configParams.visible :true,
|
|
715
|
+
sceneFunc(context, shape) {
|
|
716
|
+
context.beginPath();
|
|
717
|
+
for (let i = 0; i < group.length; i++) {
|
|
718
|
+
let entity = group[i];
|
|
719
|
+
|
|
720
|
+
if (entity.type === 'line') {
|
|
721
|
+
context.strokeStyle = entity.stroke;
|
|
722
|
+
let x1 = entity.x1;
|
|
723
|
+
let y1 = entity.y1;
|
|
724
|
+
let x2 = entity.x2;
|
|
725
|
+
let y2 = entity.y2;
|
|
726
|
+
if (x1 != undefined && y1 != undefined && x2 != undefined && y2 != undefined) {
|
|
727
|
+
context.moveTo(x1, -parseFloat(y1));
|
|
728
|
+
context.lineTo(x2, -parseFloat(y2));
|
|
752
729
|
}
|
|
753
730
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
731
|
+
if (entity.type === 'polyline') {
|
|
732
|
+
context.strokeStyle = entity.stroke;
|
|
733
|
+
|
|
734
|
+
let flag = false;
|
|
735
|
+
|
|
736
|
+
let points = entity.points;
|
|
737
|
+
let closed = entity.closed;
|
|
738
|
+
|
|
739
|
+
for (let j = 0; j < points.length; j++) {
|
|
740
|
+
let index = j % 2;
|
|
741
|
+
if (index === 0) {
|
|
742
|
+
let x = points[j];
|
|
743
|
+
let y = points[j + 1];
|
|
744
|
+
|
|
745
|
+
if (j === 0) {
|
|
746
|
+
context.moveTo(x, y);
|
|
747
|
+
} else {
|
|
748
|
+
context.lineTo(x, y);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
if (closed) {
|
|
753
|
+
if (j === points.length - 1) {
|
|
754
|
+
context.lineTo(points[0], points[1]);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
758
757
|
}
|
|
759
758
|
}
|
|
760
759
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
760
|
+
// context.closePath();
|
|
761
|
+
context.fillStrokeShape(shape);
|
|
762
|
+
},
|
|
763
|
+
});
|
|
764
|
+
if (this.konvaLayer) this.konvaLayer.add(customShape);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
const { scale, x, y } = this.calculateScaleAndPosition(
|
|
769
|
+
_this.bounds1,
|
|
770
|
+
this.konvaStage.width(),
|
|
771
|
+
this.konvaStage.height(),
|
|
772
|
+
0.05 // 5% 边距
|
|
773
|
+
);
|
|
774
|
+
|
|
775
|
+
_this.bounds1 = null;
|
|
776
|
+
|
|
777
|
+
this.konvaStage.position({ x: x, y: y });
|
|
778
|
+
this.konvaStage.scale({ x: scale, y: scale });
|
|
779
|
+
|
|
780
|
+
this.konvaStage.batchDraw();
|
|
781
|
+
//添加成功移动视口位置 pageIdx === 0
|
|
782
|
+
|
|
783
|
+
if (index === 0) {
|
|
784
|
+
pdf.addImage(
|
|
785
|
+
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
786
|
+
0,
|
|
787
|
+
0,
|
|
788
|
+
this.konvaStage.width(),
|
|
789
|
+
this.konvaStage.height()
|
|
790
|
+
);
|
|
791
|
+
} else {
|
|
792
|
+
pdf.addPage();
|
|
793
|
+
pdf.addImage(
|
|
794
|
+
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
795
|
+
0,
|
|
796
|
+
0,
|
|
797
|
+
this.konvaStage.width(),
|
|
798
|
+
this.konvaStage.height()
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
index++
|
|
768
802
|
}
|
|
769
|
-
}
|
|
770
803
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
0.05 // 5% 边距
|
|
776
|
-
);
|
|
777
|
-
console.log('test1:');
|
|
778
|
-
console.log(this.bounds1);
|
|
779
|
-
|
|
780
|
-
_this.bounds1 = null;
|
|
781
|
-
|
|
782
|
-
this.konvaStage.position({ x: x, y: y });
|
|
783
|
-
this.konvaStage.scale({ x: scale, y: scale });
|
|
784
|
-
|
|
785
|
-
this.konvaStage.batchDraw();
|
|
786
|
-
//添加成功移动视口位置
|
|
787
|
-
|
|
788
|
-
if (pageIdx == 0) {
|
|
789
|
-
pdf.addImage(
|
|
790
|
-
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
791
|
-
0,
|
|
792
|
-
0,
|
|
793
|
-
this.konvaStage.width(),
|
|
794
|
-
this.konvaStage.height()
|
|
795
|
-
);
|
|
804
|
+
}
|
|
805
|
+
if (index > 0) {
|
|
806
|
+
pdf.save('批量导出.pdf');
|
|
807
|
+
resolve()
|
|
796
808
|
} else {
|
|
797
|
-
|
|
798
|
-
pdf.addImage(
|
|
799
|
-
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
800
|
-
0,
|
|
801
|
-
0,
|
|
802
|
-
this.konvaStage.width(),
|
|
803
|
-
this.konvaStage.height()
|
|
804
|
-
);
|
|
809
|
+
reject('解析数据为空, 请检查数据再进行下载')
|
|
805
810
|
}
|
|
806
|
-
}
|
|
807
|
-
|
|
811
|
+
})
|
|
812
|
+
|
|
813
|
+
|
|
808
814
|
|
|
809
815
|
// var imgData = canvas.toDataURL('image/png');
|
|
810
816
|
//doc.text("Hello world!", 10, 10);
|
|
@@ -822,32 +828,38 @@ export default {
|
|
|
822
828
|
// 更改图纸的色系 区分明暗两种 darkness 暗色系 bright 明亮
|
|
823
829
|
setColorScheme(colorType) {
|
|
824
830
|
// const backgroundColor = colorType === "darkness" ? "#000" : "transparent";
|
|
825
|
-
const color = colorType ===
|
|
831
|
+
const color = colorType === 'darkness' ? '#fff' : '#000';
|
|
826
832
|
// konvaStage.container().style.background = backgroundColor;
|
|
827
|
-
this.konvaLayer.children.forEach(
|
|
833
|
+
this.konvaLayer.children.forEach(item => {
|
|
828
834
|
this.traverseLayer(item, color);
|
|
829
835
|
});
|
|
830
836
|
},
|
|
831
|
-
|
|
837
|
+
|
|
832
838
|
traverseLayer(obj, color) {
|
|
833
839
|
if (!obj.attrs.isGroup) {
|
|
834
840
|
if (color === '#fff') {
|
|
835
|
-
|
|
841
|
+
let setColor =
|
|
842
|
+
obj.attrs.customColor === '#000' ||
|
|
843
|
+
obj.attrs.customColor === '#000000' ||
|
|
844
|
+
obj.attrs.customColor === 'rgb(0, 0, 0)' ||
|
|
845
|
+
obj.attrs.customColor === 'rgba(0, 0, 0, 1)'
|
|
846
|
+
? color
|
|
847
|
+
: obj.attrs.customColor;
|
|
836
848
|
if (obj.attrs.shapeType === 'hatch' || obj.attrs.shapeType === 'text') {
|
|
837
849
|
obj.setFill(setColor);
|
|
838
850
|
}
|
|
839
851
|
obj.setStroke(setColor);
|
|
840
|
-
obj.attrs.oldCustomColor = obj.attrs.customColor
|
|
841
|
-
obj.attrs.customColor = setColor
|
|
852
|
+
obj.attrs.oldCustomColor = obj.attrs.customColor;
|
|
853
|
+
obj.attrs.customColor = setColor;
|
|
842
854
|
} else {
|
|
843
|
-
obj.attrs.customColor = obj.attrs.oldCustomColor
|
|
855
|
+
obj.attrs.customColor = obj.attrs.oldCustomColor;
|
|
844
856
|
if (obj.attrs.shapeType === 'hatch' || obj.attrs.shapeType === 'text') {
|
|
845
857
|
obj.setFill(obj.attrs.customColor);
|
|
846
858
|
}
|
|
847
859
|
obj.setStroke(obj.attrs.customColor);
|
|
848
860
|
}
|
|
849
861
|
} else {
|
|
850
|
-
obj.children.forEach(
|
|
862
|
+
obj.children.forEach(item => {
|
|
851
863
|
this.traverseLayer(item, color);
|
|
852
864
|
});
|
|
853
865
|
}
|
|
@@ -855,7 +867,7 @@ export default {
|
|
|
855
867
|
},
|
|
856
868
|
beforeDestroy() {
|
|
857
869
|
this.clearCache();
|
|
858
|
-
}
|
|
870
|
+
},
|
|
859
871
|
};
|
|
860
872
|
</script>
|
|
861
873
|
<style lang="scss" scoped>
|