上传功能调整

This commit is contained in:
丁瑞超 2020-11-03 17:50:02 +08:00
parent b0235e812f
commit a9fa3fc713
7 changed files with 48 additions and 14 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

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

View File

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

View File

@ -39,6 +39,7 @@
<div class="col-sm-8">
<input id="filePath" name="filePath" class="form-control" type="file">
<input id="enclosureUrl" name="enclosureUrl" type="text" hidden>
<input id="enclosureName" name="enclosureName" type="text" hidden>
</div>
</div>
<div class="form-group">
@ -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());
}
}

View File

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

View File

@ -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('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
if (row.enclosureUrl) {
actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.enclosureUrl + '\')"><i class="fa fa-download"></i>下载附件</a>');
}
return actions.join('');
}
}]
};
$.table.init(options);
});
function downLoad(url) {
window.location.href = ctx + "common/download?fileName=" + encodeURI(url) + "&delete=" + true;
}
</script>
</body>
</html>