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 9b2a6af8c..24d0c07f5 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 @@ -110,4 +110,36 @@ public class CommonController FileUtils.writeBytes(downloadPath, response.getOutputStream()); } + + /** + * 通用下载请求 + * + * @param filePath 文件路径 + * @param realFileName 文件名称 + * @param delete 是否删除 + */ + @GetMapping("common/download2") + public void fileDownload(String filePath, String realFileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) + { + try + { + if (!FileUtils.isValidFilename(realFileName)) + { + throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", realFileName)); + } + + response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + FileUtils.setAttachmentResponseHeader(response, realFileName); + + FileUtils.writeBytes(filePath, response.getOutputStream()); + if (delete) + { + FileUtils.deleteFile(filePath); + } + } + catch (Exception e) + { + log.error("下载文件失败", e); + } + } } diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index e46f8be01..7e2a33fe7 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -96,9 +96,9 @@ shiro: # 首页地址 indexUrl: /index # 验证码开关 - captchaEnabled: true + captchaEnabled: false # 验证码类型 math 数组计算 char 字符 - captchaType: math + captchaType: char cookie: # 设置Cookie的域名 默认空,即当前访问的域名 domain: 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 06e0c90dd..26a5603e5 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js @@ -482,7 +482,7 @@ function uploadFile(async, filePathId, fileNameId) { $('#' + filePathId).val(result.url); } if (fileNameId) { - $('#' + fileNameId).val(result.fileName); + $('#' + fileNameId).val(result.originalFilename); } } else { diff --git a/ruoyi-front/src/main/java/com/ruoyi/front/domain/ContractTemplate.java b/ruoyi-front/src/main/java/com/ruoyi/front/domain/ContractTemplate.java index e10e448c9..83c1bdc54 100644 --- a/ruoyi-front/src/main/java/com/ruoyi/front/domain/ContractTemplate.java +++ b/ruoyi-front/src/main/java/com/ruoyi/front/domain/ContractTemplate.java @@ -39,9 +39,12 @@ public class ContractTemplate extends BaseEntity private Integer hits; /** 附件下载(多个地址用,分隔) */ - @Excel(name = "附件下载", readConverterExp = "多=个地址用,分隔") + @Excel(name = "附件地址") private String enclosureUrl; + @Excel(name = "附件名称") + private String enclosureName; + /** 状态(0正常 1停用) */ @Excel(name = "状态", readConverterExp = "0=正常,1=停用") private String status; @@ -131,6 +134,14 @@ public class ContractTemplate extends BaseEntity return delFlag; } + public String getEnclosureName() { + return enclosureName; + } + + public void setEnclosureName(String enclosureName) { + this.enclosureName = enclosureName; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-front/src/main/resources/mapper/front/ContractTemplateMapper.xml b/ruoyi-front/src/main/resources/mapper/front/ContractTemplateMapper.xml index 832d1c261..063af4fd3 100644 --- a/ruoyi-front/src/main/resources/mapper/front/ContractTemplateMapper.xml +++ b/ruoyi-front/src/main/resources/mapper/front/ContractTemplateMapper.xml @@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -22,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, type, title, introduction, content, hits, enclosure_url, status, del_flag, create_by, create_time, update_by, update_time, remark from contract_template + select id, type, title, introduction, content, hits,enclosure_name, enclosure_url, status, del_flag, create_by, create_time, update_by, update_time, remark from contract_template @@ -52,6 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" content, hits, enclosure_url, + enclosure_name, status, del_flag, create_by, @@ -67,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{content}, #{hits}, #{enclosureUrl}, + #{enclosureName}, #{status}, #{delFlag}, #{createBy}, @@ -86,6 +89,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" content = #{content}, hits = #{hits}, enclosure_url = #{enclosureUrl}, + enclosure_name = #{enclosureName}, status = #{status}, del_flag = #{delFlag}, create_by = #{createBy}, 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 a227cf133..5fa780604 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 @@ -46,6 +46,7 @@ + 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 0f496c3ae..5a220eb48 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 @@ -126,7 +126,7 @@ actions.push('编辑 '); actions.push('删除'); if (row.enclosureUrl) { - actions.push('下载附件'); + actions.push('下载附件'); } return actions.join(''); } @@ -135,8 +135,9 @@ $.table.init(options); }); - function downLoad(url) { - window.location.href = ctx + "common/download?fileName=" + encodeURI(url) + "&delete=" + true; + 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; }