From 5e7b1ebe78b13e18ccbfae6412df2259865ca8a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E7=91=9E=E8=B6=85?= <281809423@qq.com> Date: Mon, 2 Nov 2020 18:21:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B8=E5=9E=8B=E6=A1=88=E4=BE=8B=EF=BC=8C?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87=EF=BC=8C=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=AD=97=E5=85=B8=E5=80=BC=E7=9A=84=E5=8F=96?= =?UTF-8?q?=E5=80=BC=E5=92=8C=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/static/ruoyi/js/common.js | 34 ++++++++++++ .../resources/templates/front/cases/add.html | 43 ++++++--------- .../templates/front/cases/cases.html | 54 +++++++++---------- .../resources/templates/front/cases/edit.html | 31 +++++------ 4 files changed, 91 insertions(+), 71 deletions(-) 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 fc8c9b16c..0fee47b52 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js @@ -455,3 +455,37 @@ $.ajaxSetup({ } } }); + + +//上传文件 +function uploadFile(async, id) { + var formData = new FormData(); + if ($('#filePath')[0].files[0] == null) { + $.modal.alertWarning("请先选择文件路径"); + return false; + } + formData.append('fileName', $("#fileName").val()); + formData.append('file', $('#filePath')[0].files[0]); + $.ajax({ + url: "/common/upload", + type: 'post', + cache: false, + data: formData, + processData: false, + contentType: false, + dataType: "json", + async: async, + success: function(result) { + if (result.code == web_status.SUCCESS && id) { + $('#' + id).val(result.url); + } else { + $.modal.alertError(result.msg); + return; + } + }, + error: function(error) { + $.modal.alertWarning("图片上传失败。"); + return; + } + }); +} \ 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 fe53898ec..b0f13878a 100644 --- a/ruoyi-front/src/main/resources/templates/front/cases/add.html +++ b/ruoyi-front/src/main/resources/templates/front/cases/add.html @@ -27,41 +27,31 @@
- +
- - 代码生成请选择字典属性 -
-
-
- -
- +
+ +
- +
- + +
- +
+ + +
- @@ -74,10 +64,9 @@ function submitHandler() { if ($.validate.form()) { - var data = $("#form-cases-add").serializeArray(); - var status = $("input[id='status']").is(':checked') == true ? 0 : 1; - data.push({"name": "status", "value": status}); - $.operate.save(prefix + "/add", data); + //同步上传图片,并且将上传图片返回的地址,赋值到pictureUrl对应的隐藏域上 + uploadFile(false, "pictureUrl"); + $.operate.save(prefix + "/add", $("#form-cases-add").serialize()); } } diff --git a/ruoyi-front/src/main/resources/templates/front/cases/cases.html b/ruoyi-front/src/main/resources/templates/front/cases/cases.html index 6d5a50f45..e798fab2c 100644 --- a/ruoyi-front/src/main/resources/templates/front/cases/cases.html +++ b/ruoyi-front/src/main/resources/templates/front/cases/cases.html @@ -14,26 +14,26 @@ -
  • +
  • - - - +
  • -
  • +
  • - - +
  • @@ -46,7 +46,7 @@
    - + 添加 @@ -68,6 +68,8 @@ \ No newline at end of file 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 a40a3f65f..fefd270a6 100644 --- a/ruoyi-front/src/main/resources/templates/front/cases/edit.html +++ b/ruoyi-front/src/main/resources/templates/front/cases/edit.html @@ -28,34 +28,29 @@
    - +
    - - 代码生成请选择字典属性 -
    -
    -
    - -
    - +
    + +
    - +
    - + +
    -
    - - +
    + +
    - 代码生成请选择字典属性
    @@ -70,6 +65,8 @@ function submitHandler() { if ($.validate.form()) { + //同步上传图片,并且将上传图片返回的地址,赋值到pictureUrl对应的隐藏域上 + uploadFile(false, "pictureUrl"); $.operate.save(prefix + "/edit", $('#form-cases-edit').serialize()); } }