新增前端vue

This commit is contained in:
2025-12-19 17:34:24 +08:00
parent 065469cc90
commit ba7bcc3da9
12 changed files with 199 additions and 83 deletions

View File

@@ -1,11 +0,0 @@
package com.jeesite.modules.app.utils;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
public class DateUtils {
}

View File

@@ -42,17 +42,12 @@ public class FileDownloadUtils {
// 1. 构建完整文件路径
Path fullFilePath = Paths.get(orgFileName);
File file = fullFilePath.toFile();
// 2. 校验文件合法性
validateFile(file);
// 3. 清理并编码文件名(避免特殊字符导致的解析异常)
String encodedFileName = encodeFileName(fileName);
// 4. 设置响应头(核心修复:解决下划线/乱码问题)
setDownloadResponseHeader(response, encodedFileName, file.length());
// 5. 读取文件并写入响应输出流try-with-resources自动关闭流
try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(fullFilePath));
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) {
FileCopyUtils.copy(inputStream, outputStream);
@@ -74,16 +69,12 @@ public class FileDownloadUtils {
// 1. 构建完整文件路径
Path fullFilePath = Paths.get(orgFileName);
File file = fullFilePath.toFile();
// 2. 校验文件合法性
validateFile(file);
// 3. 读取文件字节数组
byte[] fileBytes = Files.readAllBytes(fullFilePath);
// 4. 清理并编码文件名
String encodedFileName = encodeFileName(fileName);
HttpHeaders headers = new HttpHeaders();
// 核心修复使用RFC 5987标准移除多余双引号避免下划线问题
headers.set(HttpHeaders.CONTENT_DISPOSITION,
@@ -149,14 +140,8 @@ public class FileDownloadUtils {
* @return 编码后的文件名
*/
private static String encodeFileName(String fileName) {
try {
// 修复:将空格编码为%20而非+,避免浏览器解析为下划线
return URLEncoder.encode(fileName, StandardCharsets.UTF_8.name())
.replace("+", "%20");
} catch (UnsupportedEncodingException e) {
// 理论上UTF-8不会抛出此异常兜底返回原文件名
return fileName;
}
return URLEncoder.encode(fileName, StandardCharsets.UTF_8)
.replace("+", "%20");
}
}

View File

@@ -14,7 +14,7 @@ import java.util.concurrent.Executors;
public class MailSendUtils {
private static final ExecutorService MAIL_EXECUTOR = Executors.newFixedThreadPool(5);
private static String FILE_PATH = "/ogsapp/files";
private static final String FILE_PATH = "/ogsapp/files";
/**
* 同步发送HTML格式邮件

View File

@@ -0,0 +1,48 @@
package com.jeesite.modules.app.utils;
import java.nio.file.*;
import java.text.DecimalFormat;
public class MyFileUtils {
private static final long UNIT_BASE = 1024;
private static final String[] UNITS = {"B", "KB", "MB", "GB", "TB"};
private static final LoggerUtils logger = LoggerUtils.getInstance();
public static String formatFileSize(long sizeInBytes, int decimalPlaces) {
if (sizeInBytes == 0) {
return "0 " + UNITS[0];
}
long absSize = Math.abs(sizeInBytes);
String negativeFlag = sizeInBytes < 0 ? "-" : "";
int validDecimalPlaces = Math.max(0, Math.min(decimalPlaces, 4));
String formatPattern = validDecimalPlaces == 0 ? "#0" : "#0." + "0".repeat(validDecimalPlaces);
DecimalFormat df = new DecimalFormat(formatPattern);
int unitIndex = 0;
double formattedSize = absSize;
while (formattedSize >= UNIT_BASE && unitIndex < UNITS.length - 1) {
formattedSize /= UNIT_BASE;
unitIndex++;
}
return negativeFlag + df.format(formattedSize) + " " + UNITS[unitIndex];
}
public static void moveFile(String sourceName, String targetName, boolean overwrite) {
try {
Path sourcePath = Paths.get(sourceName);
Path targetPath = Paths.get(targetName);
CopyOption[] options = overwrite
? new CopyOption[]{StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE}
: new CopyOption[]{StandardCopyOption.ATOMIC_MOVE};
Files.move(sourcePath, targetPath, options);
} catch (Exception e) {
logger.error(e.getMessage());
}
}
}

View File

@@ -32,4 +32,17 @@ public class vId {
long rand = Math.abs(RAND.nextLong()) % (long) Math.pow(3, 6);
return tm + String.format("%04d", rand);
}
public static long getLongId() {
String tm = LocalDateTime.now().format(DF);
int rand = RAND.nextInt(100);
String randStr = String.format("%02d", rand);
String cidStr = tm + randStr;
try {
return Long.parseLong(cidStr);
} catch (NumberFormatException e) {
// 兜底处理:若意外超出范围,抛出明确异常
throw new RuntimeException("生成的CID超出long类型范围" + cidStr, e);
}
}
}

View File

@@ -139,6 +139,12 @@ public class BizFoldersController extends BaseController {
return renderResult(Global.TRUE, text("删除文件夹信息成功!"));
}
@RequestMapping(value = "listAll")
@ResponseBody
public List<BizFolders> listAll(BizFolders bizFolders) {
return bizFoldersService.findList(bizFolders);
}
@RequestMapping(value = "foldersAll")
@ResponseBody
public List<FolderItem> foldersAll(BizFolders bizFolders) {

View File

@@ -1,7 +1,12 @@
package com.jeesite.modules.biz.web;
import java.util.Date;
import java.util.List;
import cn.hutool.core.net.multipart.UploadFile;
import com.jeesite.modules.app.utils.MyFileUtils;
import com.jeesite.modules.app.utils.vId;
import com.jeesite.modules.file.entity.FileUpload;
import com.jeesite.modules.file.utils.FileUploadUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@@ -36,6 +41,8 @@ import com.jeesite.modules.biz.service.BizMyfilesService;
@RequestMapping(value = "${adminPath}/biz/myfiles")
public class BizMyfilesController extends BaseController {
private static final String FILE_PATH = "/ogsapp/files";
private final BizMyfilesService bizMyfilesService;
public BizMyfilesController(BizMyfilesService bizMyfilesService) {
@@ -85,8 +92,19 @@ public class BizMyfilesController extends BaseController {
@PostMapping(value = "save")
@ResponseBody
public String save(@Validated BizMyfiles bizMyfiles) {
// bizMyfilesService.save(bizMyfiles);
FileUploadUtils.saveFileUpload(bizMyfiles, bizMyfiles.getId(), "bizMyfiles_file");
List<FileUpload> fileList = FileUploadUtils.findFileUpload(bizMyfiles.getId(), "bizMyfiles_file");
for (FileUpload fileUpload : fileList) {
bizMyfiles.setCreateTime(new Date());
bizMyfiles.setTid(vId.getLongId());
bizMyfiles.setFileName(fileUpload.getFileName());
bizMyfiles.setFilePath(FILE_PATH + fileUpload.getFileUrl());
bizMyfiles.setFileHash(fileUpload.getFileEntity().getFileMd5());
bizMyfiles.setFileSize(MyFileUtils.formatFileSize(fileUpload.getFileEntity().getFileSize(), 2));
bizMyfiles.setFileExt(fileUpload.getFileEntity().getFileExtension());
bizMyfiles.setMimeType(fileUpload.getFileEntity().getFileContentType());
bizMyfilesService.save(bizMyfiles);
}
return renderResult(Global.TRUE, text("保存文件信息成功!"));
}