fl-web-component 1.1.11 → 1.2.1
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/README.md +5 -0
- package/dist/fl-web-component.common.js +244 -99
- package/dist/fl-web-component.css +1 -1
- package/package.json +1 -1
- package/packages/components/com-flcanvas/components/entityFormatting.js +4 -4
- package/packages/components/com-flcanvas/index.vue +129 -26
- package/packages/components/com-graphics/index.vue +50 -7
- package/src/utils/flgltf-parser.js +1 -1
- package/src/utils/instance-parser.js +2 -2
- package/src/utils/mock.js +260016 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
@charset "UTF-8";#fl-model[data-v-
|
|
1
|
+
@charset "UTF-8";#fl-model[data-v-b78ab6fa],#konva-container[data-v-4b99f9dc]{width:100%;height:100%;cursor:pointer}#konva-container[data-v-4b99f9dc]{z-index:3;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-09d5c9d8]{cursor:pointer;height:100%;width:100%}
|
package/package.json
CHANGED
|
@@ -290,7 +290,7 @@ function drawLine(recordDxf, entity, group, key, configParams) {
|
|
|
290
290
|
entityId: key,
|
|
291
291
|
isGroup: false,
|
|
292
292
|
stroke: configParams ? configParams.color : "#000",
|
|
293
|
-
customColor: configParams ? configParams.color : "",
|
|
293
|
+
customColor: configParams ? configParams.color : "#000",
|
|
294
294
|
strokeWidth: width,
|
|
295
295
|
visible: configParams ? configParams.visible : true,
|
|
296
296
|
oldstrokeLength:width,
|
|
@@ -334,7 +334,7 @@ function drawText(recordDxf, entity, group, key, configParams) {
|
|
|
334
334
|
text: text,
|
|
335
335
|
fontSize: fontSize,
|
|
336
336
|
fill: configParams ? configParams.color : "#000",
|
|
337
|
-
customColor: configParams ? configParams.color : "",
|
|
337
|
+
customColor: configParams ? configParams.color : "#000",
|
|
338
338
|
name: key.replace(/\s*/g, ""),
|
|
339
339
|
entityId: key,
|
|
340
340
|
fontFamily: "SimSun",
|
|
@@ -393,7 +393,7 @@ function drawLwLine(recordDxf, entity, group, key, configParams) {
|
|
|
393
393
|
name: key.replace(/\s*/g, ""),
|
|
394
394
|
entityId: key,
|
|
395
395
|
stroke: configParams ? configParams.color : "#000",
|
|
396
|
-
customColor: configParams ? configParams.color : "",
|
|
396
|
+
customColor: configParams ? configParams.color : "#000",
|
|
397
397
|
strokeWidth: width,
|
|
398
398
|
visible: configParams ? configParams.visible : true,
|
|
399
399
|
oldstrokeLength:width,
|
|
@@ -434,7 +434,7 @@ function drawSpline(recordDxf, entity, group, key, configParams) {
|
|
|
434
434
|
entityId: key,
|
|
435
435
|
isGroup: false,
|
|
436
436
|
stroke: configParams ? configParams : "#000",
|
|
437
|
-
customColor: configParams ? configParams.color : "",
|
|
437
|
+
customColor: configParams ? configParams.color : "#000",
|
|
438
438
|
strokeWidth: width,
|
|
439
439
|
visible: configParams ? configParams.visible : true,
|
|
440
440
|
oldstrokeLength: width
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
5
|
<script>
|
|
6
|
+
var inspectionRect = null;
|
|
7
|
+
var preTarget = [];
|
|
6
8
|
function base64ToBlob(base64) {
|
|
7
9
|
const byteCharacters = atob(base64);
|
|
8
10
|
const byteArrays = [];
|
|
@@ -40,7 +42,6 @@
|
|
|
40
42
|
import { formatEntity, handleFn, centering } from './components/entityFormatting';
|
|
41
43
|
var konvaStage = null,
|
|
42
44
|
konvaLayer = null;
|
|
43
|
-
var recordLayerConfig = {};
|
|
44
45
|
export default {
|
|
45
46
|
name: 'Fl2dcanvas',
|
|
46
47
|
components: {},
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
mounted() {
|
|
51
52
|
//resize方法
|
|
52
53
|
window.addEventListener('resize', () => {
|
|
54
|
+
console.log('resize');
|
|
53
55
|
if (konvaStage) {
|
|
54
56
|
const obj = document.getElementById('konva-container');
|
|
55
57
|
konvaStage.setWidth(obj.clientWidth);
|
|
@@ -81,7 +83,6 @@
|
|
|
81
83
|
var scaleBy = 1.5;
|
|
82
84
|
//初始化缩放方法
|
|
83
85
|
konvaStage.on('wheel', e => {
|
|
84
|
-
console.log(e);
|
|
85
86
|
e.evt.preventDefault();
|
|
86
87
|
var oldScale = konvaStage.scaleX();
|
|
87
88
|
var pointer = konvaStage.getPointerPosition();
|
|
@@ -106,6 +107,31 @@
|
|
|
106
107
|
};
|
|
107
108
|
konvaStage.position(newPos);
|
|
108
109
|
});
|
|
110
|
+
// 点击事件
|
|
111
|
+
konvaStage.on('click', e => {
|
|
112
|
+
let clickObj = null;
|
|
113
|
+
let position = konvaStage.getPointerPosition();
|
|
114
|
+
let x = (position.x- konvaStage.getX()) / konvaStage.scaleX();
|
|
115
|
+
let y = (position.y- konvaStage.getY()) / konvaStage.scaleY();
|
|
116
|
+
inspectionRect.setX(x);
|
|
117
|
+
inspectionRect.setY(y);
|
|
118
|
+
position = null;
|
|
119
|
+
if (
|
|
120
|
+
e.target.attrs.hasOwnProperty("className") &&
|
|
121
|
+
e.target.attrs.className === "stage"
|
|
122
|
+
) {
|
|
123
|
+
let obj = this.getIntersects(inspectionRect.getClientRect());
|
|
124
|
+
console.log(obj);
|
|
125
|
+
clickObj = obj.length > 0 ? obj[obj.length - 1] : null;
|
|
126
|
+
} else {
|
|
127
|
+
clickObj = e.target.attrs;
|
|
128
|
+
}
|
|
129
|
+
if (e.evt.button === 0) {
|
|
130
|
+
this.$emit('leftClick', clickObj);
|
|
131
|
+
} else if (e.evt.button === 2) {
|
|
132
|
+
this.$emit('rightClick', clickObj);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
109
135
|
});
|
|
110
136
|
|
|
111
137
|
//create方法结束
|
|
@@ -113,26 +139,37 @@
|
|
|
113
139
|
//销毁方法
|
|
114
140
|
|
|
115
141
|
methods: {
|
|
116
|
-
loadDxf(data) {
|
|
117
|
-
|
|
118
|
-
|
|
142
|
+
loadDxf(data, layerConfigs = {}) {
|
|
143
|
+
konvaLayer.destroyChildren();
|
|
144
|
+
konvaStage.scale({
|
|
145
|
+
x: 1,
|
|
146
|
+
y: 1,
|
|
147
|
+
});
|
|
148
|
+
konvaStage.setX(0);
|
|
149
|
+
konvaStage.setY(0);
|
|
150
|
+
inspectionRect = null;
|
|
151
|
+
inspectionRect = new Konva.Rect({
|
|
152
|
+
width: 1.5,
|
|
153
|
+
height: 1.5,
|
|
154
|
+
x: 0,
|
|
155
|
+
y: 0,
|
|
156
|
+
stroke: "#000",
|
|
157
|
+
strokeWidth: 0.2,
|
|
158
|
+
name: "intersect-rect",
|
|
159
|
+
visible: false,
|
|
160
|
+
opacity: 0
|
|
161
|
+
});
|
|
162
|
+
konvaLayer.add(inspectionRect);
|
|
119
163
|
const parser = new DxfParser();
|
|
120
164
|
let dxf = parser.parse(data);
|
|
121
165
|
let entities = formatEntity(dxf.entities);
|
|
122
|
-
|
|
123
|
-
console.log(entities);
|
|
124
|
-
|
|
125
166
|
let layers = dxf.tables.layer.layers;
|
|
126
|
-
//加载图纸
|
|
127
|
-
|
|
128
|
-
console.log('layers');
|
|
129
|
-
console.log(layers);
|
|
130
167
|
|
|
131
168
|
for (let key in layers) {
|
|
132
169
|
if (entities[key]) {
|
|
133
170
|
let group = [];
|
|
134
171
|
let l = entities[key].length;
|
|
135
|
-
let layerConfig =
|
|
172
|
+
let layerConfig = layerConfigs[key];
|
|
136
173
|
let configParams =
|
|
137
174
|
layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
138
175
|
for (let i = 0; i < l; i++) {
|
|
@@ -145,7 +182,7 @@
|
|
|
145
182
|
key,
|
|
146
183
|
configParams,
|
|
147
184
|
konvaLayer,
|
|
148
|
-
|
|
185
|
+
layerConfigs
|
|
149
186
|
);
|
|
150
187
|
}
|
|
151
188
|
if (!konvaLayer) return;
|
|
@@ -163,7 +200,7 @@
|
|
|
163
200
|
name: key.replace(/\s*/g, ''),
|
|
164
201
|
entityId: key,
|
|
165
202
|
stroke: configParams ? configParams.color : '#000',
|
|
166
|
-
customColor: configParams ? configParams.color : '',
|
|
203
|
+
customColor: configParams ? configParams.color : '#000',
|
|
167
204
|
visible: configParams ? configParams.visible : true,
|
|
168
205
|
sceneFunc(context, shape) {
|
|
169
206
|
context.beginPath();
|
|
@@ -221,11 +258,10 @@
|
|
|
221
258
|
scale = Number((boundingRect.width / boundingRect.height).toFixed(1));
|
|
222
259
|
scale = scale < 2 ? 2 : scale;
|
|
223
260
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
})*/
|
|
261
|
+
konvaStage.scale({
|
|
262
|
+
x: scale,
|
|
263
|
+
y: scale,
|
|
264
|
+
})
|
|
229
265
|
const boundingScale = konvaLayer.getClientRect();
|
|
230
266
|
//平移视口
|
|
231
267
|
const x =
|
|
@@ -235,12 +271,13 @@
|
|
|
235
271
|
this.$refs.svgDraw.clientHeight / 2 -
|
|
236
272
|
(Math.ceil(boundingScale.height) / 2 + boundingScale.y);
|
|
237
273
|
|
|
238
|
-
konvaStage.scale({
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
konvaStage.setY(
|
|
274
|
+
// konvaStage.scale({
|
|
275
|
+
// x: 2,
|
|
276
|
+
// y: 2,
|
|
277
|
+
// });
|
|
278
|
+
konvaStage.setX(x);
|
|
279
|
+
konvaStage.setY(y); // 750
|
|
280
|
+
this.$emit('loaded')
|
|
244
281
|
},
|
|
245
282
|
toPdf(name) {
|
|
246
283
|
// get data URL with default settings
|
|
@@ -282,6 +319,72 @@
|
|
|
282
319
|
konvaLayer = null;
|
|
283
320
|
konvaStage = null;
|
|
284
321
|
},
|
|
322
|
+
getIntersects(rect) {
|
|
323
|
+
let l = konvaLayer.children.length;
|
|
324
|
+
let intersects = [];
|
|
325
|
+
for (let index = 0; index < l; index++) {
|
|
326
|
+
const ele = konvaLayer.children[index];
|
|
327
|
+
if (ele.attrs.name !== "intersect-rect") {
|
|
328
|
+
const boundingRect = ele.getClientRect();
|
|
329
|
+
if (
|
|
330
|
+
!(
|
|
331
|
+
rect.x + rect.width < boundingRect.x ||
|
|
332
|
+
boundingRect.x + boundingRect.width < rect.x ||
|
|
333
|
+
rect.y + rect.height < boundingRect.y ||
|
|
334
|
+
boundingRect.y + boundingRect.height < rect.y
|
|
335
|
+
)
|
|
336
|
+
) {
|
|
337
|
+
|
|
338
|
+
intersects.push(ele);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return intersects;
|
|
343
|
+
},
|
|
344
|
+
// 参数说明arr数组,每个元素为一个对象,对象包含id, color属性
|
|
345
|
+
highLight(arr) {
|
|
346
|
+
for (let index = 0; index < arr.length; index++) {
|
|
347
|
+
const element = arr[index];
|
|
348
|
+
let name = element.id.replace(/\s*/g, "")
|
|
349
|
+
let obj = konvaStage.find("." + name)
|
|
350
|
+
if (obj.length > 0) {
|
|
351
|
+
let lists = obj.filter((item) => !item.attrs.isGroup);
|
|
352
|
+
for (let i = 0; i < lists.length; i++) {
|
|
353
|
+
preTarget.push(lists[i]);
|
|
354
|
+
const ele = lists[i];
|
|
355
|
+
if (ele.className === "Text") {
|
|
356
|
+
ele.setFill(element.color);
|
|
357
|
+
ele.setStroke(element.color)
|
|
358
|
+
} else {
|
|
359
|
+
ele.setStroke(element.color);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
resetHighLight() {
|
|
366
|
+
for (let index = 0; index < preTarget.length; index++) {
|
|
367
|
+
const element = preTarget[index];
|
|
368
|
+
if (element.className === "Text") {
|
|
369
|
+
element.setFill(element.attrs.customColor);
|
|
370
|
+
element.setStroke(element.attrs.customColor)
|
|
371
|
+
} else {
|
|
372
|
+
element.setStroke(element.attrs.customColor);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
preTarget.splice(0);
|
|
376
|
+
},
|
|
377
|
+
// 居中定位
|
|
378
|
+
centering(id) {
|
|
379
|
+
let entityId = id.replace(/\s*/g, "");
|
|
380
|
+
let obj = konvaStage.find("." + entityId);
|
|
381
|
+
let scaleBy = 8;
|
|
382
|
+
if (obj.length > 0) {
|
|
383
|
+
konvaStage.scale({ x: scaleBy, y: scaleBy });
|
|
384
|
+
centering(obj, this.$refs.svgDraw, konvaStage, scaleBy)
|
|
385
|
+
obj = null;
|
|
386
|
+
}
|
|
387
|
+
},
|
|
285
388
|
beforeDestroy() {
|
|
286
389
|
this.clearCache();
|
|
287
390
|
},
|
|
@@ -119,11 +119,32 @@
|
|
|
119
119
|
this.initControl();
|
|
120
120
|
this.initLight();
|
|
121
121
|
this.initLabelRender();
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
// 判断是设备是手机还是电脑
|
|
123
|
+
let isMobileDevice = this.isMobileDevice();
|
|
124
|
+
if (isMobileDevice) {
|
|
125
|
+
renderer.domElement.addEventListener('pointerup', this.mouseClick, false);
|
|
126
|
+
renderer.domElement.addEventListener('pointerdown', this.mouseDown, false);
|
|
127
|
+
} else {
|
|
128
|
+
renderer.domElement.addEventListener('mouseup', this.mouseClick, false);
|
|
129
|
+
renderer.domElement.addEventListener('mousedown', this.mouseDown, false);
|
|
130
|
+
}
|
|
124
131
|
this.animate();
|
|
125
132
|
},
|
|
126
133
|
methods: {
|
|
134
|
+
// 判断是设备是手机还是电脑
|
|
135
|
+
isMobileDevice() {
|
|
136
|
+
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
|
|
137
|
+
if (/windows phone/i.test(userAgent)) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
if (/android/i.test(userAgent)) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
},
|
|
127
148
|
initRender() {
|
|
128
149
|
renderer = new this.THREE.WebGLRenderer({
|
|
129
150
|
antialias: true,
|
|
@@ -307,8 +328,15 @@
|
|
|
307
328
|
if (!measureFlag) {
|
|
308
329
|
lastTime = new Date().getTime();
|
|
309
330
|
if (lastTime - firstTime < 300) {
|
|
310
|
-
|
|
311
|
-
|
|
331
|
+
// 获取元素在页面中的偏移位置
|
|
332
|
+
const rect = renderer.domElement.getBoundingClientRect();
|
|
333
|
+
const x = event.clientX - rect.left;
|
|
334
|
+
const y = event.clientY - rect.top;
|
|
335
|
+
|
|
336
|
+
// mouse.x = (event.clientX / instructions.offsetWidth) * 2 - 1;
|
|
337
|
+
// mouse.y = -(event.clientY / instructions.offsetHeight) * 2 + 1;
|
|
338
|
+
mouse.x = (x / rect.width) * 2 - 1;
|
|
339
|
+
mouse.y = -(y / rect.height) * 2 + 1;
|
|
312
340
|
raycaster.setFromCamera(mouse, camera);
|
|
313
341
|
const intersects = raycaster.intersectObjects(scene.children, true);
|
|
314
342
|
let params = {};
|
|
@@ -443,8 +471,6 @@
|
|
|
443
471
|
});
|
|
444
472
|
break;
|
|
445
473
|
case 'opacity':
|
|
446
|
-
// obj.material.opacity = ele.attr[key];
|
|
447
|
-
// obj.material.transparent = true;
|
|
448
474
|
targetObj.forEach(children => {
|
|
449
475
|
if (children.isMesh) {
|
|
450
476
|
const opacity = children.geometry.attributes.opacity.array;
|
|
@@ -533,7 +559,6 @@
|
|
|
533
559
|
} else if (obj.isMesh) {
|
|
534
560
|
this.setModelCenter(obj.parent);
|
|
535
561
|
}
|
|
536
|
-
// cameraControls.fitToBox( obj, true);
|
|
537
562
|
}
|
|
538
563
|
},
|
|
539
564
|
// 根据自定义参数修改模型
|
|
@@ -1431,6 +1456,24 @@
|
|
|
1431
1456
|
}
|
|
1432
1457
|
scenePass = null;
|
|
1433
1458
|
},
|
|
1459
|
+
// 获取中心点
|
|
1460
|
+
getCenter(obj) {
|
|
1461
|
+
console.log(obj)
|
|
1462
|
+
let center = new this.THREE.Vector3();
|
|
1463
|
+
obj.boundingBox.getCenter(center);
|
|
1464
|
+
const mat4 = new this.THREE.Matrix4();
|
|
1465
|
+
mat4.makeRotationX(-Math.PI / 2);
|
|
1466
|
+
center.applyMatrix4(mat4)
|
|
1467
|
+
return center;
|
|
1468
|
+
},
|
|
1469
|
+
getSize(obj) {
|
|
1470
|
+
let size = new this.THREE.Vector3();
|
|
1471
|
+
obj.boundingBox.getSize(size);
|
|
1472
|
+
const mat4 = new this.THREE.Matrix4();
|
|
1473
|
+
mat4.makeRotationX(-Math.PI / 2);
|
|
1474
|
+
size.applyMatrix4(mat4)
|
|
1475
|
+
return size;
|
|
1476
|
+
},
|
|
1434
1477
|
animate() {
|
|
1435
1478
|
const delta = fpsClock.getDelta();
|
|
1436
1479
|
timeStamp += delta;
|
|
@@ -112,8 +112,8 @@ function handleInstancedMeshModel(
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
console.log('modelGroup', modelGroup);
|
|
116
|
-
console.log('drawObjMapInstance', drawObjMapInstance);
|
|
115
|
+
// console.log('modelGroup', modelGroup);
|
|
116
|
+
// console.log('drawObjMapInstance', drawObjMapInstance);
|
|
117
117
|
return modelGroup;
|
|
118
118
|
// timeRender();
|
|
119
119
|
// console.log('scene', scene)
|