新增示例(多图上传)

master
RuoYi 2021-07-06 17:54:39 +08:00
parent 7a72ce37e6
commit 06edfaddb8
5 changed files with 127 additions and 21 deletions

View File

@ -1,5 +1,7 @@
package com.ruoyi.web.controller.common;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
@ -15,6 +17,7 @@ import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.config.ServerConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.FileInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
@ -65,7 +68,7 @@ public class CommonController
}
/**
*
*
*/
@PostMapping("/common/upload")
@ResponseBody
@ -89,6 +92,33 @@ public class CommonController
}
}
/**
*
*/
@PostMapping("/common/uploads")
@ResponseBody
public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception
{
try
{
// 上传文件路径
String filePath = RuoYiConfig.getUploadPath();
List<FileInfo> fileInfos = new LinkedList<FileInfo>();
for (MultipartFile file : files)
{
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file);
String url = serverConfig.getUrl() + fileName;
fileInfos.add(new FileInfo(fileName, url));
}
return AjaxResult.success(fileInfos);
}
catch (Exception e)
{
return AjaxResult.error(e.getMessage());
}
}
/**
*
*/

View File

@ -243,6 +243,7 @@ public class SysRoleController extends BaseController
/**
*
*/
@RequiresPermissions("system:role:edit")
@Log(title = "角色管理", businessType = BusinessType.GRANT)
@PostMapping("/authUser/cancel")
@ResponseBody
@ -254,6 +255,7 @@ public class SysRoleController extends BaseController
/**
*
*/
@RequiresPermissions("system:role:edit")
@Log(title = "角色管理", businessType = BusinessType.GRANT)
@PostMapping("/authUser/cancelAll")
@ResponseBody
@ -288,6 +290,7 @@ public class SysRoleController extends BaseController
/**
*
*/
@RequiresPermissions("system:role:edit")
@Log(title = "角色管理", businessType = BusinessType.GRANT)
@PostMapping("/authUser/selectAll")
@ResponseBody

View File

@ -14,16 +14,16 @@
</div>
<div class="ibox-content">
<div class="form-group">
<label class="font-noraml">简单示例</label>
<label class="font-noraml">单文件上传</label>
<div class="file-loading">
<input class="file" type="file" multiple data-min-file-count="1" data-theme="fas">
<input id="singleFile" name="file" type="file">
</div>
</div>
<div class="form-group">
<label class="font-noraml">多文件上传</label>
<div class="file-loading">
<input id="fileinput-demo-1" type="file" multiple>
<input id="multipleFile" name="files" type="file" multiple>
</div>
</div>
<hr>
@ -38,25 +38,36 @@
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<script type="text/javascript">
<script th:inline="javascript">
$(document).ready(function () {
$("#fileinput-demo-1").fileinput({
'theme': 'explorer-fas',
'uploadUrl': '#',
overwriteInitial: false,
initialPreviewAsData: true,
initialPreview: [
"/img/profile.jpg"
]
});
$("#fileinput-demo-1").on("fileuploaded", function(event, data, proviewId, index) {
console.info(event);
console.info(data);
console.info(proviewId);
console.info(index);
});
// 单图上传
$("#singleFile").fileinput({
uploadUrl: ctx + 'common/upload',
maxFileCount: 1,
autoReplace: true
}).on('fileuploaded', function (event, data, previewId, index) {
var rsp = data.response;
log.info("return url" + rsp.url)
log.info("reutrn fileName" + rsp.fileName)
}).on('fileremoved', function (event, id, index) {
$("input[name='" + event.currentTarget.id + "']").val('')
})
// 多图上传
$("#multipleFile").fileinput({
uploadUrl: ctx + 'common/uploads',
uploadAsync: false
}).on('filebatchuploadsuccess', function (event, data, previewId, index) {
var rsp = data.response;
var fileJson = rsp.data;
for (var i in fileJson) {
log.info("return data.url" + fileJson[i].url)
log.info("reutrn data.name" + fileJson[i].name)
}
}).on('fileremoved', function (event, id, index) {
$("input[name='" + event.currentTarget.id + "']").val('')
})
});
</script>
</body>

View File

@ -0,0 +1,61 @@
package com.ruoyi.common.core.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
*
*
* @author ruoyi
*/
public class FileInfo
{
/**
*
*/
private String name;
/**
*
*/
private String url;
public FileInfo()
{
}
public FileInfo(String name, String url)
{
this.name = name;
this.url = url;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getUrl()
{
return url;
}
public void setUrl(String url)
{
this.url = url;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("name", getName())
.append("url", getUrl())
.toString();
}
}

View File

@ -265,6 +265,7 @@ public class SysUserServiceImpl implements ISysUserService
* @param roleIds
*/
@Override
@Transactional
public void insertUserAuth(Long userId, Long[] roleIds)
{
userRoleMapper.deleteUserRoleByUserId(userId);