廖井涛
2025-08-21 6c09c62de88b8c2ba4a2c10c542746b1c8943984
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<script setup>
import {computed, onMounted, onUpdated, reactive, ref, watch} from "vue"
import {filterChanged} from "@/hook"
import {useI18n} from "vue-i18n"
import {ElMessage, ElMessageBox,} from "element-plus"
import request from "@/utils/request"
import {useRouter,useRoute} from "vue-router"
import {Ellipse, Leafer, Line, Path, Polygon} from "leafer-ui";
import {round} from "xe-utils";
import DxfParser from "dxf-parser";
import { saveAs } from 'file-saver';
import DXFWriter from 'dxf-writer';
 
 
const { t } = useI18n()
const router = useRouter()
const route = useRoute()
let width = ref("")
let height = ref("null")
let rowIndex = ref(null)
const xGrid = ref()
 
 
 
let fileName=ref(null)
let fileDate=ref(null)
let dxfData=ref(null)
let state=ref(false)
let points=ref([])
let data1=ref(0);let data2=ref(0);let data3=ref(0);let data4=ref(0)
let data5=ref(0);let data6=ref(0);let data7=ref(0);let data8=ref(0)
 
let datas1=ref(0);let datas2=ref(0);let datas3=ref(0);let datas4=ref(0)
let datas5=ref(0);let datas6=ref(0);let datas7=ref(0);let datas8=ref(0)
let big=0
let leafer;
let parsedDXFData = ref([]);
let orderDetailWidth=ref(0)
let orderDetailHeight=ref(0)
let widthAgv=ref(0)
let heightAgv=ref(0)
 
const ongetprojectOrder = (row) => {
  if(row==undefined||row.width==null){
    const main = document.getElementById('main2')
    const width = document.getElementById('width2')
    const height = document.getElementById('height2')
    main.style.backgroundColor = "#ffffff"
    width.innerHTML = 0
    height.innerHTML = 0
    if (leafer !== undefined) {
      leafer.clear()
    }
    return
  }
 
  if (row.fileName == null || row.fileName == "") {
    orderDetailWidth.value = row.width
    orderDetailHeight.value = row.height
    const main = document.getElementById('main2')
    const width = document.getElementById('width2')
    const height = document.getElementById('height2')
    if (orderDetailWidth.value / 400 > orderDetailHeight.value / 200) {
      big = orderDetailWidth.value / 400
    } else {
      big = orderDetailHeight.value / 200
    }
    let widthAgv = orderDetailWidth.value / big
    let heightAgv = orderDetailHeight.value / big
    main.style.width = widthAgv + "px"
    main.style.height = heightAgv + "px"
    main.style.backgroundColor = "#8d9095"
    width.innerHTML = orderDetailWidth.value
    height.innerHTML = orderDetailHeight.value
    datas2.value = heightAgv
    datas8.value = heightAgv
    datas5.value = widthAgv
    datas7.value = widthAgv
    if (leafer !== undefined) {
      leafer.clear()
    }
    leafer = new Leafer({view: 'canva2'})
    points.value = [0, heightAgv, 0, 0, widthAgv, 0, widthAgv, heightAgv]
    const polygon = new Polygon({
      points: points.value,
      stroke: '#f00',
      origin: [0, 0]
    })
    setTimeout(() => {
      leafer.add(polygon);
    }, 30)
    state.value = true
  } else {
    const b64Data = row.fileData;
    const byteCharacters = atob(b64Data);
    const parser = new DxfParser();
    dxfData.value = parser.parseSync(byteCharacters)
    state.value = false
    handleFileUpload()
  }
}
 
 
  function toBottomOrigin(y, canvasHeight) {
    return canvasHeight - y; // 将左上角Y坐标转换为左下角坐标系
  }
 
 
  const handleFileUpload = () => {
    const main = document.getElementById('main2')
    const width = document.getElementById('width2')
    const height = document.getElementById('height2')
    if (leafer !== undefined) {
      leafer.clear()
    }
    leafer = new Leafer({view: 'canva2'});
    try {
      let type = 0;
      let minX = Infinity, minY = Infinity;
      let maxX = -Infinity, maxY = -Infinity;
      dxfData.value.entities.forEach(entity => {
        if (entity.type === 'LINE' || entity.type === 'LWPOLYLINE') {
          entity.vertices.forEach(vertices => {
            minX = Math.min(vertices.x, minX);
            minY = Math.min(vertices.y, minY);
            maxX = Math.max(vertices.x, maxX);
            maxY = Math.max(vertices.y, maxY);
          })
        }
        if (entity.type === 'ARC') {
          type = 1
          const center = {x: entity.center.x, y: entity.center.y};
          const radius = entity.radius;
          const startAngle = entity.startAngle * (180 / Math.PI);
          const endAngle = entity.endAngle * (180 / Math.PI);
 
          const points = [];
          const steps = 32;
          for (let i = 0; i <= steps; i++) {
            const angle = startAngle + (endAngle - startAngle) * (i / steps);
            const x = center.x + radius * Math.cos(angle * Math.PI / 180);
            const y = center.y + radius * Math.sin(angle * Math.PI / 180);
            points.push({x, y});
          }
 
 
          points.forEach(p => {
            minX = Math.min(minX, p.x);
            minY = Math.min(minY, p.y);
            maxX = Math.max(maxX, p.x);
            maxY = Math.max(maxY, p.y);
          });
        }
        if (entity.type === 'CIRCLE') {
          type = 1
          minX = Math.min(minX, entity.center.x - entity.radius);
          minY = Math.min(minY, entity.center.y - entity.radius);
          maxX = Math.max(maxX, entity.center.x + entity.radius);
          maxY = Math.max(maxY, entity.center.y + entity.radius);
        }
      });
      if ((maxX - minX) / 400 > (maxY - minY) / 200) {
        big = (maxX - minX) / 400
      } else {
        big = (maxY - minY) / 200
      }
 
      Object.values(dxfData.value.entities).forEach(entity => {
        switch (entity.type) {
          case 'LINE':
            main.style.width = (maxX - minX) / big + "px"
            main.style.height = (maxY - minY) / big + "px"
            main.style.backgroundColor = "#8d9095"
            width.innerHTML = round(maxX - minX, 2)
            height.innerHTML = round(maxY - minY, 2)
            const line = new Line({
              points: [(entity.vertices[0].x - minX) / big, ((maxY - minY) - (entity.vertices[0].y - minY)) / big,
                (entity.vertices[1].x - minX) / big, ((maxY - minY) - (entity.vertices[1].y - minY)) / big],
              stroke: '#f00',
              strokeWidth: 1
            })
            setTimeout(() => {
              leafer.add(line);
            }, 30);
            break;
          case 'LWPOLYLINE':
 
            main.style.width = (maxX - minX) / big + "px"
            main.style.height = (maxY - minY) / big + "px"
            main.style.backgroundColor = "#8d9095"
            width.innerHTML = round(maxX - minX, 2)
            height.innerHTML = round(maxY - minY, 2)
 
            let point = entity.vertices.map(v => [
              (v.x - minX) / big,
              toBottomOrigin((v.y - minY) / big, (maxY - minY) / big),
            ]).flat()
 
 
 
              const polygon = new Polygon({
                points: point,
                stroke: '#f00'
              })
              setTimeout(() => {
                leafer.add(polygon);
              }, 30);
 
 
 
            break;
          case 'CIRCLE':
            let CIRCLEX = (entity.center.x - minX - entity.radius) / big
            let CIRCLEY = ((maxY - minY) - (entity.center.y - minY + entity.radius)) / big
            if (big < (entity.radius * 2) / 400) {
              big = (entity.radius * 2) / 400
              main.style.width = entity.radius * 2 / big + "px"
              main.style.height = entity.radius * 2 / big + "px"
              width.innerHTML = round(entity.radius * 2, 2)
              height.innerHTML = round(entity.radius * 2, 2)
              CIRCLEX = 0
              CIRCLEY = 0
            }
 
            const ellipse = new Ellipse({
              x: CIRCLEX,
              y: CIRCLEY,
              width: entity.radius * 2 / big,
              height: entity.radius * 2 / big,
              //fill: "#32cd79"
              stroke: '#f00',
            })
            setTimeout(() => {
              leafer.add(ellipse);
            }, 30);
 
            break;
          case 'ELLIPSE':
            console.log(entity)
 
            const {majorAxisEndPoint, axisRatio} = entity;
 
            const dx = majorAxisEndPoint.x;
            const dy = majorAxisEndPoint.y;
            const a = Math.sqrt(dx ** 2 + dy ** 2);
            const c = a * axisRatio;
            const θ = Math.atan2(dy, dx);
            const l = axisRatio * (180 / Math.PI);
 
            if ((a * 2) / 400 > (c * 2) / 200) {
              big = (a * 2) / 400
            } else {
              big = (c * 2) / 200
            }
 
            main.style.width = a * 2 / big + "px"
            main.style.height = c * 2 / big + "px"
            width.innerHTML = round(a * 2, 2)
            height.innerHTML = round(c * 2, 2)
            const ellipse2 = new Ellipse({
              width: a * 2 / big,
              height: c * 2 / big,
              stroke: '#f00',
            })
 
            setTimeout(() => {
              leafer.add(ellipse2);
            }, 30);
 
            break;
          case 'ARC':
            const center = {x: entity.center.x, y: entity.center.y};
            const radius = entity.radius;
            const startAngle = entity.startAngle * (180 / Math.PI);
            const endAngle = entity.endAngle * (180 / Math.PI);
 
            if ((maxX - minX) / 400 > (maxY - minY) / 200) {
              big = (maxX - minX) / 400
            } else {
              big = (maxY - minY) / 200
            }
 
 
            // 计算圆弧的起点和终点
            const startX = (center.x + radius * Math.cos(entity.startAngle) - minX);
            const startY = (maxY - minY) - ((center.y + radius * Math.sin(entity.startAngle)) - minY);
            const endX = (center.x + radius * Math.cos(entity.endAngle) - minX);
            const endY = (maxY - minY) - ((center.y + radius * Math.sin(entity.endAngle)) - minY);
 
            // 创建圆弧路径
            const path = new Path({
              path: `M ${startX / big} ${startY / big} A ${radius / big} ${radius / big} 0 ${endAngle - startAngle > 180 ? 1 : 0} 0 ${endX / big} ${endY / big}`,
              stroke: '#f00',
              strokeWidth: 1,
            });
 
 
            setTimeout(() => {
              leafer.add(path);
            }, 30);
 
 
            break;
 
        }
      })
    } catch (error) {
      console.error('解析DXF文件时出错:', error);
    }
 
  };
 
  const validate = async () => {
    data1.value = 0
    data2.value = 0
    data3.value = 0
    data4.value = 0
    data5.value = 0
    data6.value = 0
    data7.value = 0
    data8.value = 0
    big = 0
    return true
  }
 
defineExpose({
  validate,
  ongetprojectOrder
})
 
 
 
 
 
 
</script>
 
<template>
  <div style="width: 404px;height: 204px;border: 2px solid #000;float: left;
              position: relative;display: flex;justify-content: center;align-content: center;margin-left: 80px;margin-top: 10px;">
    <div id="main2" ref="parent"  >
      <canvas  id="canva2" ></canvas>
    </div>
  </div>
  <div id="width2" style="height: 20px;position: absolute;top: -8px;left: 250px;">{{orderDetailWidth}}</div>
  <div id="height2" style="width: 60px;position: absolute;top: 95px;left: 20px;">{{orderDetailHeight}}</div>
 
 
 
 
 
</template>
 
<style scoped>
.contactNumber{
  width: 60px;
  height:20px;
  border: none;
  box-shadow: none;
  font-size: 15px;
}
.custom-file-upload {
  border: 1px solid #ccc;
  display: inline-block;
  padding: 6px 12px;
  cursor: pointer;
  background-color: #f9f9f9;
}
 
#mains {
  position: relative;
}
</style>