上传功能优化
This commit is contained in:
parent
e2f50b32e6
commit
c6bf33ee4c
|
|
@ -131,7 +131,11 @@ public class CommonController
|
|||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
FileUtils.setAttachmentResponseHeader(response, realFileName);
|
||||
|
||||
FileUtils.writeBytes(filePath, response.getOutputStream());
|
||||
// 本地资源路径
|
||||
String localPath = Global.getProfile();
|
||||
// 数据库资源地址
|
||||
String downloadPath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
|
||||
FileUtils.writeBytes(downloadPath, response.getOutputStream());
|
||||
if (delete)
|
||||
{
|
||||
FileUtils.deleteFile(filePath);
|
||||
|
|
|
|||
|
|
@ -458,7 +458,7 @@ $.ajaxSetup({
|
|||
|
||||
|
||||
//上传文件
|
||||
function uploadFile(async, filePathId, fileNameId) {
|
||||
function uploadFile(async, fullPathId, fileNameId, absolutePAthId) {
|
||||
let res = -1;
|
||||
var formData = new FormData();
|
||||
if ($('#filePath')[0].files[0] == null) {
|
||||
|
|
@ -477,13 +477,16 @@ function uploadFile(async, filePathId, fileNameId) {
|
|||
dataType: "json",
|
||||
async: async,
|
||||
success: function(result) {
|
||||
if (result.code == web_status.SUCCESS && id) {
|
||||
if (filePathId) {
|
||||
$('#' + filePathId).val(result.url);
|
||||
if (result.code == web_status.SUCCESS) {
|
||||
if (fullPathId) {
|
||||
$('#' + fullPathId).val(result.url);
|
||||
}
|
||||
if (fileNameId) {
|
||||
$('#' + fileNameId).val(result.originalFilename);
|
||||
}
|
||||
if (absolutePAthId) {
|
||||
$('#' + absolutePAthId).val(result.fileName);
|
||||
}
|
||||
|
||||
} else {
|
||||
$.modal.alertError(result.msg);
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@
|
|||
if ($.validate.form()) {
|
||||
//同步上传图片,并且将上传图片返回的地址,赋值到pictureUrl对应的隐藏域上
|
||||
if ($('#filePath')[0].files[0]) {
|
||||
let result = uploadFile(false, "enclosureUrl", "enclosureName");
|
||||
let result = uploadFile(false, null , "enclosureName", "enclosureUrl");
|
||||
if (result != web_status.SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label is-required">附件:</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="filePath" name="filePath" class="form-control" type="file">
|
||||
<input id="filePath" name="filePath" class="form-control" type="file" th:text="*{enclosureName}">
|
||||
<input id="enclosureUrl" name="enclosureUrl" type="text" hidden>
|
||||
<input id="enclosureName" name="enclosureName" type="text" hidden>
|
||||
</div>
|
||||
|
|
@ -78,7 +78,7 @@
|
|||
if ($.validate.form()) {
|
||||
//同步上传图片,并且将上传图片返回的地址,赋值到pictureUrl对应的隐藏域上
|
||||
if ($('#filePath')[0].files[0]) {
|
||||
let result = uploadFile(false, "enclosureUrl", "enclosureName");
|
||||
let result = uploadFile(false, null , "enclosureName", "enclosureUrl");
|
||||
if (result != web_status.SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,9 +124,9 @@
|
|||
formatter: function(value, row, index) {
|
||||
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>');
|
||||
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="downLoad(\'' + row.enclosureUrl + '\', \'' + row.enclosureName+ '\')"><i class="fa fa-download"></i>下载附件</a>');
|
||||
actions.push('<a class="btn btn-warning btn-xs " href="javascript:void(0)" onclick="downLoad(\'' + row.enclosureUrl + '\', \'' + row.enclosureName+ '\')"><i class="fa fa-download"></i>下载附件</a>');
|
||||
}
|
||||
return actions.join('');
|
||||
}
|
||||
|
|
@ -136,8 +136,7 @@
|
|||
});
|
||||
|
||||
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;
|
||||
window.location.href = ctx + "common/download2?filePath=" + encodeURI(fileUrl) + "&realFileName=" + encodeURI(realFileName) + "&delete=" + false;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Reference in New Issue