保存进度!

This commit is contained in:
2025-11-27 18:18:22 +08:00
parent bf6e78b423
commit 835e812d4e
10 changed files with 151 additions and 89 deletions

View File

@@ -2,7 +2,7 @@
* @Author: Kane Wang <wangkane@qq.com>
* @Date: 2025-10-16 09:46:42
* @LastEditors: Kane Wang
* @LastModified: 2025-11-18 17:03:33
* @LastModified: 2025-11-27 17:29:30
* @FilePath: src/main/java/com/cpic/xim/utils/files/SaveUploadFile.java
* @Description:
*
@@ -82,30 +82,32 @@ public class SaveUploadFile
/**
* 将files参数中上传的文件保存到tempFilePath指定的路径文件名加上毫秒数避免重复。
* @param files
* @param tempFilePath
*
* @param files
* @param absoluteFilePath
* @return 返回UploadedFile对象数组
* @throws ProcessUploadedFileException
*/
public static Vector<UploadedFile> saveUploadFiles(
MultipartFile[] files,
String tempFilePath
String absoluteFilePath,
String relativeFilePath
)
throws ProcessUploadedFileException
{
Vector<UploadedFile> savedFiles = new Vector<>();
UploadedFile uploadedFile = null;
Vector<UploadedFile> savedFiles = new Vector<>();
UploadedFile uploadedFile = null;
// File dir = new File( tempFilePath );
String fileName = "";
String fullPath;
String fullPath = null;
if ( !(tempFilePath.endsWith( "/" ) || tempFilePath.endsWith( "\\" )) )
if ( !(absoluteFilePath.endsWith( "/" ) || absoluteFilePath.endsWith( "\\" )) )
{
fullPath = tempFilePath + "/";
fullPath = absoluteFilePath + "/";
}
else
{
fullPath = tempFilePath;
fullPath = absoluteFilePath;
}
try
@@ -122,18 +124,18 @@ public class SaveUploadFile
Long milliSecond = LocalDateTime.now().toInstant( ZoneOffset.of( "+8" ) ).toEpochMilli();
fileName = String.valueOf( milliSecond ) + " - " + file.getOriginalFilename();
File destFile = new File( tempFilePath, fileName );
File destFile = new File( fullPath, fileName );
file.transferTo( destFile );
uploadedFile = new UploadedFile(fileName, destFile.getPath() );
uploadedFile = new UploadedFile( fileName, fullPath, relativeFilePath );
savedFiles.add( uploadedFile );
}
}
catch ( IOException error )
{
throw new ProcessUploadedFileException( "临时目录" + tempFilePath + "保存文件" + fileName + "失败!" );
throw new ProcessUploadedFileException( "临时目录" + absoluteFilePath + "保存文件" + fileName + "失败!" );
}
return savedFiles;
@@ -142,32 +144,33 @@ public class SaveUploadFile
/**
*
* @param originFilePath 文件路径
* @param newFilePath 新文件存放路径
* @param newFilePath 新文件存放路径
* @throws MoveUploadedFileException
*/
public static void MoveUploadedFile(
String originFilePath,
String newFilePath
) throws MoveUploadedFileException
)
throws MoveUploadedFileException
{
// 防御性验证
File originFile = new File( originFilePath );
File dest = new File( newFilePath );
File dest = new File( newFilePath );
// 文件如果不存在就抛出异常
if ( originFile.exists() == false )
{
throw new MoveUploadedFileException("文件不存在!");
throw new MoveUploadedFileException( "文件不存在!" );
}
if ( dest.exists() == true )
{
throw new MoveUploadedFileException("目的路径已存在同名文件!" );
throw new MoveUploadedFileException( "目的路径已存在同名文件!" );
}
if ( originFile.renameTo(dest) == false )
if ( originFile.renameTo( dest ) == false )
{
throw new MoveUploadedFileException("移动文件失败!" );
throw new MoveUploadedFileException( "移动文件失败!" );
}
}
}

View File

@@ -2,7 +2,7 @@
* @Author: Kane Wang <wangkane@qq.com>
* @Date: 2025-10-31 17:33:13
* @LastEditors: Kane Wang
* @LastModified: 2025-11-19 21:16:07
* @LastModified: 2025-11-27 11:43:18
* @FilePath: src/main/java/com/cpic/xim/utils/files/UploadedFile.java
* @Description:
*
@@ -12,37 +12,62 @@ 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;
@JsonProperty( "absoluteFilePath" )
private String absoluteFilePath;
@JsonProperty( "relativeFilePath" )
private String relativeFilePath;
public String getFileName()
{
return fileName;
}
public void setFileName( String fileName )
{
this.fileName = fileName;
}
public String getLocalFilePath()
public String getAbsoluteFilePath()
{
return localFilePath;
return absoluteFilePath;
}
public void setLocalFilePath( String localFilePath )
public void setAbsoluteFilePath( String absoluteFilePath )
{
this.localFilePath = localFilePath;
this.absoluteFilePath = absoluteFilePath;
}
public UploadedFile( String fileName, String localFilePath )
public String getRelativeFilePath()
{
this.fileName = fileName;
this.localFilePath = localFilePath;
return relativeFilePath;
}
public void setRelativeFilePath( String relativeFilePath )
{
this.relativeFilePath = relativeFilePath;
}
public UploadedFile( String fileName, String absoluteFilePath, String relativeFilePath )
{
this.fileName = fileName;
this.absoluteFilePath = absoluteFilePath;
this.relativeFilePath = relativeFilePath;
}
public UploadedFile( String fileName, String absoluteFilePath )
{
this.fileName = fileName;
this.absoluteFilePath = absoluteFilePath;
this.relativeFilePath = "";
}
}

View File

@@ -30,7 +30,7 @@ import jakarta.servlet.http.HttpServletRequest;
// @SuppressWarnings( "unused" )
@Controller
@RequestMapping( path = "/file" )
public class FileUpload
public class UploadFileController
{
/**
* 接收上传文件并保存到临时目录
@@ -60,14 +60,15 @@ public class FileUpload
result.setSuccess( true );
result.setMessage( "上传成功!" );
String filePath = request.getServletContext().getRealPath( "/temp/upload/" + sessionID );
File dir = new File( filePath );
String relativeFilePath = "/temp/upload/" + sessionID;
String absolutefilePath = request.getServletContext().getRealPath( relativeFilePath );
File dir = new File( absolutefilePath );
// 创建临时目录
if ( (!dir.exists()) && (!dir.mkdirs()) )
{
result.setSuccess( false );
result.setMessage( "创建临时目录失败:" + filePath );
result.setMessage( "创建临时目录失败:" + absolutefilePath );
return result;
}
@@ -76,7 +77,9 @@ public class FileUpload
{
files[0] = file;
Vector<UploadedFile> uploadFiles = SaveUploadFile.saveUploadFiles( files, filePath );
Vector<UploadedFile> uploadFiles = SaveUploadFile.saveUploadFiles( files,
absolutefilePath,
relativeFilePath );
result.setFileList( uploadFiles );
}

View File

@@ -18,3 +18,4 @@ VITE_APP_CACHE_ENABLED=true
#上传文件
VITE_APP_URL_UPLOAD_FILE=http://222.76.244.118:8081/RegulatoryManagementBackend/file/file-upload.do
VITE_APP_URL_MOVE_FILE=http://222.76.244.118:8081/RegulatoryManagementBackend/file/move-file.do
VITE_APP_URL_PREFIX=http://222.76.244.118:8081/RegulatoryManagementBackend/

View File

@@ -21,7 +21,7 @@ module.exports = {
},
extends:["eslint:recommended",],
rules:{
indent: ["warn", 4,],
// indent: ["warn", 4,],
// 圆括号中的空格,为空不加空格,紧跟花括号、方括号、圆括号时也不加入空格
"space-in-parens": ["error", "always", { exceptions: ["{}", "[]", "()", "empty",], },],
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
@@ -81,7 +81,7 @@ module.exports = {
"plugin:@typescript-eslint/recommended",
],
rules: {
indent: ["warn", 4,],
// indent: ["warn", 4,],
"no-trailing-spaces": ["error", {"ignoreComments": true,},],
// 圆括号中的空格,为空不加空格,紧跟花括号、方括号、圆括号时也不加入空格
"space-in-parens": ["error", "always", { exceptions: ["{}", "[]", "()", "empty",], },],
@@ -121,7 +121,7 @@ module.exports = {
},],
// typescript
// "@typescript-eslint/indent": ["warn", 4,],
"@stylistic/indent": ["warn", 4,],
"@stylistic/indent": ["warn", 4, { "SwitchCase": 1, },],
"@typescript-eslint/no-explicit-any": "warn",
// "@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-extra-semi": "off",
@@ -173,7 +173,7 @@ module.exports = {
"@typescript-eslint/no-explicit-any": "off",
// "@typescript-eslint/no-unsafe-argument": "warn",
// "@typescript-eslint/indent": ["error", 4,],
"@stylistic/indent": ["warn", 4,],
"@stylistic/indent": ["warn", 4, { "SwitchCase": 1, },],
"@typescript-eslint/no-extra-semi": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-unused-vars": "warn",

View File

@@ -1738,7 +1738,6 @@
"integrity": "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@types/lodash": "*"
}
@@ -1749,7 +1748,6 @@
"integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"undici-types": "~7.16.0"
}
@@ -1797,7 +1795,6 @@
"integrity": "sha512-lJi3PfxVmo0AkEY93ecfN+r8SofEqZNGByvHAI3GBLrvt1Cw6H5k1IM02nSzu0RfUafr2EvFSw0wAsZgubNplQ==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@typescript-eslint/scope-manager": "8.47.0",
"@typescript-eslint/types": "8.47.0",
@@ -2291,7 +2288,6 @@
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"acorn": "bin/acorn"
},
@@ -2769,7 +2765,6 @@
"integrity": "sha512-BhHmn2yNOFA9H9JmmIVKJmd288g9hrVRDkdoIgRCRuSySRUHH7r/DI6aAXW9T1WwUuY3DFgrcaqB+deURBLR5g==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.8.0",
"@eslint-community/regexpp": "^4.12.1",
@@ -3529,16 +3524,14 @@
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"dev": true,
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/lodash-es": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
"integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==",
"dev": true,
"license": "MIT",
"peer": true
"license": "MIT"
},
"node_modules/lodash-unified": {
"version": "1.0.3",
@@ -4074,7 +4067,6 @@
"integrity": "sha512-N+7WK20/wOr7CzA2snJcUSSNTCzeCGUTFY3OgeQP3mZ1aj9NMQ0mSTXwlrnd89j33zzQJGqIN52GIOmYrfq46A==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"chokidar": "^4.0.0",
"immutable": "^5.0.2",
@@ -4234,7 +4226,6 @@
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
"devOptional": true,
"license": "Apache-2.0",
"peer": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@@ -4283,7 +4274,6 @@
"integrity": "sha512-NL8jTlbo0Tn4dUEXEsUg8KeyG/Lkmc4Fnzb8JXN/Ykm9G4HNImjtABMJgkQoVjOBN/j2WAwDTRytdqJbZsah7w==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"esbuild": "^0.25.0",
"fdir": "^6.5.0",
@@ -4365,7 +4355,6 @@
"resolved": "https://registry.npmmirror.com/vue/-/vue-3.5.24.tgz",
"integrity": "sha512-uTHDOpVQTMjcGgrqFPSb8iO2m1DUvo+WbGqoXQz8Y1CeBYQ0FXf2z1gLRaBtHjlRz7zZUBHxjVB5VTLzYkvftg==",
"license": "MIT",
"peer": true,
"dependencies": {
"@vue/compiler-dom": "3.5.24",
"@vue/compiler-sfc": "3.5.24",
@@ -4389,7 +4378,6 @@
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"peer": true,
"bin": {
"vue-demi-fix": "bin/vue-demi-fix.js",
"vue-demi-switch": "bin/vue-demi-switch.js"
@@ -4416,7 +4404,6 @@
"integrity": "sha512-CydUvFOQKD928UzZhTp4pr2vWz1L+H99t7Pkln2QSPdvmURT0MoC4wUccfCnuEaihNsu9aYYyk+bep8rlfkUXw==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"debug": "^4.4.0",
"eslint-scope": "^8.2.0",

View File

@@ -2,7 +2,7 @@
* @Author: Kane Wang <wangkane@qq.com>
* @Date: 2025-11-21 10:19:11
* @LastEditors: Kane Wang
* @LastModified: 2025-11-21 10:36:19
* @LastModified: 2025-11-27 17:41:28
* @FilePath: src/types/upload_file.ts
* @Description:
*
@@ -19,7 +19,8 @@ interface UploadFileResponse
interface UploadedFile
{
fileName: string;
localFilePath: string;
absoluteFilePath: string;
relativeFilePath: string;
}
export {

View File

@@ -11,6 +11,7 @@
const API_URL= {
URL_UPLOAD_FILE: import.meta.env.VITE_APP_URL_UPLOAD_FILE,
URL_MOVE_FILE: import.meta.env.VITE_APP_URL_MOVE_FILE,
URL_PREFIX: import.meta.env.VITE_APP_URL_PREFIX,
};
console.log( API_URL );

View File

@@ -1,20 +0,0 @@
/**
* @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

@@ -48,7 +48,10 @@ Copyright © CPIC All rights reserved
<el-col :span="5" />
<el-col :span="3">
<div class="button-wrapper-right">
<el-button type="primary" icon="document">
<el-button
type="primary" icon="document"
@click="onPreviewUploadedFile(1)"
>
提交
</el-button>
</div>
@@ -75,7 +78,11 @@ Copyright © CPIC All rights reserved
</el-table-column>
<el-table-column label="操作" align="center" width="200px">
<template #default="file">
<el-button type="primary" icon="search" circle />
<el-button
type="primary" icon="search"
circle
@click="onPreviewUploadedFile(file.row.rowIndex)"
/>
<el-button
type="danger" icon="delete"
circle
@@ -107,6 +114,30 @@ Copyright © CPIC All rights reserved
</div>
</el-upload>
</el-dialog>
<el-dialog
v-model="ui.showPreviewDialog" :close-on-click-model="false"
:close-on-press-escape="false"
:show-close="true"
align-center
title="文件预览"
width="1024px"
>
<VueOfficePdf
v-if="ui.isPDF" :src="ui.fileURL"
style="height:calc(100vh - 100px);"
@error="errorHandle"
/>
<VueOfficeDocx
v-if="ui.isDOCX" :src="ui.fileURL"
style="height:calc(100vh - 100px);"
@error="errorHandle"
/>
<VueOfficeExcel
v-if="ui.isXLSX" :src="ui.fileURL"
style="height:calc(100vh - 100px);"
@error="errorHandle"
/>
</el-dialog>
</div>
</div>
</template>
@@ -117,26 +148,35 @@ import {type RegulatoryData, type RegulatoryFile} from "@/types/regulatory/regul
import { type UploadedFile, type UploadFileResponse } from "@/types/upload_file.ts";
import {API_URL} from "@/utils/config.ts";
import { getFileType } from "@/utils/utils";
import VueOfficePdf from "@vue-office/pdf";
import VueOfficeDocx from "@vue-office/docx";
import VueOfficeExcel from "@vue-office/excel";
interface UI{
showUI: boolean;
showUploadDialog: boolean;
showPreviewDialog: boolean;
urlFileUpload: string;
uploadParameters: {
fileName: string;
};
newRegulatory: RegulatoryData;
showFileList: boolean;
isPDF: boolean;
isDOCX: boolean;
isXLSX: boolean;
fileURL: string;
};
export default {
name: "NewRegulatory",
components: {},
components: {VueOfficePdf, VueOfficeDocx, VueOfficeExcel,},
setup()
{
const ui: UI = reactive({
showUI: true,
showUploadDialog: false,
showPreviewDialog: false,
urlFileUpload: API_URL.URL_UPLOAD_FILE,
uploadParameters: {
fileName: "1234",
@@ -149,6 +189,10 @@ export default {
regulatory_files: [],
},
showFileList: false,
isPDF: true,
isDOCX: false,
isXLSX: false,
fileURL: "http://10.39.0.1:8080/regulatory/%E4%BF%A1%E6%81%AF%E6%8A%80%E6%9C%AF%E9%83%A8/test.pdf",
});
const headerCellStyle = reactive(
@@ -193,6 +237,11 @@ export default {
};
const onPreviewUploadedFile = ( rowId: number ): void =>
{
ui.showPreviewDialog = true;
};
/**
* 用来给 el-table 行设置样式。
* 其中给row加一个参数rowIndex用行号赋值。
@@ -240,10 +289,10 @@ export default {
}
const uploadedFile: RegulatoryFile = {
regulatory_file_name: response.fileList[0]?.fileName ?? "",
local_file_path: response.fileList[0]?.localFilePath ?? "",
file_type: getFileType( response.fileList[0]?.localFilePath ),
file_url: "",
regulatory_file_name: response.fileList[0].fileName ?? "",
local_file_path: response.fileList[0]?.absoluteFilePath ?? "",
file_type: getFileType( response.fileList[0]?.fileName ),
file_url: API_URL.URL_PREFIX + response.fileList[0]?.relativeFilePath,
};
ui.newRegulatory.regulatory_files?.push( uploadedFile );
@@ -266,6 +315,11 @@ export default {
}
};
const errorHandle = ()=>
{
ElMessage.error( "渲染文档出错!" );
};
return {
ui,
headerCellStyle,
@@ -274,6 +328,8 @@ export default {
tableRowClassName,
showUploadFileDialog,
onDeleteUploadedFile,
onPreviewUploadedFile,
errorHandle,
};
},
};
@@ -299,4 +355,9 @@ export default {
:deep(.el-input) .el-input__inner {
text-align: center;
}
:deep(.el-dialog) {
min-width: calc(100wh - 100px);
max-width: calc(100wh - 100px);
}
</style>