From d22b29f45db30d36d1bbe9d5527f00225b304619 Mon Sep 17 00:00:00 2001 From: Kane Wang Date: Thu, 20 Nov 2025 00:21:22 +0800 Subject: [PATCH] baocun --- .../cpic/xim/utils/files/UploadedFile.java | 20 +++--- .../src/utils/uploadFile/uploadFile.ts | 20 ++++++ 开发日志.md | 65 ++++++++++++++++++- 3 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 code/web/regulatory-management-util/src/utils/uploadFile/uploadFile.ts diff --git a/code/backend/RegulatoryManagementBackend/src/main/java/com/cpic/xim/utils/files/UploadedFile.java b/code/backend/RegulatoryManagementBackend/src/main/java/com/cpic/xim/utils/files/UploadedFile.java index f9f6132..b0f71e7 100644 --- a/code/backend/RegulatoryManagementBackend/src/main/java/com/cpic/xim/utils/files/UploadedFile.java +++ b/code/backend/RegulatoryManagementBackend/src/main/java/com/cpic/xim/utils/files/UploadedFile.java @@ -2,40 +2,44 @@ * @Author: Kane Wang * @Date: 2025-10-31 17:33:13 * @LastEditors: Kane Wang - * @LastModified: 2025-10-31 17:36:03 - * @FilePath: src/main/java/com/cpic/xim/web/controllers/fileupload/UploadedFile.java + * @LastModified: 2025-11-19 21:16:07 + * @FilePath: src/main/java/com/cpic/xim/utils/files/UploadedFile.java * @Description: * * Copyright (c) 2025 by Kane All rights reserved */ package com.cpic.xim.utils.files; +import com.fasterxml.jackson.annotation.JsonProperty; + public class UploadedFile { - + @JsonProperty( "fileName" ) private String fileName; + + @JsonProperty( "localFilePath" ) private String localFilePath; - + public String getFileName() { return fileName; } - + public void setFileName( String fileName ) { this.fileName = fileName; } - + public String getLocalFilePath() { return localFilePath; } - + public void setLocalFilePath( String localFilePath ) { this.localFilePath = localFilePath; } - + public UploadedFile( String fileName, String localFilePath ) { this.fileName = fileName; diff --git a/code/web/regulatory-management-util/src/utils/uploadFile/uploadFile.ts b/code/web/regulatory-management-util/src/utils/uploadFile/uploadFile.ts new file mode 100644 index 0000000..2963547 --- /dev/null +++ b/code/web/regulatory-management-util/src/utils/uploadFile/uploadFile.ts @@ -0,0 +1,20 @@ +/** + * @author Kane Wang + * @date 2025-11-19 21:08:58 + * Copyright © CPIC All rights reserved + */ + +interface UploadFileResponse +{ + success: boolean; + message: string; + fileList: UploadedFile[] | null; +} + +interface UploadedFile +{ + fileName: string; + localFilePath: string; +} + +export { type UploadFileResponse, type UploadedFile }; \ No newline at end of file diff --git a/开发日志.md b/开发日志.md index e0d84bb..699bc3f 100644 --- a/开发日志.md +++ b/开发日志.md @@ -65,4 +65,67 @@ tomcat 默认是不支持跨域的,不做配置使用vue下载文件会有Acce ### pdf预览组件 -使用 \ No newline at end of file +使用 + +## 技术 + +### element-plus 文件上传 + +element-plus 文件上传组件的响应函数,作为:on-success属性值。要传递的参数作为:data属性值。 + +```typescript +import { type FileUploadResponse } from "@/utils/fileUpload.js"; +import { type UploadProps, type UploadFile, type UploadFiles, ElMessage, ElMessageBox } from "element-plus"; + +const onUploadSuccess: UploadProps["onSuccess"] = ( response: FileUploadResponse, uploadFile: UploadFile, uploadFiles: UploadFiles ): void => + { + // 先判断成功标志位 + if ( response.success ) + { + // 成功,发出导入报表请求 + if ( response.fileList.length === 0 ) + { + // 上传文件路径有问题,提示一下 + ElMessageBox.confirm( + "上传文件的保存路径有误,请联系开发人员。", + "上传文件错误", + { + confirmButtonText: "确定", + type: "warning", + center: true, + } + ) + .then((): void => {}) + .catch((): void => {}); + } + + const request: ImportBIReportRequest = { + filePath: response.fileList[0], + reportType: ui.selectedReportType, + firstRow: ui.firstRow, + sheetIndex: ui.sheetIndex, + }; + + console.log( "请求参数", request ); + + // 发出请求 + importBIReport( request, importResponseHandler ); + } + else + { + // 失败了,提示一下 + ElMessageBox.confirm( + response.message, + "上传文件错误", + { + confirmButtonText: "确定", + type: "warning", + center: true, + } + ) + .then((): void => {}) + .catch((): void => {}); + } + }; +``` +