保存进度!

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> * @Author: Kane Wang <wangkane@qq.com>
* @Date: 2025-10-16 09:46:42 * @Date: 2025-10-16 09:46:42
* @LastEditors: Kane Wang * @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 * @FilePath: src/main/java/com/cpic/xim/utils/files/SaveUploadFile.java
* @Description: * @Description:
* *
@@ -82,14 +82,16 @@ public class SaveUploadFile
/** /**
* 将files参数中上传的文件保存到tempFilePath指定的路径文件名加上毫秒数避免重复。 * 将files参数中上传的文件保存到tempFilePath指定的路径文件名加上毫秒数避免重复。
*
* @param files * @param files
* @param tempFilePath * @param absoluteFilePath
* @return 返回UploadedFile对象数组 * @return 返回UploadedFile对象数组
* @throws ProcessUploadedFileException * @throws ProcessUploadedFileException
*/ */
public static Vector<UploadedFile> saveUploadFiles( public static Vector<UploadedFile> saveUploadFiles(
MultipartFile[] files, MultipartFile[] files,
String tempFilePath String absoluteFilePath,
String relativeFilePath
) )
throws ProcessUploadedFileException throws ProcessUploadedFileException
{ {
@@ -97,15 +99,15 @@ public class SaveUploadFile
UploadedFile uploadedFile = null; UploadedFile uploadedFile = null;
// File dir = new File( tempFilePath ); // File dir = new File( tempFilePath );
String fileName = ""; String fileName = "";
String fullPath; String fullPath = null;
if ( !(tempFilePath.endsWith( "/" ) || tempFilePath.endsWith( "\\" )) ) if ( !(absoluteFilePath.endsWith( "/" ) || absoluteFilePath.endsWith( "\\" )) )
{ {
fullPath = tempFilePath + "/"; fullPath = absoluteFilePath + "/";
} }
else else
{ {
fullPath = tempFilePath; fullPath = absoluteFilePath;
} }
try try
@@ -122,18 +124,18 @@ public class SaveUploadFile
Long milliSecond = LocalDateTime.now().toInstant( ZoneOffset.of( "+8" ) ).toEpochMilli(); Long milliSecond = LocalDateTime.now().toInstant( ZoneOffset.of( "+8" ) ).toEpochMilli();
fileName = String.valueOf( milliSecond ) + " - " + file.getOriginalFilename(); fileName = String.valueOf( milliSecond ) + " - " + file.getOriginalFilename();
File destFile = new File( tempFilePath, fileName ); File destFile = new File( fullPath, fileName );
file.transferTo( destFile ); file.transferTo( destFile );
uploadedFile = new UploadedFile(fileName, destFile.getPath() ); uploadedFile = new UploadedFile( fileName, fullPath, relativeFilePath );
savedFiles.add( uploadedFile ); savedFiles.add( uploadedFile );
} }
} }
catch ( IOException error ) catch ( IOException error )
{ {
throw new ProcessUploadedFileException( "临时目录" + tempFilePath + "保存文件" + fileName + "失败!" ); throw new ProcessUploadedFileException( "临时目录" + absoluteFilePath + "保存文件" + fileName + "失败!" );
} }
return savedFiles; return savedFiles;
@@ -148,7 +150,8 @@ public class SaveUploadFile
public static void MoveUploadedFile( public static void MoveUploadedFile(
String originFilePath, String originFilePath,
String newFilePath String newFilePath
) throws MoveUploadedFileException )
throws MoveUploadedFileException
{ {
// 防御性验证 // 防御性验证
File originFile = new File( originFilePath ); File originFile = new File( originFilePath );

View File

@@ -2,7 +2,7 @@
* @Author: Kane Wang <wangkane@qq.com> * @Author: Kane Wang <wangkane@qq.com>
* @Date: 2025-10-31 17:33:13 * @Date: 2025-10-31 17:33:13
* @LastEditors: Kane Wang * @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 * @FilePath: src/main/java/com/cpic/xim/utils/files/UploadedFile.java
* @Description: * @Description:
* *
@@ -12,13 +12,20 @@ package com.cpic.xim.utils.files;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
/**
* 描述上传文件的类。
*
*/
public class UploadedFile public class UploadedFile
{ {
@JsonProperty( "fileName" ) @JsonProperty( "fileName" )
private String fileName; private String fileName;
@JsonProperty( "localFilePath" ) @JsonProperty( "absoluteFilePath" )
private String localFilePath; private String absoluteFilePath;
@JsonProperty( "relativeFilePath" )
private String relativeFilePath;
public String getFileName() public String getFileName()
{ {
@@ -30,19 +37,37 @@ public class UploadedFile
this.fileName = 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()
{
return relativeFilePath;
}
public void setRelativeFilePath( String relativeFilePath )
{
this.relativeFilePath = relativeFilePath;
}
public UploadedFile( String fileName, String absoluteFilePath, String relativeFilePath )
{ {
this.fileName = fileName; this.fileName = fileName;
this.localFilePath = localFilePath; 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" ) // @SuppressWarnings( "unused" )
@Controller @Controller
@RequestMapping( path = "/file" ) @RequestMapping( path = "/file" )
public class FileUpload public class UploadFileController
{ {
/** /**
* 接收上传文件并保存到临时目录 * 接收上传文件并保存到临时目录
@@ -60,14 +60,15 @@ public class FileUpload
result.setSuccess( true ); result.setSuccess( true );
result.setMessage( "上传成功!" ); result.setMessage( "上传成功!" );
String filePath = request.getServletContext().getRealPath( "/temp/upload/" + sessionID ); String relativeFilePath = "/temp/upload/" + sessionID;
File dir = new File( filePath ); String absolutefilePath = request.getServletContext().getRealPath( relativeFilePath );
File dir = new File( absolutefilePath );
// 创建临时目录 // 创建临时目录
if ( (!dir.exists()) && (!dir.mkdirs()) ) if ( (!dir.exists()) && (!dir.mkdirs()) )
{ {
result.setSuccess( false ); result.setSuccess( false );
result.setMessage( "创建临时目录失败:" + filePath ); result.setMessage( "创建临时目录失败:" + absolutefilePath );
return result; return result;
} }
@@ -76,7 +77,9 @@ public class FileUpload
{ {
files[0] = file; files[0] = file;
Vector<UploadedFile> uploadFiles = SaveUploadFile.saveUploadFiles( files, filePath ); Vector<UploadedFile> uploadFiles = SaveUploadFile.saveUploadFiles( files,
absolutefilePath,
relativeFilePath );
result.setFileList( uploadFiles ); 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_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_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",], extends:["eslint:recommended",],
rules:{ rules:{
indent: ["warn", 4,], // indent: ["warn", 4,],
// 圆括号中的空格,为空不加空格,紧跟花括号、方括号、圆括号时也不加入空格 // 圆括号中的空格,为空不加空格,紧跟花括号、方括号、圆括号时也不加入空格
"space-in-parens": ["error", "always", { exceptions: ["{}", "[]", "()", "empty",], },], "space-in-parens": ["error", "always", { exceptions: ["{}", "[]", "()", "empty",], },],
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off", "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
@@ -81,7 +81,7 @@ module.exports = {
"plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended",
], ],
rules: { rules: {
indent: ["warn", 4,], // indent: ["warn", 4,],
"no-trailing-spaces": ["error", {"ignoreComments": true,},], "no-trailing-spaces": ["error", {"ignoreComments": true,},],
// 圆括号中的空格,为空不加空格,紧跟花括号、方括号、圆括号时也不加入空格 // 圆括号中的空格,为空不加空格,紧跟花括号、方括号、圆括号时也不加入空格
"space-in-parens": ["error", "always", { exceptions: ["{}", "[]", "()", "empty",], },], "space-in-parens": ["error", "always", { exceptions: ["{}", "[]", "()", "empty",], },],
@@ -121,7 +121,7 @@ module.exports = {
},], },],
// typescript // typescript
// "@typescript-eslint/indent": ["warn", 4,], // "@typescript-eslint/indent": ["warn", 4,],
"@stylistic/indent": ["warn", 4,], "@stylistic/indent": ["warn", 4, { "SwitchCase": 1, },],
"@typescript-eslint/no-explicit-any": "warn", "@typescript-eslint/no-explicit-any": "warn",
// "@typescript-eslint/no-unsafe-argument": "warn", // "@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-extra-semi": "off", "@typescript-eslint/no-extra-semi": "off",
@@ -173,7 +173,7 @@ module.exports = {
"@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-explicit-any": "off",
// "@typescript-eslint/no-unsafe-argument": "warn", // "@typescript-eslint/no-unsafe-argument": "warn",
// "@typescript-eslint/indent": ["error", 4,], // "@typescript-eslint/indent": ["error", 4,],
"@stylistic/indent": ["warn", 4,], "@stylistic/indent": ["warn", 4, { "SwitchCase": 1, },],
"@typescript-eslint/no-extra-semi": "off", "@typescript-eslint/no-extra-semi": "off",
"@typescript-eslint/no-inferrable-types": "off", "@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-unused-vars": "warn", "@typescript-eslint/no-unused-vars": "warn",

View File

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

View File

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

View File

@@ -11,6 +11,7 @@
const API_URL= { const API_URL= {
URL_UPLOAD_FILE: import.meta.env.VITE_APP_URL_UPLOAD_FILE, URL_UPLOAD_FILE: import.meta.env.VITE_APP_URL_UPLOAD_FILE,
URL_MOVE_FILE: import.meta.env.VITE_APP_URL_MOVE_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 ); 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="5" />
<el-col :span="3"> <el-col :span="3">
<div class="button-wrapper-right"> <div class="button-wrapper-right">
<el-button type="primary" icon="document"> <el-button
type="primary" icon="document"
@click="onPreviewUploadedFile(1)"
>
提交 提交
</el-button> </el-button>
</div> </div>
@@ -75,7 +78,11 @@ Copyright © CPIC All rights reserved
</el-table-column> </el-table-column>
<el-table-column label="操作" align="center" width="200px"> <el-table-column label="操作" align="center" width="200px">
<template #default="file"> <template #default="file">
<el-button type="primary" icon="search" circle /> <el-button
type="primary" icon="search"
circle
@click="onPreviewUploadedFile(file.row.rowIndex)"
/>
<el-button <el-button
type="danger" icon="delete" type="danger" icon="delete"
circle circle
@@ -107,6 +114,30 @@ Copyright © CPIC All rights reserved
</div> </div>
</el-upload> </el-upload>
</el-dialog> </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>
</div> </div>
</template> </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 { type UploadedFile, type UploadFileResponse } from "@/types/upload_file.ts";
import {API_URL} from "@/utils/config.ts"; import {API_URL} from "@/utils/config.ts";
import { getFileType } from "@/utils/utils"; 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{ interface UI{
showUI: boolean; showUI: boolean;
showUploadDialog: boolean; showUploadDialog: boolean;
showPreviewDialog: boolean;
urlFileUpload: string; urlFileUpload: string;
uploadParameters: { uploadParameters: {
fileName: string; fileName: string;
}; };
newRegulatory: RegulatoryData; newRegulatory: RegulatoryData;
showFileList: boolean; showFileList: boolean;
isPDF: boolean;
isDOCX: boolean;
isXLSX: boolean;
fileURL: string;
}; };
export default { export default {
name: "NewRegulatory", name: "NewRegulatory",
components: {}, components: {VueOfficePdf, VueOfficeDocx, VueOfficeExcel,},
setup() setup()
{ {
const ui: UI = reactive({ const ui: UI = reactive({
showUI: true, showUI: true,
showUploadDialog: false, showUploadDialog: false,
showPreviewDialog: false,
urlFileUpload: API_URL.URL_UPLOAD_FILE, urlFileUpload: API_URL.URL_UPLOAD_FILE,
uploadParameters: { uploadParameters: {
fileName: "1234", fileName: "1234",
@@ -149,6 +189,10 @@ export default {
regulatory_files: [], regulatory_files: [],
}, },
showFileList: false, 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( const headerCellStyle = reactive(
@@ -193,6 +237,11 @@ export default {
}; };
const onPreviewUploadedFile = ( rowId: number ): void =>
{
ui.showPreviewDialog = true;
};
/** /**
* 用来给 el-table 行设置样式。 * 用来给 el-table 行设置样式。
* 其中给row加一个参数rowIndex用行号赋值。 * 其中给row加一个参数rowIndex用行号赋值。
@@ -240,10 +289,10 @@ export default {
} }
const uploadedFile: RegulatoryFile = { const uploadedFile: RegulatoryFile = {
regulatory_file_name: response.fileList[0]?.fileName ?? "", regulatory_file_name: response.fileList[0].fileName ?? "",
local_file_path: response.fileList[0]?.localFilePath ?? "", local_file_path: response.fileList[0]?.absoluteFilePath ?? "",
file_type: getFileType( response.fileList[0]?.localFilePath ), file_type: getFileType( response.fileList[0]?.fileName ),
file_url: "", file_url: API_URL.URL_PREFIX + response.fileList[0]?.relativeFilePath,
}; };
ui.newRegulatory.regulatory_files?.push( uploadedFile ); ui.newRegulatory.regulatory_files?.push( uploadedFile );
@@ -266,6 +315,11 @@ export default {
} }
}; };
const errorHandle = ()=>
{
ElMessage.error( "渲染文档出错!" );
};
return { return {
ui, ui,
headerCellStyle, headerCellStyle,
@@ -274,6 +328,8 @@ export default {
tableRowClassName, tableRowClassName,
showUploadFileDialog, showUploadFileDialog,
onDeleteUploadedFile, onDeleteUploadedFile,
onPreviewUploadedFile,
errorHandle,
}; };
}, },
}; };
@@ -299,4 +355,9 @@ export default {
:deep(.el-input) .el-input__inner { :deep(.el-input) .el-input__inner {
text-align: center; text-align: center;
} }
:deep(.el-dialog) {
min-width: calc(100wh - 100px);
max-width: calc(100wh - 100px);
}
</style> </style>