guoyujie
2025-11-10 37bb2aac6fe2d856f06ff447d26163422c56024a
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
<script setup>
import { ref, reactive, onMounted } from 'vue'
import {
  Document, UploadFilled, MagicStick, RefreshLeft,
  Download, Plus, Picture, Refresh
} from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import request from "@/utils/requestByFile"
 
const uploadRef = ref()
const fileList = ref([])
const converting = ref(false)
const progressPercentage = ref(0)
const progressStatus = ref('')
const progressText = ref('')
const conversionResult = ref(null)
const supportedFormats = ref(['png', 'jpg', 'jpeg', 'bmp'])
const loadingFormats = ref(false)
let props = defineProps({
  rowIndex:null,
  orderId:null
})
 
const form = reactive({
  format: 'png'
})
 
onMounted(() => {
  //loadSupportedFormats()
})
 
 
 
const loadSupportedFormats = async () => {
  try {
    if (fileList.value.length === 0) {
      ElMessage.warning('请先选择要上传的DWG文件')
      return
    }
    loadingFormats.value = true
 
    converting.value = true
    progressPercentage.value = 0
    progressStatus.value = ''
    progressText.value = '准备上传...'
 
    // 模拟进度更新
    const progressInterval = setInterval(() => {
      if (progressPercentage.value < 80) {
        progressPercentage.value += 10
        progressText.value = `上传中... ${progressPercentage.value}%`
      }
    }, 500)
 
 
    const data ={
      file:fileList.value[0].raw
    }
    request.post(`/orderFile/updateOrderFileByOrderNumber/${props.orderId}/${props.rowIndex.orderNumber}`,data).then(res=>{
      if (res.code === '200') {
        conversionResult.value = res.data
        uploadRef.value.clearFiles()
        clearInterval(progressInterval)
        progressPercentage.value = 100
        progressStatus.value = 'success'
        progressText.value = '上传完成!'
        uploadRef.value.clearFiles()
        fileList.value = []
        setTimeout(() => {
 
          converting.value = false
        },2000)
      }
    })
  } catch (error) {
    console.error('保存失败:', error)
  } finally {
    loadingFormats.value = false
  }
}
 
 
 
 
 
const handleFileChange = (file) => {
  if (!(file.raw.name.toLowerCase().endsWith('.dwg') || file.raw.name.toLowerCase().endsWith('.dxf'))) {
    ElMessage.error('请选择DWG或DXF格式的文件')
    uploadRef.value.clearFiles()
    return
  }
 
  if (file.raw.size > 50 * 1024 * 1024) {
    ElMessage.error('文件大小不能超过50MB')
    uploadRef.value.clearFiles()
    return
  }
  fileList.value = [file]
  ElMessage.success(`已选择文件: ${file.name}`)
}
 
const handleFileRemove = () => {
  conversionResult.value = null
  uploadRef.value.clearFiles()
}
 
/*const handleConvert = async () => {
  if (fileList.value.length === 0) {
    ElMessage.warning('请先选择要上传的DWG文件')
    return
  }
 
  if (!form.format) {
    ElMessage.warning('请选择输出格式')
    return
  }
 
  try {
    converting.value = true
    progressPercentage.value = 0
    progressStatus.value = ''
    progressText.value = '准备转换...'
 
    // 模拟进度更新
    const progressInterval = setInterval(() => {
      if (progressPercentage.value < 80) {
        progressPercentage.value += 10
        progressText.value = `转换中... ${progressPercentage.value}%`
      }
    }, 500)
 
    const file = fileList.value[0].raw
    //const response = await cadApi.convertDwgToImage(file, form.format)
    const response = null
    clearInterval(progressInterval)
    progressPercentage.value = 100
    progressStatus.value = 'success'
    progressText.value = '转换完成!'
 
    conversionResult.value = response.data
 
    ElMessage.success('文件转换成功!')
 
  } catch (error) {
    progressStatus.value = 'exception'
    progressText.value = '转换失败'
    console.error('转换失败:', error)
  } finally {
    converting.value = false
  }
}*/
 
const handleDownload = () => {
  if (!conversionResult.value) return
 
  const link = document.createElement('a')
  link.href = conversionResult.value.imageData
  link.download = conversionResult.value.fileName
  document.body.appendChild(link)
  link.click()
  document.body.removeChild(link)
 
  ElMessage.success('文件下载开始')
}
 
const handleNewConversion = () => {
  ElMessageBox.confirm('是否开始新的文件上传?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
  }).then(() => {
    handleReset()
    ElMessage.success('已重置,可以开始新的上传')
  })
}
 
const handleReset = () => {
  uploadRef.value.clearFiles()
  fileList.value = []
  conversionResult.value = null
  progressPercentage.value = 0
  progressStatus.value = ''
  progressText.value = ''
  form.format = 'png'
}
 
const formatFileSize = (bytes) => {
  if (bytes === 0) return '0 Bytes'
  const k = 1024
  const sizes = ['Bytes', 'KB', 'MB', 'GB']
  const i = Math.floor(Math.log(bytes) / Math.log(k))
  return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
}
</script>
<template>
  <div class="file-upload-container">
    <el-card class="upload-card" shadow="hover">
      <template #header>
        <div class="card-header">
          <span class="header-title">
            <el-icon><Document /></el-icon>
            DWG文件上传
          </span>
        </div>
      </template>
 
      <!-- 文件上传区域 -->
      <el-upload
          ref="uploadRef"
          class="upload-demo"
          drag
          action=""
          :auto-upload="false"
          :on-change="handleFileChange"
          :on-remove="handleFileRemove"
          :file-list="fileList"
          :limit="1"
          :accept="'.dwg' || '.dxf' "
          :disabled="converting"
      >
        <el-icon class="el-icon--upload"><UploadFilled /></el-icon>
        <div class="el-upload__text">
          拖拽DWG文件到此处或 <em>点击选择文件</em>
        </div>
        <template #tip>
          <div class="el-upload__tip">
            仅支持 .dwg 格式文件,且文件大小不超过50MB
          </div>
        </template>
      </el-upload>
 
      <!-- 上传选项 -->
      <div  class="conversion-options">
 
        <div class="action-buttons">
          <el-button
              type="primary"
              :loading="converting"
              @click="loadSupportedFormats"
              :disabled="!form.format"
          >
            <template #icon>
              <el-icon><MagicStick /></el-icon>
            </template>
            保存
          </el-button>
 
          <el-button @click="handleReset"
                     :loading="converting">
            <template #icon>
              <el-icon><RefreshLeft /></el-icon>
            </template>
            重置
          </el-button>
        </div>
      </div>
 
      <!-- 转换进度 -->
      <div v-if="converting" class="conversion-progress">
        <el-divider content-position="left">上传进度</el-divider>
        <el-progress
            :percentage="progressPercentage"
            :status="progressStatus"
            :stroke-width="8"
        />
        <div class="progress-text">
          {{ progressText }}
        </div>
      </div>
 
      <!-- 转换结果 -->
      <div v-if="conversionResult" class="conversion-result">
        <el-divider content-position="left">上传结果</el-divider>
 
        <el-result
            icon="success"
            :sub-title="`文件已成功转格式`"
        >
          <template #extra>
            <div class="result-content">
              <!-- 图片预览 -->
              <div class="image-preview">
                <el-image
                    :src="conversionResult"
                    :preview-src-list="[conversionResult]"
                    fit="contain"
                    style="max-height: 600px;"
                >
<!--                  <template #error>-->
<!--                    <div class="image-slot">-->
<!--                      <el-icon><Picture /></el-icon>-->
<!--                      <div>图片加载失败</div>-->
<!--                    </div>-->
<!--                  </template>-->
                </el-image>
              </div>
 
 
 
              <!-- 操作按钮 -->
<!--              <div class="result-actions">
                <el-button
                    type="primary"
                    @click="handleDownload"
                    :icon="Download"
                >
                  下载图片
                </el-button>
                <el-button
                    @click="handleNewConversion"
                    :icon="Plus"
                >
                  新的上传
                </el-button>
              </div>-->
            </div>
          </template>
        </el-result>
      </div>
    </el-card>
  </div>
</template>
 
 
 
<style scoped>
.file-upload-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}
 
.upload-card {
  min-height: 600px;
}
 
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
 
.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: bold;
}
 
:deep(.upload-demo) {
  width: 100%;
}
 
:deep(.el-upload-dragger) {
  width: 100%;
  padding: 40px;
}
 
.conversion-options {
  margin-top: 20px;
}
 
.action-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}
 
.conversion-progress {
  margin-top: 20px;
}
 
.progress-text {
  text-align: center;
  margin-top: 8px;
  color: #666;
  font-size: 14px;
}
 
.conversion-result {
  margin-top: 20px;
}
 
.result-content {
  text-align: center;
}
 
.image-preview {
  margin: 20px 0;
  display: flex;
  justify-content: center;
}
 
.file-info {
  margin: 20px 0;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}
 
.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}
 
.image-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: #909399;
}
 
.image-slot .el-icon {
  font-size: 48px;
  margin-bottom: 16px;
}
</style>