From 24d2936224f216590300fa4619c83eec3b698c05 Mon Sep 17 00:00:00 2001 From: sbx0 Date: Fri, 12 Jan 2024 18:13:50 +0800 Subject: [PATCH] better image ui --- .../todo/business/file/FileController.java | 4 ++ .../main/java/cn/sbx0/todo/utils/JSON.java | 7 +++- todo-web/app/file/components/image/image.jsx | 13 ++++--- .../app/file/components/upload/upload.jsx | 39 +++++-------------- 4 files changed, 27 insertions(+), 36 deletions(-) diff --git a/todo-service/src/main/java/cn/sbx0/todo/business/file/FileController.java b/todo-service/src/main/java/cn/sbx0/todo/business/file/FileController.java index a8d613e..9db0a06 100644 --- a/todo-service/src/main/java/cn/sbx0/todo/business/file/FileController.java +++ b/todo-service/src/main/java/cn/sbx0/todo/business/file/FileController.java @@ -53,6 +53,10 @@ public ResponseEntity downloadFile(@PathVariable String file String jsonFilePath = filePath + JSON_TYPE; // 读取文件原始信息 FileInfoEntity fileInfo = JSON.readFromFile(jsonFilePath, FileInfoEntity.class); + if (fileInfo == null) { + return ResponseEntity.ok() + .body(null); + } FileSystemResource fileSystemResource = new FileSystemResource(filePath); diff --git a/todo-service/src/main/java/cn/sbx0/todo/utils/JSON.java b/todo-service/src/main/java/cn/sbx0/todo/utils/JSON.java index c397d26..44ac19a 100644 --- a/todo-service/src/main/java/cn/sbx0/todo/utils/JSON.java +++ b/todo-service/src/main/java/cn/sbx0/todo/utils/JSON.java @@ -42,7 +42,12 @@ public static T format(String content, Class valueType) { } public static T readFromFile(String filePath,Class valueType) throws IOException { - return OBJECT_MAPPER.readValue(new File(filePath), valueType); + File file = new File(filePath); + if (file.exists()) { + return OBJECT_MAPPER.readValue(file, valueType); + } else { + return null; + } } public static JavaType getCollectionType(Class collectionClass, Class... elementClasses) { diff --git a/todo-web/app/file/components/image/image.jsx b/todo-web/app/file/components/image/image.jsx index bdbafad..4547ad1 100644 --- a/todo-web/app/file/components/image/image.jsx +++ b/todo-web/app/file/components/image/image.jsx @@ -10,13 +10,14 @@ function ImageClickFull({src}) { }; return ( -
- +
+ +
); } diff --git a/todo-web/app/file/components/upload/upload.jsx b/todo-web/app/file/components/upload/upload.jsx index 0bae2c9..ca09523 100644 --- a/todo-web/app/file/components/upload/upload.jsx +++ b/todo-web/app/file/components/upload/upload.jsx @@ -66,7 +66,7 @@ function DragAndDropUpload() { if (json.success) { let newFiles = files.slice(0); let file = json.data.name; - newFiles.push(file); + newFiles.push({name: file}); setFiles(newFiles); } else { console.error('Upload failed:', json.message); @@ -94,34 +94,15 @@ function DragAndDropUpload() { } return ( -
-
-
-

拖拽/粘贴上传

-

- 拖拽/粘贴文件到此区域进行上传 -

-
- {dragging ? '放开以上传文件' : '拖拽文件到此区域'} -
-
-
-
- { - files.map((one => { - return
- -
; - })) - } -
+
+ { + files.map((one => )) + }
); }