From c6bf33ee4c300c9d10171961b49a0a7ed84cf29f Mon Sep 17 00:00:00 2001 From: dingruichao <281809423@qq.com> Date: Tue, 3 Nov 2020 20:55:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/web/controller/common/CommonController.java | 6 +++++- .../src/main/resources/static/ruoyi/js/common.js | 11 +++++++---- .../templates/front/contract_template/add.html | 2 +- .../templates/front/contract_template/edit.html | 4 ++-- .../templates/front/contract_template/template.html | 7 +++---- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java index 24d0c07f5..c6aff5da5 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java @@ -131,7 +131,11 @@ public class CommonController response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); FileUtils.setAttachmentResponseHeader(response, realFileName); - FileUtils.writeBytes(filePath, response.getOutputStream()); + // 本地资源路径 + String localPath = Global.getProfile(); + // 数据库资源地址 + String downloadPath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX); + FileUtils.writeBytes(downloadPath, response.getOutputStream()); if (delete) { FileUtils.deleteFile(filePath); diff --git a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js index 26a5603e5..11a0a4394 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js @@ -458,7 +458,7 @@ $.ajaxSetup({ //上传文件 -function uploadFile(async, filePathId, fileNameId) { +function uploadFile(async, fullPathId, fileNameId, absolutePAthId) { let res = -1; var formData = new FormData(); if ($('#filePath')[0].files[0] == null) { @@ -477,13 +477,16 @@ function uploadFile(async, filePathId, fileNameId) { dataType: "json", async: async, success: function(result) { - if (result.code == web_status.SUCCESS && id) { - if (filePathId) { - $('#' + filePathId).val(result.url); + if (result.code == web_status.SUCCESS) { + if (fullPathId) { + $('#' + fullPathId).val(result.url); } if (fileNameId) { $('#' + fileNameId).val(result.originalFilename); } + if (absolutePAthId) { + $('#' + absolutePAthId).val(result.fileName); + } } else { $.modal.alertError(result.msg); diff --git a/ruoyi-front/src/main/resources/templates/front/contract_template/add.html b/ruoyi-front/src/main/resources/templates/front/contract_template/add.html index 49c8e8ac5..d8109e45c 100644 --- a/ruoyi-front/src/main/resources/templates/front/contract_template/add.html +++ b/ruoyi-front/src/main/resources/templates/front/contract_template/add.html @@ -77,7 +77,7 @@ if ($.validate.form()) { //同步上传图片,并且将上传图片返回的地址,赋值到pictureUrl对应的隐藏域上 if ($('#filePath')[0].files[0]) { - let result = uploadFile(false, "enclosureUrl", "enclosureName"); + let result = uploadFile(false, null , "enclosureName", "enclosureUrl"); if (result != web_status.SUCCESS) { return; } diff --git a/ruoyi-front/src/main/resources/templates/front/contract_template/edit.html b/ruoyi-front/src/main/resources/templates/front/contract_template/edit.html index 5fa780604..ac99539a3 100644 --- a/ruoyi-front/src/main/resources/templates/front/contract_template/edit.html +++ b/ruoyi-front/src/main/resources/templates/front/contract_template/edit.html @@ -44,7 +44,7 @@
- +
@@ -78,7 +78,7 @@ if ($.validate.form()) { //同步上传图片,并且将上传图片返回的地址,赋值到pictureUrl对应的隐藏域上 if ($('#filePath')[0].files[0]) { - let result = uploadFile(false, "enclosureUrl", "enclosureName"); + let result = uploadFile(false, null , "enclosureName", "enclosureUrl"); if (result != web_status.SUCCESS) { return; } diff --git a/ruoyi-front/src/main/resources/templates/front/contract_template/template.html b/ruoyi-front/src/main/resources/templates/front/contract_template/template.html index 5a220eb48..165286417 100644 --- a/ruoyi-front/src/main/resources/templates/front/contract_template/template.html +++ b/ruoyi-front/src/main/resources/templates/front/contract_template/template.html @@ -124,9 +124,9 @@ formatter: function(value, row, index) { var actions = []; actions.push('编辑 '); - actions.push('删除'); + actions.push('删除 '); if (row.enclosureUrl) { - actions.push('下载附件'); + actions.push('下载附件'); } return actions.join(''); } @@ -136,8 +136,7 @@ }); function downLoad(fileUrl,realFileName) { - alert(ctx + "common/download2?filePath = " + fileUrl + "&realFileName=" + encodeURI(realFileName) + "&delete=" + false); - window.location.href = ctx + "common/download2?filePath = " + fileUrl + "&realFileName=" + encodeURI(realFileName) + "&delete=" + false; + window.location.href = ctx + "common/download2?filePath=" + encodeURI(fileUrl) + "&realFileName=" + encodeURI(realFileName) + "&delete=" + false; }