fl-web-component 1.3.12 → 1.3.14

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 +1 @@
1
- @charset "UTF-8";#fl-model[data-v-785e8966]{width:100%;height:100%;cursor:pointer}[data-v-785e8966] .tips-label{width:60px;color:#000;font:12px Helvetica;margin-top:-3em;padding:5px;text-align:center;vertical-align:middle;background-color:khaki}[data-v-785e8966] .measure-label{max-width:100px;margin-top:-1em;border:10px;border-radius:5px;padding:3px 10px;cursor:pointer;color:#009bea;background-color:#f4f4f4;box-shadow:0 1px 3px 1px rgba(0,0,0,.25)}[data-v-785e8966] .circle-tag{width:10px;height:10px;margin-top:5px;border-radius:50%;background-color:#ff5000}[data-v-785e8966] .measure-label-font{word-break:break-all}[data-v-785e8966] .mark-label-img{padding-top:5px;width:20px;height:20px}#konva-container[data-v-2fa9e609]{z-index:3;width:100%;height:100%;cursor:pointer;overflow:hidden}span[data-v-f547d5c6]{font-weight:bolder}.text[data-v-f547d5c6]{margin-top:20px}.line[data-v-f547d5c6]{border-bottom:1px solid #dcdfe6;margin:20px 0}.center[data-v-f547d5c6]{display:flex;flex-direction:column;align-items:center}.center .cen span[data-v-f547d5c6],.center .top span[data-v-f547d5c6]{color:"#53a8ff";display:inline-block;width:30px;height:30px;text-align:center;line-height:30px;border:1px solid;padding:5px;margin-bottom:10px;background-color:#e9f3ff}.center .cen span[data-v-f547d5c6]{margin:10px}.button[data-v-f547d5c6]{display:flex;justify-content:end;margin-top:20px}@font-face{font-family:iconfont;src:url(//at.alicdn.com/t/font_3226805_qqvo3ag3r8.woff2?t=1646635700216) format("woff2"),url(//at.alicdn.com/t/font_3226805_qqvo3ag3r8.woff?t=1646635700216) format("woff"),url(//at.alicdn.com/t/font_3226805_qqvo3ag3r8.ttf?t=1646635700216) format("truetype")}.iconfont[data-v-f547d5c6]{font-family:iconfont!important;font-size:50px;font-style:normal;color:"#53a8ff";-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.icon-shubiao[data-v-f547d5c6]:before{content:""}#svg-tigger[data-v-0ec35ee4]{cursor:pointer;height:100%;width:100%}
1
+ @charset "UTF-8";#fl-model[data-v-0390b048]{width:100%;height:100%;cursor:pointer}[data-v-0390b048] .tips-label{width:60px;color:#000;font:12px Helvetica;margin-top:-3em;padding:5px;text-align:center;vertical-align:middle;background-color:khaki}[data-v-0390b048] .measure-label{max-width:100px;margin-top:-1em;border:10px;border-radius:5px;padding:3px 10px;cursor:pointer;color:#009bea;background-color:#f4f4f4;box-shadow:0 1px 3px 1px rgba(0,0,0,.25)}[data-v-0390b048] .circle-tag{width:10px;height:10px;margin-top:5px;border-radius:50%;background-color:#ff5000}[data-v-0390b048] .measure-label-font{word-break:break-all}[data-v-0390b048] .mark-label-img{padding-top:5px;width:20px;height:20px}.lil-gui{background:hsla(0,0%,100%,.95)!important;border:1px solid #e0e0e0!important;border-radius:8px!important;box-shadow:0 4px 12px rgba(0,0,0,.15)!important;backdrop-filter:blur(10px)!important;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif!important}.lil-gui .title{background:linear-gradient(135deg,#f8f9fa,#e9ecef)!important;color:#495057!important;border-bottom:1px solid #dee2e6!important;font-weight:600!important;padding:0 12px!important;border-radius:8px 8px 0 0!important}.lil-gui .controller{border-bottom:1px solid #f1f3f4!important;background:transparent!important}.lil-gui .controller:last-child{border-bottom:none!important}.lil-gui .controller .name{color:#495057!important;font-weight:500!important;font-size:12px!important}.lil-gui .controller .widget{background:#f8f9fa!important;border:1px solid #ced4da!important;border-radius:4px!important;color:#495057!important}.lil-gui .controller .widget:focus,.lil-gui .controller .widget:hover{border-color:#80bdff!important;box-shadow:0 0 0 2px rgba(0,123,255,.25)!important}.lil-gui .controller .widget:focus{outline:none!important}.lil-gui .controller input[type=range]{background:#e9ecef!important;height:4px!important;-webkit-appearance:none!important;-moz-appearance:none!important;appearance:none!important;border-radius:2px!important}.lil-gui .controller.number .fill{border-right:solid #008de9}.lil-gui .controller input[type=range]::-webkit-slider-thumb{background:#007bff!important;border:2px solid #fff!important;box-shadow:0 2px 4px rgba(0,0,0,.2)!important;width:16px!important;height:16px!important;border-radius:50%!important;-webkit-appearance:none!important;appearance:none!important;cursor:pointer!important}.lil-gui .controller input[type=range]::-moz-range-thumb{background:#007bff!important;border:2px solid #fff!important;box-shadow:0 2px 4px rgba(0,0,0,.2)!important;width:16px!important;height:16px!important;border-radius:50%!important;cursor:pointer!important}.lil-gui .controller .option{background:#fff!important;color:#495057!important;border-bottom:1px solid #f1f3f4!important}.lil-gui .controller .option:hover{background:#f8f9fa!important}.lil-gui .controller .option:last-child{border-bottom:none!important}.lil-gui input:active{background:#e6eff4}.lil-gui .controller button{background:linear-gradient(135deg,#007bff,#0056b3)!important;color:#fff!important;border:none!important;border-radius:4px!important;font-weight:500!important;transition:all .2s ease!important}.lil-gui .controller button:hover{background:linear-gradient(135deg,#0056b3,#004085)!important;transform:translateY(-1px)!important;box-shadow:0 4px 8px rgba(0,123,255,.3)!important}.lil-gui .controller .color{border:2px solid #fff!important;border-radius:4px!important;box-shadow:0 2px 4px rgba(0,0,0,.1)!important}.lil-gui .controller.number .slider,.lil-gui .controller.number .slider:hover{background-color:#e6eff4}.lil-gui input,.lil-gui input:hover,.lil-gui input[type=number]:focus,.lil-gui input[type=text]:focus{background:#e6eff4}.lil-gui .controller>.name{min-width:25px}.lil-gui .controller.number input{color:#2e3136}.lil-gui .controller.number .slider:active{background-color:#e6eff4}.lil-gui .folder>.title{background:linear-gradient(135deg,#f1f3f4,#e9ecef)!important;color:#495057!important;border-bottom:1px solid #dee2e6!important}.lil-gui .folder>.title:before{color:#6c757d!important}.lil-gui .folder.closed>.children{display:none!important}#konva-container[data-v-1b43deb6]{z-index:3;width:100%;height:100%;cursor:pointer;overflow:hidden}span[data-v-f547d5c6]{font-weight:bolder}.text[data-v-f547d5c6]{margin-top:20px}.line[data-v-f547d5c6]{border-bottom:1px solid #dcdfe6;margin:20px 0}.center[data-v-f547d5c6]{display:flex;flex-direction:column;align-items:center}.center .cen span[data-v-f547d5c6],.center .top span[data-v-f547d5c6]{color:"#53a8ff";display:inline-block;width:30px;height:30px;text-align:center;line-height:30px;border:1px solid;padding:5px;margin-bottom:10px;background-color:#e9f3ff}.center .cen span[data-v-f547d5c6]{margin:10px}.button[data-v-f547d5c6]{display:flex;justify-content:end;margin-top:20px}@font-face{font-family:iconfont;src:url(//at.alicdn.com/t/font_3226805_qqvo3ag3r8.woff2?t=1646635700216) format("woff2"),url(//at.alicdn.com/t/font_3226805_qqvo3ag3r8.woff?t=1646635700216) format("woff"),url(//at.alicdn.com/t/font_3226805_qqvo3ag3r8.ttf?t=1646635700216) format("truetype")}.iconfont[data-v-f547d5c6]{font-family:iconfont!important;font-size:50px;font-style:normal;color:"#53a8ff";-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.icon-shubiao[data-v-f547d5c6]:before{content:""}#svg-tigger[data-v-0ec35ee4]{cursor:pointer;height:100%;width:100%}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fl-web-component",
3
- "version": "1.3.12",
3
+ "version": "1.3.14",
4
4
  "scripts": {
5
5
  "tip1": "仅调试本组件不涉及业务组件,请执行dev",
6
6
  "dev": "vue-cli-service serve",
@@ -1,10 +1,9 @@
1
1
  <template>
2
- <div ref="svgDraw" id="konva-container" style="height: 100%"></div>
2
+
3
+ <div ref="svgDraw" id="konva-container" style="height:100%"></div>
3
4
  </template>
4
5
 
5
6
  <script>
6
- var inspectionRect = null;
7
- var preTarget = [];
8
7
  function base64ToBlob(base64) {
9
8
  const byteCharacters = atob(base64);
10
9
  const byteArrays = [];
@@ -21,10 +20,13 @@ var preTarget = [];
21
20
  return new Blob(byteArrays, { type: 'application/pdf' });
22
21
  }
23
22
 
23
+
24
24
  function createObjectURL(blob) {
25
25
  return URL.createObjectURL(blob);
26
26
  }
27
27
 
28
+
29
+
28
30
  function downloadPDF(base64, fileName) {
29
31
  const blob = base64ToBlob(base64);
30
32
  const url = createObjectURL(blob);
@@ -36,106 +38,90 @@ var preTarget = [];
36
38
  document.body.removeChild(link); // 下载完成后移除元素
37
39
  URL.revokeObjectURL(url); // 释放URL对象
38
40
  }
39
- import Konva from 'konva';
40
- import DxfParser from 'dxf-parser';
41
- import jsPDF from 'jspdf';
42
- import { formatEntity, handleFn, centering } from './components/entityFormatting';
43
- var konvaStage = null,
44
- konvaLayer = null;
45
- var activedSvgPan = {
46
- x: 0,
47
- y: 0,
48
- zoom: {
49
- x: 1,
50
- y: 1,
51
- },
52
- };
41
+ import Konva from 'konva'
42
+ import DxfParser from "dxf-parser";
43
+ import jsPDF from 'jspdf'
44
+ import { formatEntity, handleFn, centering } from './components/entityFormatting'
45
+ var konvaStage = null, konvaLayer = null;
46
+ var recordLayerConfig = {}
47
+ var activedSvgPan = {
48
+ x: 0,
49
+ y: 0,
50
+ zoom: {
51
+ x: 1,
52
+ y: 1,
53
+ },
54
+ };
53
55
  export default {
54
- name: 'Fl2dcanvas',
56
+ name: "Fl2dcanvas",
55
57
  components: {},
56
58
  data() {
57
- return {};
59
+ return {
60
+
61
+ };
58
62
  },
59
- mounted() {
63
+ created() {
60
64
  //resize方法
61
65
  window.addEventListener('resize', () => {
62
66
  if (konvaStage) {
63
- const obj = document.getElementById('konva-container');
64
- konvaStage.setWidth(obj.clientWidth);
65
- konvaStage.setHeight(obj.clientHeight);
66
- konvaStage._resizeDOM();
67
+ const obj = document.getElementById('konva-container')
68
+ konvaStage.setWidth(obj.clientWidth)
69
+ konvaStage.setHeight(obj.clientHeight)
70
+ konvaStage._resizeDOM()
67
71
  }
68
72
  });
69
73
 
74
+
70
75
  this.$nextTick(() => {
71
- konvaStage = new Konva.Stage({
72
- className: 'stage',
73
- container: 'konva-container',
74
- width: this.$refs.svgDraw.clientWidth,
75
- height: this.$refs.svgDraw.clientHeight,
76
- draggable: true,
77
- });
78
- //init layer
79
- konvaLayer = new Konva.Layer({
80
- name: 'konva-layer',
81
- x: 0,
82
- y: 0,
83
- });
84
- //设置清晰度
85
- konvaLayer.getCanvas().setPixelRatio(2);
86
- konvaStage.add(konvaLayer);
87
- konvaLayer.draw();
88
- var scaleBy = 1.5;
89
- //初始化缩放方法
90
- konvaStage.on('wheel', e => {
91
- e.evt.preventDefault();
92
- var oldScale = konvaStage.scaleX();
93
- var pointer = konvaStage.getPointerPosition();
94
- var mousePointTo = {
95
- x: (pointer.x - konvaStage.x()) / oldScale,
96
- y: (pointer.y - konvaStage.y()) / oldScale,
97
- };
98
- // how to scale? Zoom in? Or zoom out?
99
- let direction = e.evt.deltaY > 0 ? -1 : 1;
100
- if (e.evt.ctrlKey) {
101
- direction = -direction;
102
- }
103
- var newScale = direction > 0 ? oldScale * scaleBy : oldScale / scaleBy;
104
- this.scaleRatio = Math.ceil(newScale);
105
- // 判断比例尺百分比
106
- if (this.scaleRatio <1 || this.scaleRatio >= 100) return;
107
- // 设置放大缩小多少倍
108
- konvaStage.scale({ x: newScale, y: newScale });
109
- var newPos = {
110
- x: pointer.x - mousePointTo.x * newScale,
111
- y: pointer.y - mousePointTo.y * newScale,
112
- };
113
- konvaStage.position(newPos);
114
- });
115
- // 点击事件
116
- konvaStage.on('click', e => {
117
- let clickObj = null;
118
- let position = konvaStage.getPointerPosition();
119
- let x = (position.x- konvaStage.getX()) / konvaStage.scaleX();
120
- let y = (position.y- konvaStage.getY()) / konvaStage.scaleY();
121
- inspectionRect.setX(x);
122
- inspectionRect.setY(y);
123
- position = null;
124
- if (
125
- e.target.attrs.hasOwnProperty("className") &&
126
- e.target.attrs.className === "stage"
127
- ) {
128
- let obj = this.getIntersects(inspectionRect.getClientRect());
129
- clickObj = obj.length > 0 ? obj[obj.length - 1] : null;
130
- } else {
131
- clickObj = e.target.attrs;
132
- }
133
- if (e.evt.button === 0) {
134
- this.$emit('leftClick', clickObj);
135
- } else if (e.evt.button === 2) {
136
- this.$emit('rightClick', clickObj);
137
- }
138
- });
76
+ console.log(document.getElementById('konva-container'));
77
+ console.log(this.$refs.svgDraw);
78
+ konvaStage = new Konva.Stage({
79
+ className: "stage",
80
+ container: "konva-container",
81
+ width: this.$refs.svgDraw.clientWidth,
82
+ height: this.$refs.svgDraw.clientHeight,
83
+ draggable: true,
84
+ });
85
+ //init layer
86
+ konvaLayer = new Konva.Layer({
87
+ name: "konva-layer",
88
+ x: 0,
89
+ y: 0,
90
+ });
91
+ //设置清晰度
92
+ konvaLayer.getCanvas().setPixelRatio(2);
93
+ konvaStage.add(konvaLayer);
94
+ konvaLayer.draw();
95
+ var scaleBy = 1.1;
96
+ //初始化缩放方法
97
+ konvaStage.on("wheel", (e) => {
98
+ console.log(e)
99
+ e.evt.preventDefault();
100
+ var oldScale = konvaStage.scaleX();
101
+ var pointer = konvaStage.getPointerPosition();
102
+ var mousePointTo = {
103
+ x: (pointer.x - konvaStage.x()) / oldScale,
104
+ y: (pointer.y - konvaStage.y()) / oldScale,
105
+ };
106
+ // how to scale? Zoom in? Or zoom out?
107
+ let direction = e.evt.deltaY > 0 ? -1 : 1;
108
+ if (e.evt.ctrlKey) {
109
+ direction = -direction;
110
+ }
111
+ var newScale = direction > 0 ? oldScale * scaleBy : oldScale / scaleBy;
112
+ this.scaleRatio = Math.ceil(newScale)
113
+ console.log(this.scaleRatio);
114
+ // 判断比例尺百分比
115
+ console.log(this.scaleRatio);
116
+ if (this.scaleRatio <1 || this.scaleRatio >= 100) return
117
+ // 设置放大缩小多少倍
118
+ konvaStage.scale({ x: newScale, y: newScale });
119
+ var newPos = {
120
+ x: pointer.x - mousePointTo.x * newScale,
121
+ y: pointer.y - mousePointTo.y * newScale,
122
+ };
123
+ konvaStage.position(newPos);
124
+ });
139
125
  });
140
126
 
141
127
  //create方法结束
@@ -143,178 +129,170 @@ var activedSvgPan = {
143
129
  //销毁方法
144
130
 
145
131
  methods: {
146
- loadDxf(data, layerConfigs = {}) {
147
- konvaLayer.destroyChildren();
148
- konvaStage.scale({
149
- x: 1,
150
- y: 1,
151
- });
152
- konvaStage.setX(0);
153
- konvaStage.setY(0);
154
- inspectionRect = null;
155
- inspectionRect = new Konva.Rect({
156
- width: 1.5,
157
- height: 1.5,
158
- x: 0,
159
- y: 0,
160
- stroke: "#000",
161
- strokeWidth: 0.2,
162
- name: "intersect-rect",
163
- visible: false,
164
- opacity: 0
165
- });
166
- konvaLayer.add(inspectionRect);
167
- const parser = new DxfParser();
168
- let dxf = parser.parse(data);
169
- let entities = formatEntity(dxf.entities);
170
- let layers = dxf.tables.layer.layers;
171
-
172
- for (let key in entities) {
173
- if (entities[key]) {
174
- let group = [];
175
- let l = entities[key].length;
176
- let layerConfig = layerConfigs[key];
177
- let configParams =
178
- layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
179
- for (let i = 0; i < l; i++) {
180
- let type = entities[key][i].type;
181
- handleFn(
182
- type,
183
- dxf,
184
- entities[key][i],
185
- group,
186
- key,
187
- configParams,
188
- konvaLayer,
189
- layerConfigs
190
- );
191
- }
192
- if (!konvaLayer) return;
193
- for (let i = 0; i < group.length; i++) {
194
- let entity = group[i];
195
- if (entity.type === 'text') {
196
- if (konvaLayer) konvaLayer.add(entity.obj);
132
+ loadDxf(data){
133
+
134
+
135
+
136
+
137
+ const parser = new DxfParser();
138
+ let dxf = parser.parse(data);
139
+ let entities = formatEntity(dxf.entities);
140
+
141
+
142
+ let layers = dxf.tables.layer.layers;
143
+ //加载图纸
144
+ console.log(layers);
145
+
146
+ for (let key in entities) {
147
+
148
+
149
+
150
+ if (entities[key]) {
151
+ let group = [];
152
+ let l = entities[key].length
153
+ let layerConfig = recordLayerConfig[key]
154
+ let configParams = layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null
155
+ for (let i = 0; i < l; i++) {
156
+ let type = entities[key][i].type;
157
+ handleFn(type, dxf, entities[key][i], group, key, configParams, konvaLayer, recordLayerConfig)
197
158
  }
198
- }
159
+ if (!konvaLayer) return
160
+ for(let i = 0; i < group.length;i++) {
161
+ let entity = group[i];
162
+ if (entity.type === 'text') {
163
+ if (konvaLayer) konvaLayer.add(entity.obj);
164
+ }
165
+ }
166
+
167
+
199
168
 
200
- let customShape = new Konva.Shape({
201
- x: 0,
202
- y: 0,
203
- strokeWidth: 0.2,
204
- name: key.replace(/\s*/g, ''),
205
- entityId: key,
206
- stroke: configParams ? configParams.color : '#000',
207
- customColor: configParams ? configParams.color : '#000',
208
- visible: configParams ? configParams.visible : true,
209
- sceneFunc(context, shape) {
210
- context.beginPath();
211
- for (let i = 0; i < group.length; i++) {
212
- let entity = group[i];
213
- if (entity.type === 'line') {
214
- let x1 = entity.x1;
215
- let y1 = entity.y1;
216
- let x2 = entity.x2;
217
- let y2 = entity.y2;
218
-
219
- if (x1 != undefined && y1 != undefined && x2 != undefined && y2 != undefined) {
220
- context.moveTo(x1, -parseFloat(y1));
221
- context.lineTo(x2, -parseFloat(y2));
169
+ let customShape = new Konva.Shape({
170
+ x: 0,
171
+ y: 0,
172
+ strokeWidth: 0.2,
173
+ name: key.replace(/\s*/g, ""),
174
+ entityId: key,
175
+ stroke: configParams ? configParams.color : "#000",
176
+ customColor: configParams ? configParams.color : "",
177
+ //visible: configParams ? configParams.visible :true,
178
+ sceneFunc (context, shape) {
179
+ context.beginPath();
180
+ for(let i = 0; i < group.length;i++){
181
+ let entity = group[i];
182
+ if(entity.type === 'line'){
183
+ let x1=entity.x1;
184
+ let y1=entity.y1;
185
+ let x2=entity.x2;
186
+ let y2=entity.y2;
187
+
188
+
189
+ if(x1!=undefined&&y1!=undefined&&x2!=undefined&&y2!=undefined) {
190
+
191
+
192
+ context.moveTo(x1, -parseFloat(y1));
193
+ context.lineTo(x2, -parseFloat(y2));
194
+ }
222
195
  }
223
- shape.px = entity.x1
224
- shape.py = -entity.y1
225
- }
226
- if (entity.type === 'polyline') {
227
- let flag = false;
228
-
229
- let points = entity.points;
230
- let closed = entity.closed;
231
-
232
- for (let j = 0; j < points.length; j++) {
233
- let index = j % 2;
234
- if (index === 0) {
235
- let x = points[j];
236
- let y = points[j + 1];
237
- if (j === 0) {
238
- context.moveTo(x, y);
239
- } else {
240
- context.lineTo(x, y);
196
+ if(entity.type === "polyline"){
197
+ let flag=false;
198
+
199
+
200
+
201
+ let points=entity.points;
202
+ let closed = entity.closed;
203
+
204
+
205
+
206
+ for(let j = 0; j < points.length; j++){
207
+ let index = j % 2;
208
+ if(index === 0){
209
+ let x = points[j];
210
+ let y = points[j+1];
211
+ if(j === 0){
212
+ context.moveTo(x, y);
213
+ }else{
214
+ context.lineTo(x,y);
215
+ }
241
216
  }
242
- }
243
217
 
244
- if (closed) {
245
- if (j === points.length - 1) {
246
- context.lineTo(points[0], points[1]);
218
+ if(closed) {
219
+ if (j === points.length - 1) {
220
+ context.lineTo(points[0], points[1]);
221
+ }
247
222
  }
248
223
  }
249
224
  }
250
- shape.px = points[0]
251
- shape.py = points[1]
252
225
  }
226
+ // context.closePath();
227
+ context.fillStrokeShape(shape);
253
228
  }
254
- // context.closePath();
255
- context.fillStrokeShape(shape);
256
- },
257
- });
258
- if (konvaLayer) konvaLayer.add(customShape);
229
+ });
230
+ if (konvaLayer) konvaLayer.add(customShape);
231
+ }
259
232
  }
260
- }
261
- //缩放视口
262
- let scale = 1;
263
- const boundingRect = konvaLayer.getClientRect();
264
- let ratio = Number((this.$refs.svgDraw?.clientWidth / boundingRect.width).toFixed(1));
265
- if (ratio > 2) {
266
- scale = Number((boundingRect.width / boundingRect.height).toFixed(1));
267
- scale = scale < 2 ? 2 : scale;
268
- }
269
- konvaStage.scale({
270
- x: scale,
271
- y: scale,
272
- })
273
- const boundingScale = konvaLayer.getClientRect();
274
- //平移视口
275
- const x =
276
- this.$refs.svgDraw?.clientWidth / 2 -
277
- (Math.ceil(boundingScale.width) / 2 + boundingScale.x / 2);
278
- const y =
279
- this.$refs.svgDraw.clientHeight / 2 -
280
- (Math.ceil(boundingScale.height) / 2 + boundingScale.y);
281
-
282
- // konvaStage.scale({
283
- // x: 2,
284
- // y: 2,
285
- // });
286
- konvaStage.setX(x);
287
- konvaStage.setY(y); // 750
288
-
289
- activedSvgPan.zoom.x = scale;
290
- activedSvgPan.zoom.y = scale;
291
- activedSvgPan.x = x;
292
- activedSvgPan.y = y;
293
- setTimeout(() => {
294
- this.$emit('loaded')
295
- }, 100)
296
- },
297
- toPdf(name) {
233
+ //缩放视口
234
+ let scale = 1;
235
+ const boundingRect = konvaLayer.getClientRect();
236
+ let ratio = Number((this.$refs.svgDraw?.clientWidth / boundingRect.width).toFixed(1));
237
+ if (ratio > 2) {
238
+ scale = Number((boundingRect.width / boundingRect.height).toFixed(1));
239
+ scale = scale < 2 ? 2 : scale;
240
+ }
241
+ // konvaStage.scale({
242
+ // x: scale,
243
+ // y: scale,
244
+ //})
245
+ const boundingScale = konvaLayer.getClientRect();
246
+ //平移视口
247
+ const x =
248
+ this.$refs.svgDraw?.clientWidth / 2 -
249
+ (Math.ceil(boundingScale.width) / 2 + boundingScale.x / 2);
250
+ const y =
251
+ this.$refs.svgDraw.clientHeight / 2 -
252
+ (Math.ceil(boundingScale.height) / 2 + boundingScale.y);
253
+
254
+
255
+
256
+
257
+ konvaStage.scale({
258
+ x: 2,
259
+ y: 2,
260
+ });
261
+ konvaStage.setX(0);
262
+ konvaStage.setY(750); // 750
263
+
264
+ activedSvgPan.zoom.x = 0;
265
+ activedSvgPan.zoom.y = 750;
266
+ activedSvgPan.x = x;
267
+ activedSvgPan.y = x;
268
+ setTimeout(() => {
269
+ this.$emit('loaded')
270
+ }, 100)
271
+
272
+
273
+
274
+ },
275
+ toPdf(name){
276
+ //konvaStage.scale({
277
+ //x: activedSvgPan.zoom.x,
278
+ //y: activedSvgPan.zoom.y,
279
+ //});
280
+ //konvaStage.setX(activedSvgPan.x);
281
+ //konvaStage.setY(activedSvgPan.y);
298
282
  // get data URL with default settings
299
- konvaStage.scale({
300
- x: activedSvgPan.zoom.x,
301
- y: activedSvgPan.zoom.y,
302
- });
303
- konvaStage.setX(activedSvgPan.x);
304
- konvaStage.setY(activedSvgPan.y);
283
+
305
284
  // open in new window
306
285
  konvaLayer.getCanvas().setPixelRatio(1);
307
286
  const jpegURL = konvaStage.toDataURL({
308
287
  mimeType: 'image/jpeg',
309
- quality: 1.0,
288
+ quality:1.0
310
289
  });
311
290
 
312
- let pageData = konvaLayer.canvas.toDataURL('image/jpeg', 1.0);
291
+ let pageData=konvaLayer.canvas.toDataURL('image/jpeg', 1.0);
313
292
 
314
- console.log(pageData);
315
293
 
316
294
  let img = new Image();
317
- img.src = jpegURL;
295
+ img.src=jpegURL;
318
296
  const pdf = new jsPDF('l', 'px', [konvaStage.width(), konvaStage.height()]);
319
297
 
320
298
  pdf.addImage(
@@ -325,95 +303,24 @@ var activedSvgPan = {
325
303
  konvaStage.height()
326
304
  );
327
305
 
328
- pdf.save(name + '.pdf');
329
- // var imgData = canvas.toDataURL('image/png');
306
+ pdf.save(name+".pdf");
307
+ // var imgData = canvas.toDataURL('image/png');
330
308
  //doc.text("Hello world!", 10, 10);
331
309
  //doc.save("a4.pdf");
332
310
  },
333
- clearCache() {
334
- konvaLayer && konvaLayer.destroyChildren();
335
- konvaLayer && konvaLayer.destroy();
336
- konvaLayer && konvaLayer.clear();
337
- konvaStage && konvaStage.destroy();
338
- konvaStage && konvaStage.clearCache();
339
- konvaLayer = null;
340
- konvaStage = null;
341
- },
342
- getIntersects(rect) {
343
- let l = konvaLayer.children.length;
344
- let intersects = [];
345
- for (let index = 0; index < l; index++) {
346
- const ele = konvaLayer.children[index];
347
- if (ele.attrs.name !== "intersect-rect") {
348
- const boundingRect = ele.getClientRect();
349
- if (
350
- !(
351
- rect.x + rect.width < boundingRect.x ||
352
- boundingRect.x + boundingRect.width < rect.x ||
353
- rect.y + rect.height < boundingRect.y ||
354
- boundingRect.y + boundingRect.height < rect.y
355
- )
356
- ) {
357
-
358
- intersects.push(ele);
359
- }
360
- }
361
- }
362
- return intersects;
363
- },
364
- // 参数说明arr数组,每个元素为一个对象,对象包含id, color属性
365
- highLight(arr) {
366
- for (let index = 0; index < arr.length; index++) {
367
- const element = arr[index];
368
- let name = element.id.replace(/\s*/g, "")
369
- let obj = konvaStage.find("." + name)
370
- if (obj.length > 0) {
371
- let lists = obj.filter((item) => !item.attrs.isGroup);
372
- for (let i = 0; i < lists.length; i++) {
373
- preTarget.push(lists[i]);
374
- const ele = lists[i];
375
- if (ele.className === "Text") {
376
- ele.setFill(element.color);
377
- ele.setStroke(element.color)
378
- } else {
379
- ele.setStroke(element.color);
380
- }
381
- }
382
- }
383
- }
384
- },
385
- resetHighLight() {
386
- for (let index = 0; index < preTarget.length; index++) {
387
- const element = preTarget[index];
388
- if (element.className === "Text") {
389
- element.setFill(element.attrs.customColor);
390
- element.setStroke(element.attrs.customColor)
391
- } else {
392
- element.setStroke(element.attrs.customColor);
393
- }
394
- }
395
- preTarget.splice(0);
396
- },
397
- // 居中定位
398
- centering(id) {
399
- let entityId = id.replace(/\s*/g, "");
400
- let obj = konvaStage.find("." + entityId);
401
- let scaleBy = 8;
402
- if (obj.length > 0) {
403
- konvaStage.scale({ x: scaleBy, y: scaleBy });
404
- centering(obj, this.$refs.svgDraw, konvaStage, scaleBy)
405
- obj = null;
406
- }
407
- },
408
- resize(width, height) {
409
- konvaStage.setWidth(width);
410
- konvaStage.setHeight(height);
411
- konvaStage._resizeDOM();
311
+ clearCache(){
312
+ konvaLayer && konvaLayer.destroyChildren()
313
+ konvaLayer && konvaLayer.destroy()
314
+ konvaLayer && konvaLayer.clear()
315
+ konvaStage && konvaStage.destroy()
316
+ konvaStage && konvaStage.clearCache()
317
+ konvaLayer = null
318
+ konvaStage = null
412
319
  },
413
320
  beforeDestroy() {
414
- this.clearCache();
415
- },
416
- },
321
+ this.clearCache()
322
+ }
323
+ }
417
324
  };
418
325
  </script>
419
326
  <style lang="scss" scoped>