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()); } }