From a9fa3fc71386c7843c450b5e2985ebbf6cfaeddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E7=91=9E=E8=B6=85?= <281809423@qq.com> Date: Tue, 3 Nov 2020 17:50:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=8A=9F=E8=83=BD=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/common/CommonController.java | 1 + .../main/resources/static/ruoyi/js/common.js | 19 ++++++++++++++----- .../resources/templates/front/cases/add.html | 5 ++++- .../resources/templates/front/cases/edit.html | 5 ++++- .../front/contract_template/add.html | 8 +++++++- .../front/contract_template/edit.html | 7 ++++++- .../front/contract_template/template.html | 17 ++++++++++++----- 7 files changed, 48 insertions(+), 14 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 bca6ca82d..9b2a6af8c 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 @@ -81,6 +81,7 @@ public class CommonController String url = serverConfig.getUrl() + fileName; AjaxResult ajax = AjaxResult.success(); ajax.put("fileName", fileName); + ajax.put("originalFilename", file.getOriginalFilename()); ajax.put("url", url); return ajax; } 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 0fee47b52..06e0c90dd 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js @@ -458,11 +458,12 @@ $.ajaxSetup({ //上传文件 -function uploadFile(async, id) { +function uploadFile(async, filePathId, fileNameId) { + let res = -1; var formData = new FormData(); if ($('#filePath')[0].files[0] == null) { $.modal.alertWarning("请先选择文件路径"); - return false; + return res; } formData.append('fileName', $("#fileName").val()); formData.append('file', $('#filePath')[0].files[0]); @@ -477,15 +478,23 @@ function uploadFile(async, id) { async: async, success: function(result) { if (result.code == web_status.SUCCESS && id) { - $('#' + id).val(result.url); + if (filePathId) { + $('#' + filePathId).val(result.url); + } + if (fileNameId) { + $('#' + fileNameId).val(result.fileName); + } + } else { $.modal.alertError(result.msg); - return; } + + res = result.code; }, error: function(error) { $.modal.alertWarning("图片上传失败。"); - return; } }); + + return res; } \ No newline at end of file diff --git a/ruoyi-front/src/main/resources/templates/front/cases/add.html b/ruoyi-front/src/main/resources/templates/front/cases/add.html index b0f13878a..1d45864ff 100644 --- a/ruoyi-front/src/main/resources/templates/front/cases/add.html +++ b/ruoyi-front/src/main/resources/templates/front/cases/add.html @@ -65,7 +65,10 @@ function submitHandler() { if ($.validate.form()) { //同步上传图片,并且将上传图片返回的地址,赋值到pictureUrl对应的隐藏域上 - uploadFile(false, "pictureUrl"); + let result = uploadFile(false, "pictureUrl"); + if (result != web_status.SUCCESS) { + return; + } $.operate.save(prefix + "/add", $("#form-cases-add").serialize()); } } diff --git a/ruoyi-front/src/main/resources/templates/front/cases/edit.html b/ruoyi-front/src/main/resources/templates/front/cases/edit.html index fefd270a6..3b4c61382 100644 --- a/ruoyi-front/src/main/resources/templates/front/cases/edit.html +++ b/ruoyi-front/src/main/resources/templates/front/cases/edit.html @@ -66,7 +66,10 @@ function submitHandler() { if ($.validate.form()) { //同步上传图片,并且将上传图片返回的地址,赋值到pictureUrl对应的隐藏域上 - uploadFile(false, "pictureUrl"); + let result = uploadFile(false, "pictureUrl"); + if (result != web_status.SUCCESS) { + return; + } $.operate.save(prefix + "/edit", $('#form-cases-edit').serialize()); } } 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 17f46ba13..49c8e8ac5 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 @@ -39,6 +39,7 @@
+
@@ -75,7 +76,12 @@ function submitHandler() { if ($.validate.form()) { //同步上传图片,并且将上传图片返回的地址,赋值到pictureUrl对应的隐藏域上 - uploadFile(false, "enclosureUrl"); + if ($('#filePath')[0].files[0]) { + let result = uploadFile(false, "enclosureUrl", "enclosureName"); + if (result != web_status.SUCCESS) { + return; + } + } $.operate.save(prefix + "/add", $('#form-template-add').serialize()); } } 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 4a665f1fb..a227cf133 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 @@ -76,7 +76,12 @@ function submitHandler() { if ($.validate.form()) { //同步上传图片,并且将上传图片返回的地址,赋值到pictureUrl对应的隐藏域上 - uploadFile(false, "enclosureUrl"); + if ($('#filePath')[0].files[0]) { + let result = uploadFile(false, "enclosureUrl", "enclosureName"); + if (result != web_status.SUCCESS) { + return; + } + } $.operate.save(prefix + "/edit", $('#form-template-edit').serialize()); } } 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 c4ba25a9f..0f496c3ae 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 @@ -98,18 +98,18 @@ field: 'introduction', title: '简介' }, - { + /* { field: 'content', title: '详情内容' - }, + },*/ { field: 'hits', title: '点击量' }, - { + /*{ field: 'enclosureUrl', - title: '附件下载' - }, + title: '附件' + },*/ { field: 'status', title: '状态' @@ -125,12 +125,19 @@ var actions = []; actions.push('编辑 '); actions.push('删除'); + if (row.enclosureUrl) { + actions.push('下载附件'); + } return actions.join(''); } }] }; $.table.init(options); }); + + function downLoad(url) { + window.location.href = ctx + "common/download?fileName=" + encodeURI(url) + "&delete=" + true; + } \ No newline at end of file