This commit is contained in:
2025-11-20 00:21:22 +08:00
parent c9c2493671
commit d22b29f45d
3 changed files with 96 additions and 9 deletions

View File

@@ -2,40 +2,44 @@
* @Author: Kane Wang <wangkane@qq.com>
* @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;

View File

@@ -0,0 +1,20 @@
/**
* @author Kane Wang <wangkane@qq.com>
* @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 };

View File

@@ -65,4 +65,67 @@ tomcat 默认是不支持跨域的不做配置使用vue下载文件会有Acce
### pdf预览组件
使用
使用
## 技术
### 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 => {});
}
};
```