From fe1fe00ecbd8409aff566b291a613426909d5901 Mon Sep 17 00:00:00 2001 From: zhanglipeng <chinazhanglipeng@qq.com> Date: Mon, 11 Oct 2021 08:53:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD=20?= =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/utils/ruoyi.js | 6 ++++-- ruoyi-ui/src/views/benyi/filelibrary/index.vue | 3 ++- .../com/ruoyi/framework/config/RuoYiConfig.java | 8 ++++++++ .../ruoyi/project/common/CommonController.java | 17 ++++++++++------- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js index bbdbde8dd..ff1d610c3 100644 --- a/ruoyi-ui/src/utils/ruoyi.js +++ b/ruoyi-ui/src/utils/ruoyi.js @@ -106,13 +106,15 @@ export function selectMoeDictLabel(datas, value) { } // 通用下载方法 -export function download(fileName) { +export function download(fileName, fileUrlPath) { window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + + "&fileUrlPath=" + + encodeURI(fileUrlPath) + "&delete=" + - true; + false; } // 字符串格式化(%s ) diff --git a/ruoyi-ui/src/views/benyi/filelibrary/index.vue b/ruoyi-ui/src/views/benyi/filelibrary/index.vue index 0041d8ea3..c164b83a7 100644 --- a/ruoyi-ui/src/views/benyi/filelibrary/index.vue +++ b/ruoyi-ui/src/views/benyi/filelibrary/index.vue @@ -187,7 +187,8 @@ export default { //下载 handleDown(row) { var url = row.fileurl; - window.open(this.apiurl + url); + //window.open(this.apiurl + url); + this.download(row.name,row.fileurl); }, //预览 handleView(row) { diff --git a/ruoyi/src/main/java/com/ruoyi/framework/config/RuoYiConfig.java b/ruoyi/src/main/java/com/ruoyi/framework/config/RuoYiConfig.java index 7bf9d3fc4..77b88cea9 100644 --- a/ruoyi/src/main/java/com/ruoyi/framework/config/RuoYiConfig.java +++ b/ruoyi/src/main/java/com/ruoyi/framework/config/RuoYiConfig.java @@ -106,6 +106,14 @@ public class RuoYiConfig return getProfile() + "/download/"; } + /** + * 获取下载路径 + */ + public static String getDownuploadPath() + { + return getProfile() + "/"; + } + /** * 获取上传路径 */ diff --git a/ruoyi/src/main/java/com/ruoyi/project/common/CommonController.java b/ruoyi/src/main/java/com/ruoyi/project/common/CommonController.java index 846c3001c..70c4bd755 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/common/CommonController.java +++ b/ruoyi/src/main/java/com/ruoyi/project/common/CommonController.java @@ -54,22 +54,25 @@ public class CommonController { * @param delete 是否删除 */ @GetMapping("common/download") - public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { + public void fileDownload(String fileName,String fileUrlPath ,Boolean delete, HttpServletResponse response, HttpServletRequest request) { try { if (!FileUtils.isValidFilename(fileName)) { throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName)); } - String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); - String filePath = RuoYiConfig.getDownloadPath() + fileName; + //String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); + String filePath = RuoYiConfig.getDownuploadPath() + fileUrlPath; + filePath=filePath.replace("/profile/",""); + + System.out.println("filepath"+filePath); response.setCharacterEncoding("utf-8"); response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", - "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName)); + "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, fileName)); FileUtils.writeBytes(filePath, response.getOutputStream()); - if (delete) { - FileUtils.deleteFile(filePath); - } +// if (delete) { +// FileUtils.deleteFile(filePath); +// } } catch (Exception e) { log.error("下载文件失败", e); }