index.vue
1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!--
* @Description:
* @Autor: renchao
* @LastEditTime: 2023-09-18 14:06:16
-->
<template>
<div style="width:100%;height:100%;">
<canvas id="mxcad" style="width:100%;height:100%;">
</canvas>
</div>
</template>
<script>
import Mx from "mxdraw"
export default {
mounted () {
// 动态加载 js库核心代码
Mx.loadCoreCode().then(() => {
// Mx.MxFun.setMxServer("ws://localhost:5090") // 开启socket通信 可编辑图纸
// 创建控件对象
Mx.MxFun.createMxObject({
canvasId: "mxcad", // canvas元素的id
cadFile: "buf/hhhh.dwg", // http方式(预览): 加载public/demo文件夹下转换后的图纸
callback: (mxDraw, {
canvas,
canvasParent
}) => {
// 可以拿到canvas元素和它的父级元素
// 拿到图层数据
mxDraw.addEvent('uiSetLayerData', (listLayer) => {
console.log(listLayer)
})
},
isNewFile: true // 是否新建文件
})
})
},
}
</script>
<style scoped lang="scss">
#mxcad {
pointer-events: none;
}
</style>