From 33dbc6a161554f3a897f9e9273feb4f2c1b47381 Mon Sep 17 00:00:00 2001
From: chenlu <1320612696@qq.com>
Date: 星期一, 15 十二月 2025 17:04:27 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10105/r/ERP_override
---
north-glass-erp/northglass-erp/src/components/sd/order/UploadPicture.vue | 233 ++++++++++++++++++++++++++++++++-------------------------
1 files changed, 130 insertions(+), 103 deletions(-)
diff --git a/north-glass-erp/northglass-erp/src/components/sd/order/UploadPicture.vue b/north-glass-erp/northglass-erp/src/components/sd/order/UploadPicture.vue
index 36e5585..7cb8bb5 100644
--- a/north-glass-erp/northglass-erp/src/components/sd/order/UploadPicture.vue
+++ b/north-glass-erp/northglass-erp/src/components/sd/order/UploadPicture.vue
@@ -2,11 +2,13 @@
import { ref, reactive, onMounted } from 'vue'
import {
Document, UploadFilled, MagicStick, RefreshLeft,
- Download, Plus, Picture, Refresh
+ Download, Plus, Picture, Refresh, Delete
} from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import request from "@/utils/requestByFile"
+import {useI18n} from "vue-i18n";
+const { t } = useI18n()
const uploadRef = ref()
const fileList = ref([])
const converting = ref(false)
@@ -16,9 +18,11 @@
const conversionResult = ref(null)
const supportedFormats = ref(['png', 'jpg', 'jpeg', 'bmp'])
const loadingFormats = ref(false)
+let result = ref(null)
let props = defineProps({
rowIndex:null,
- orderId:null
+ orderId:null,
+ state:null
})
const form = reactive({
@@ -26,15 +30,81 @@
})
onMounted(() => {
- //loadSupportedFormats()
+ getFileList()
})
+const getFileList = async () => {
+ request.post(`/orderFile/getOrderNumberFile/${props.orderId}/${props.rowIndex.orderNumber}`).then(res=>{
+ if(res.data===null){
+ return
+ }
+ result.value = res.data
+ conversionResult.value = res.data.imageBase64
+ })
+}
+
+const deleteFile = async () => {
+ request.post(`/orderFile/deleteOrderNumberFile/${props.orderId}/${props.rowIndex.orderNumber}`).then(res=>{
+ result.value = null
+ conversionResult.value = null
+ ElMessage.success(t("basicData.msg.deleteSuccess"))
+ })
+}
+
+const downloadFile = () => {
+ try {
+ // 绉婚櫎瀛楃涓蹭腑鐨勬柟鎷彿鍜岀┖鏍�
+ const cleanString = result.value.fileData.replace(/[\[\]\s]/g, '');
+
+ // 濡傛灉瀛楃涓蹭负绌猴紝杩斿洖绌虹殑Uint8Array
+ if (!cleanString) {
+ return new Uint8Array();
+ }
+
+ // 鍒嗗壊瀛楃涓插苟杞崲涓烘暟瀛楁暟缁�
+ const byteStrings = cleanString.split(',');
+ const bytes = byteStrings.map(byteStr => {
+ // 灏嗗瓧绗︿覆杞崲涓烘暟瀛楋紙澶勭悊璐熸暟锛�
+ let value = parseInt(byteStr, 10);
+
+ // Java瀛楄妭鏄湁绗﹀彿鐨�(-128鍒�127)锛岄渶瑕佽浆鎹负鏃犵鍙�(0鍒�255)
+ if (value < 0) {
+ value = 256 + value;
+ }
+
+ return value;
+ });
+
+ const uint8Array = new Uint8Array(bytes);
+ const file = new File([uint8Array], `${props.orderId}-${props.rowIndex.orderNumber}.dwg`, { type:'application/x-dwg' })
+
+ const url = URL.createObjectURL(file);
+ // 鍒涘缓涓嬭浇閾炬帴
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = file.name;
+ a.style.display = 'none';
+
+ // 娣诲姞鍒癉OM骞惰Е鍙戠偣鍑�
+ document.body.appendChild(a);
+ a.click();
+
+ // 娓呯悊璧勬簮
+ setTimeout(() => {
+ document.body.removeChild(a);
+ URL.revokeObjectURL(url);
+ }, 100);
+ } catch (error) {
+ console.error('瑙f瀽Java瀛楄妭鏁扮粍瀛楃涓叉椂鍑洪敊:', error);
+ throw new Error('鏃犳晥鐨凧ava瀛楄妭鏁扮粍鏍煎紡');
+ }
+}
const loadSupportedFormats = async () => {
try {
if (fileList.value.length === 0) {
- ElMessage.warning('璇峰厛閫夋嫨瑕佷笂浼犵殑DWG鏂囦欢')
+ ElMessage.warning(t("order.msg.pleaseUploadPicture1"))
return
}
loadingFormats.value = true
@@ -42,28 +112,29 @@
converting.value = true
progressPercentage.value = 0
progressStatus.value = ''
- progressText.value = '鍑嗗涓婁紶...'
+ progressText.value = t("order.msg.pleaseUploadPicture2")
// 妯℃嫙杩涘害鏇存柊
const progressInterval = setInterval(() => {
if (progressPercentage.value < 80) {
progressPercentage.value += 10
- progressText.value = `涓婁紶涓�... ${progressPercentage.value}%`
+ progressText.value = t("order.msg.pleaseUploadPicture3")+progressPercentage.value+'%'
}
}, 500)
-
const data ={
- file:fileList.value[0].raw
+ file:fileList.value[0].raw,
+ name:fileList.value[0].raw.name
}
request.post(`/orderFile/updateOrderFileByOrderNumber/${props.orderId}/${props.rowIndex.orderNumber}`,data).then(res=>{
if (res.code === '200') {
- conversionResult.value = res.data
+ result.value = res.data
+ conversionResult.value = res.data.imageBase64
uploadRef.value.clearFiles()
clearInterval(progressInterval)
progressPercentage.value = 100
progressStatus.value = 'success'
- progressText.value = '涓婁紶瀹屾垚!'
+ progressText.value = t("order.msg.pleaseUploadPicture4")
uploadRef.value.clearFiles()
fileList.value = []
setTimeout(() => {
@@ -73,106 +144,54 @@
}
})
} catch (error) {
- console.error('淇濆瓨澶辫触:', error)
+ ElMessage.error(t("order.msg.pleaseUploadPicture5"))
} finally {
loadingFormats.value = false
}
}
+const fileTypeCheck = (file) => {
+ const fileName = file.raw.name.toLowerCase();
+ switch (true) {
+ case /\.dwg$/.test(fileName):
+ case /\.png$/.test(fileName):
+ case /\.jpg$/.test(fileName):
+ return true;
+ default:
+ return false;
+ }
+};
const handleFileChange = (file) => {
- if (!(file.raw.name.toLowerCase().endsWith('.dwg') || file.raw.name.toLowerCase().endsWith('.dxf'))) {
- ElMessage.error('璇烽�夋嫨DWG鎴朌XF鏍煎紡鐨勬枃浠�')
+ const fileTypeCheckBoole = fileTypeCheck(file)
+ if (!(fileTypeCheckBoole )) {
+ //ElMessage.error('璇烽�夋嫨DWG鎴朌XF鏍煎紡鐨勬枃浠�')
+ ElMessage.error(t("order.msg.pleaseUploadPicture6"))
uploadRef.value.clearFiles()
return
}
if (file.raw.size > 50 * 1024 * 1024) {
- ElMessage.error('鏂囦欢澶у皬涓嶈兘瓒呰繃50MB')
+ ElMessage.error(t("order.msg.pleaseUploadPicture7"))
uploadRef.value.clearFiles()
return
}
fileList.value = [file]
- ElMessage.success(`宸查�夋嫨鏂囦欢: ${file.name}`)
+ ElMessage.success(t("order.msg.pleaseUploadPicture8")+file.name)
}
const handleFileRemove = () => {
conversionResult.value = null
+ result.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()
@@ -182,6 +201,7 @@
progressStatus.value = ''
progressText.value = ''
form.format = 'png'
+ result.value = null
}
const formatFileSize = (bytes) => {
@@ -199,13 +219,15 @@
<div class="card-header">
<span class="header-title">
<el-icon><Document /></el-icon>
- DWG鏂囦欢涓婁紶
+ {{$t("order.msg.pleaseUploadPicture9")}}
</span>
+
</div>
</template>
<!-- 鏂囦欢涓婁紶鍖哄煙 -->
<el-upload
+ v-if="!conversionResult"
ref="uploadRef"
class="upload-demo"
drag
@@ -215,49 +237,49 @@
: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>
+ {{$t("order.msg.pleaseUploadPicture10")}} <em>{{$t("order.msg.pleaseUploadPicture11")}}</em>
</div>
<template #tip>
<div class="el-upload__tip">
- 浠呮敮鎸� .dwg 鏍煎紡鏂囦欢锛屼笖鏂囦欢澶у皬涓嶈秴杩�50MB
+ {{$t("order.msg.pleaseUploadPicture12")}}
</div>
</template>
</el-upload>
<!-- 涓婁紶閫夐」 -->
- <div class="conversion-options">
+ <div v-if="!conversionResult" class="conversion-options">
<div class="action-buttons">
<el-button
type="primary"
:loading="converting"
@click="loadSupportedFormats"
- :disabled="!form.format"
+ :disabled="!form.format || props.state !== 1 || converting"
>
<template #icon>
<el-icon><MagicStick /></el-icon>
</template>
- 淇濆瓨
+ {{$t("basicData.save")}}
</el-button>
<el-button @click="handleReset"
- :loading="converting">
+ :loading="converting"
+ :disabled="props.state !== 1 || converting">
<template #icon>
<el-icon><RefreshLeft /></el-icon>
</template>
- 閲嶇疆
+ {{$t("craft.reset")}}
</el-button>
</div>
</div>
<!-- 杞崲杩涘害 -->
<div v-if="converting" class="conversion-progress">
- <el-divider content-position="left">涓婁紶杩涘害</el-divider>
+ <el-divider content-position="left">{{$t("order.msg.pleaseUploadPicture13")}}</el-divider>
<el-progress
:percentage="progressPercentage"
:status="progressStatus"
@@ -270,14 +292,15 @@
<!-- 杞崲缁撴灉 -->
<div v-if="conversionResult" class="conversion-result">
- <el-divider content-position="left">涓婁紶缁撴灉</el-divider>
+ <el-divider content-position="left">{{$t("order.msg.pleaseUploadPicture14")}}</el-divider>
<el-result
icon="success"
- :sub-title="`鏂囦欢宸叉垚鍔熻浆鏍煎紡`"
+ :sub-title='t("order.msg.pleaseUploadPicture15")'
>
<template #extra>
<div class="result-content">
+
<!-- 鍥剧墖棰勮 -->
<div class="image-preview">
<el-image
@@ -293,26 +316,30 @@
<!-- </div>-->
<!-- </template>-->
</el-image>
+
</div>
<!-- 鎿嶄綔鎸夐挳 -->
-<!-- <div class="result-actions">
+ <div class="result-actions">
<el-button
+ @click='downloadFile'
type="primary"
- @click="handleDownload"
- :icon="Download"
- >
- 涓嬭浇鍥剧墖
+ ><template #icon>
+ <el-icon><Download/></el-icon>
+ </template>
+ {{$t("order.msg.pleaseUploadPicture16")}}
</el-button>
<el-button
- @click="handleNewConversion"
- :icon="Plus"
- >
- 鏂扮殑涓婁紶
+ @click = 'deleteFile'
+ :disabled="props.state !== 1"
+ ><template #icon>
+ <el-icon><Delete /></el-icon>
+ </template>
+ {{$t("basicData.delete")}}
</el-button>
- </div>-->
+ </div>
</div>
</template>
</el-result>
--
Gitblit v1.8.0