From 75fb721ba216a37250651c97e72ae90f82f0db8d Mon Sep 17 00:00:00 2001
From: guoyujie <guoyujie@ng.com>
Date: 星期一, 15 十二月 2025 14:08:06 +0800
Subject: [PATCH] 修改文件上传既能上传dwg文件,又能上传图片文件
---
north-glass-erp/src/main/java/com/example/erp/controller/sd/OrderFileController.java | 8 ++
north-glass-erp/northglass-erp/src/lang/en.js | 1
north-glass-erp/northglass-erp/src/lang/ar.js | 1
north-glass-erp/northglass-erp/src/views/sd/order/CreateOrder.vue | 2
north-glass-erp/northglass-erp/src/components/sd/order/UploadPicture.vue | 30 ++++++---
north-glass-erp/northglass-erp/src/lang/ru.js | 2
north-glass-erp/src/main/java/com/example/erp/service/sd/OrderFileService.java | 79 +++++++++++++++++++-------
north-glass-erp/northglass-erp/src/lang/zh.js | 1
north-glass-erp/northglass-erp/src/lang/kr.js | 1
9 files changed, 89 insertions(+), 36 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 6e039b2..3095388 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
@@ -102,7 +102,7 @@
const loadSupportedFormats = async () => {
try {
if (fileList.value.length === 0) {
- ElMessage.warning('璇峰厛閫夋嫨瑕佷笂浼犵殑DWG鏂囦欢')
+ ElMessage.warning('璇峰厛閫夋嫨瑕佷笂浼犵殑DWG鏂囦欢鎴栧浘鐗囨枃浠�')
return
}
loadingFormats.value = true
@@ -120,9 +120,9 @@
}
}, 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') {
@@ -148,15 +148,26 @@
}
}
+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) => {
- console.log(file)
- if (!(file.raw.name.toLowerCase().endsWith('.dwg') )) {
+ const fileTypeCheckBoole = fileTypeCheck(file)
+ if (!(fileTypeCheckBoole )) {
//ElMessage.error('璇烽�夋嫨DWG鎴朌XF鏍煎紡鐨勬枃浠�')
- ElMessage.error('璇烽�夋嫨DWG鏍煎紡鐨勬枃浠�')
+ ElMessage.error('璇烽�夋嫨DWG鏂囦欢鎴朖PG銆丳NG鏍煎紡鐨勫浘鐗囨枃浠�')
uploadRef.value.clearFiles()
return
}
@@ -206,7 +217,7 @@
<div class="card-header">
<span class="header-title">
<el-icon><Document /></el-icon>
- DWG鏂囦欢涓婁紶
+ 鏂囦欢涓婁紶
</span>
</div>
@@ -224,16 +235,15 @@
: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>
+ 鎷栨嫿鏂囦欢鍒版澶勬垨 <em>鐐瑰嚮閫夋嫨鏂囦欢</em>
</div>
<template #tip>
<div class="el-upload__tip">
- 浠呮敮鎸� .dwg 鏍煎紡鏂囦欢锛屼笖鏂囦欢澶у皬涓嶈秴杩�50MB
+ 浠呮敮鎸� .dwg銆�.jpg銆�.png 鏍煎紡鏂囦欢锛屼笖鏂囦欢澶у皬涓嶈秴杩�50MB
</div>
</template>
</el-upload>
diff --git a/north-glass-erp/northglass-erp/src/lang/ar.js b/north-glass-erp/northglass-erp/src/lang/ar.js
index 9fec150..1411175 100644
--- a/north-glass-erp/northglass-erp/src/lang/ar.js
+++ b/north-glass-erp/northglass-erp/src/lang/ar.js
@@ -337,6 +337,7 @@
layer:'鍗曠墖妯″紡',
notFinish:'寰呭畬鎴�',
processCardCollect:'娴佺▼鍗℃眹鎬�',
+ fileUpload:'鏂囦欢涓婁紶'
},
searchOrder:{
diff --git a/north-glass-erp/northglass-erp/src/lang/en.js b/north-glass-erp/northglass-erp/src/lang/en.js
index 29f9e6e..8467d76 100644
--- a/north-glass-erp/northglass-erp/src/lang/en.js
+++ b/north-glass-erp/northglass-erp/src/lang/en.js
@@ -337,6 +337,7 @@
layer:'鍗曠墖妯″紡',
notFinish:'寰呭畬鎴�',
processCardCollect:'娴佺▼鍗℃眹鎬�',
+ fileUpload:'鏂囦欢涓婁紶'
},
searchOrder:{
diff --git a/north-glass-erp/northglass-erp/src/lang/kr.js b/north-glass-erp/northglass-erp/src/lang/kr.js
index c808376..02ef188 100644
--- a/north-glass-erp/northglass-erp/src/lang/kr.js
+++ b/north-glass-erp/northglass-erp/src/lang/kr.js
@@ -337,6 +337,7 @@
layer:'鍗曠墖妯″紡',
notFinish:'寰呭畬鎴�',
processCardCollect:'娴佺▼鍗℃眹鎬�',
+ fileUpload:'鏂囦欢涓婁紶'
},
searchOrder:{
diff --git a/north-glass-erp/northglass-erp/src/lang/ru.js b/north-glass-erp/northglass-erp/src/lang/ru.js
index 0acd315..7f63ec1 100644
--- a/north-glass-erp/northglass-erp/src/lang/ru.js
+++ b/north-glass-erp/northglass-erp/src/lang/ru.js
@@ -337,7 +337,7 @@
layer:'鍗曠墖妯″紡',
notFinish:'寰呭畬鎴�',
processCardCollect:'娴佺▼鍗℃眹鎬�',
-
+ fileUpload:'鏂囦欢涓婁紶'
},
searchOrder:{
createOrder:'袙褘锌懈褋邪褌褜 蟹邪泻邪蟹',
diff --git a/north-glass-erp/northglass-erp/src/lang/zh.js b/north-glass-erp/northglass-erp/src/lang/zh.js
index 06112dd..6baa5d0 100644
--- a/north-glass-erp/northglass-erp/src/lang/zh.js
+++ b/north-glass-erp/northglass-erp/src/lang/zh.js
@@ -337,6 +337,7 @@
layer:'鍗曠墖妯″紡',
notFinish:'寰呭畬鎴�',
processCardCollect:'娴佺▼鍗℃眹鎬�',
+ fileUpload:'鏂囦欢涓婁紶'
},
searchOrder:{
diff --git a/north-glass-erp/northglass-erp/src/views/sd/order/CreateOrder.vue b/north-glass-erp/northglass-erp/src/views/sd/order/CreateOrder.vue
index 0b6cb66..8987e37 100644
--- a/north-glass-erp/northglass-erp/src/views/sd/order/CreateOrder.vue
+++ b/north-glass-erp/northglass-erp/src/views/sd/order/CreateOrder.vue
@@ -139,7 +139,7 @@
{ code: 'updateOrderId', name: t('searchOrder.updateOrderId'), prefixIcon: 'vxe-icon-eye-fill', visible: true, disabled: false },
{ code: 'reportingTransfer', name: t('searchOrder.reportingTransfer'), prefixIcon: 'vxe-icon-send', visible: true, disabled: true },
{ code: 'uploadPicture', name: t('order.graphic'),prefixIcon: 'vxe-icon-picture-fill', visible: true, },
- { code: 'fileUpload', name: t('涓婁紶DWG鏂囦欢'),prefixIcon: 'vxe-icon-picture-fill', visible: true, }
+ { code: 'fileUpload', name: t('涓婁紶鏂囦欢'),prefixIcon: 'vxe-icon-picture-fill', visible: true, }
]
]
}
diff --git a/north-glass-erp/src/main/java/com/example/erp/controller/sd/OrderFileController.java b/north-glass-erp/src/main/java/com/example/erp/controller/sd/OrderFileController.java
index 37850f1..1094e5b 100644
--- a/north-glass-erp/src/main/java/com/example/erp/controller/sd/OrderFileController.java
+++ b/north-glass-erp/src/main/java/com/example/erp/controller/sd/OrderFileController.java
@@ -19,9 +19,13 @@
private final OrderFileService orderFileService;
@PostMapping("/updateOrderFileByOrderNumber/{orderId}/{orderNumber}")
- public Result updateOrderFileByOrderNumber(@RequestParam("file") MultipartFile file, @PathVariable String orderId, @PathVariable String orderNumber) throws IOException {
+ public Result updateOrderFileByOrderNumber(
+ @RequestParam("file") MultipartFile file,
+ @RequestParam("name") String name,
+ @PathVariable String orderId,
+ @PathVariable String orderNumber) throws IOException {
- return Result.success(orderFileService.updateOrderFileByOrderNumber(file,orderId,orderNumber));
+ return Result.success(orderFileService.updateOrderFileByOrderNumber(file,name,orderId,orderNumber));
}
@PostMapping("/getOrderFilePicture")
public Result getOrderFilePicture(@RequestBody List<Map<String,Object>> orderDetails) throws NoSuchFieldException {
diff --git a/north-glass-erp/src/main/java/com/example/erp/service/sd/OrderFileService.java b/north-glass-erp/src/main/java/com/example/erp/service/sd/OrderFileService.java
index 116db21..e15bb07 100644
--- a/north-glass-erp/src/main/java/com/example/erp/service/sd/OrderFileService.java
+++ b/north-glass-erp/src/main/java/com/example/erp/service/sd/OrderFileService.java
@@ -53,33 +53,45 @@
return orderFiles;
}
- public Object updateOrderFileByOrderNumber(MultipartFile file,String orderId,String orderNumber) throws IOException {
+ public Object updateOrderFileByOrderNumber(MultipartFile file,String name,String orderId,String orderNumber) throws IOException {
+ //鍒ゆ柇鏄惁瑙勫畾鐨勬牸寮忓悗缂�鍚�
+ if(!isAllowedFile(name)){
+ return null;
+ }
+
try (InputStream is = License.class.getResourceAsStream("/lisence.xml")) {
- License license = new License();
- license.setLicense(is);
+ String base64 = null;
+ if(name.toLowerCase().endsWith(".dwg")){
+
+ License license = new License();
+ license.setLicense(is);
- // 璋冪敤Image绫荤殑Load鏂规硶鏉ュ姞杞借緭鍏ョ殑DWG鏂囦欢銆�
- Image image = Image.load(file.getInputStream());
- // 鍒涘缓CadRasterizationOptions瀹炰緥浠ュ惎鐢–AD鏍呮牸鍖栭�夐」銆�
- CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
- // 璁剧疆瀹藉害
- rasterizationOptions.setPageWidth(1000);
- // 璁剧疆楂樺害
- rasterizationOptions.setPageHeight(700);
- // 璋冪敤杩欎釜setEmbedBackground鏂规硶鏉ヨ缃儗鏅壊鏄惁涓嶇瓑浜庤緭鍑烘牸寮忕殑榛樿鑳屾櫙鑹�
- //rasterizationOptions.setEmbedBackground(true);
- // 涓虹敓鎴愮殑鍥惧儚鍒涘缓涓�涓狿ngOptions鐨勫疄渚嬶紝骞跺皢鍏跺垎閰嶇粰ImageOptionsBase绫荤殑瀹炰緥銆�
- ImageOptionsBase options = new PngOptions();
- // 璋冪敤 setVectorRasterizationOptions 鏂规硶鏉ュ畾涔夊厜鏍呭寲閫夐」
- options.setVectorRasterizationOptions(rasterizationOptions);
+ // 璋冪敤Image绫荤殑Load鏂规硶鏉ュ姞杞借緭鍏ョ殑DWG鏂囦欢銆�
+ Image image = Image.load(file.getInputStream());
+ // 鍒涘缓CadRasterizationOptions瀹炰緥浠ュ惎鐢–AD鏍呮牸鍖栭�夐」銆�
+ CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
+ // 璁剧疆瀹藉害
+ rasterizationOptions.setPageWidth(1000);
+ // 璁剧疆楂樺害
+ rasterizationOptions.setPageHeight(700);
+ // 璋冪敤杩欎釜setEmbedBackground鏂规硶鏉ヨ缃儗鏅壊鏄惁涓嶇瓑浜庤緭鍑烘牸寮忕殑榛樿鑳屾櫙鑹�
+ //rasterizationOptions.setEmbedBackground(true);
+ // 涓虹敓鎴愮殑鍥惧儚鍒涘缓涓�涓狿ngOptions鐨勫疄渚嬶紝骞跺皢鍏跺垎閰嶇粰ImageOptionsBase绫荤殑瀹炰緥銆�
+ ImageOptionsBase options = new PngOptions();
+ // 璋冪敤 setVectorRasterizationOptions 鏂规硶鏉ュ畾涔夊厜鏍呭寲閫夐」
+ options.setVectorRasterizationOptions(rasterizationOptions);
- // 淇濆瓨鍒板瓧鑺傛祦
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- image.save(outputStream, options);
- byte[] imageBytes = outputStream.toByteArray();
- String base64 = "data:image/png;base64," + Base64.getEncoder().encodeToString(imageBytes);
+ // 淇濆瓨鍒板瓧鑺傛祦
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ image.save(outputStream, options);
+ byte[] imageBytes = outputStream.toByteArray();
+ base64 = "data:image/png;base64," + Base64.getEncoder().encodeToString(imageBytes);
+ }else{
+ base64 = "data:image/png;base64," + Base64.getEncoder().encodeToString(file.getBytes());
+ }
+
OrderFile orderFile = new OrderFile();
orderFile.setImageBase64(base64);
orderFile.setFileName(file.getName());
@@ -107,6 +119,10 @@
e.printStackTrace();
return null;
}
+
+
+
+
}
public Object getOrderNumberFile(String orderId, String orderNumber) {
@@ -122,4 +138,23 @@
.eq("order_number", orderNumber)
) > 0;
}
+
+ public static boolean isAllowedFile(String fileName) {
+ List<String> allowedExtensions = Arrays.asList(".dwg", ".png", ".jpg");
+ if (fileName == null || fileName.isEmpty()) {
+ return false;
+ }
+
+ String lowerFileName = fileName.toLowerCase();
+
+ for (String ext : allowedExtensions) {
+ if (!ext.startsWith(".")) {
+ ext = "." + ext;
+ }
+ if (lowerFileName.endsWith(ext)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
--
Gitblit v1.8.0