新增示例(多图上传)
parent
7a72ce37e6
commit
06edfaddb8
|
@ -1,5 +1,7 @@
|
||||||
package com.ruoyi.web.controller.common;
|
package com.ruoyi.web.controller.common;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -15,6 +17,7 @@ import com.ruoyi.common.config.RuoYiConfig;
|
||||||
import com.ruoyi.common.config.ServerConfig;
|
import com.ruoyi.common.config.ServerConfig;
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
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.StringUtils;
|
||||||
import com.ruoyi.common.utils.file.FileUploadUtils;
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
||||||
import com.ruoyi.common.utils.file.FileUtils;
|
import com.ruoyi.common.utils.file.FileUtils;
|
||||||
|
@ -65,7 +68,7 @@ public class CommonController
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用上传请求
|
* 通用上传请求(单个)
|
||||||
*/
|
*/
|
||||||
@PostMapping("/common/upload")
|
@PostMapping("/common/upload")
|
||||||
@ResponseBody
|
@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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地资源通用下载
|
* 本地资源通用下载
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -243,6 +243,7 @@ public class SysRoleController extends BaseController
|
||||||
/**
|
/**
|
||||||
* 取消授权
|
* 取消授权
|
||||||
*/
|
*/
|
||||||
|
@RequiresPermissions("system:role:edit")
|
||||||
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
||||||
@PostMapping("/authUser/cancel")
|
@PostMapping("/authUser/cancel")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@ -254,6 +255,7 @@ public class SysRoleController extends BaseController
|
||||||
/**
|
/**
|
||||||
* 批量取消授权
|
* 批量取消授权
|
||||||
*/
|
*/
|
||||||
|
@RequiresPermissions("system:role:edit")
|
||||||
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
||||||
@PostMapping("/authUser/cancelAll")
|
@PostMapping("/authUser/cancelAll")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@ -288,6 +290,7 @@ public class SysRoleController extends BaseController
|
||||||
/**
|
/**
|
||||||
* 批量选择用户授权
|
* 批量选择用户授权
|
||||||
*/
|
*/
|
||||||
|
@RequiresPermissions("system:role:edit")
|
||||||
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
||||||
@PostMapping("/authUser/selectAll")
|
@PostMapping("/authUser/selectAll")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
|
|
@ -14,16 +14,16 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="ibox-content">
|
<div class="ibox-content">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="font-noraml">简单示例</label>
|
<label class="font-noraml">单文件上传</label>
|
||||||
<div class="file-loading">
|
<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>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="font-noraml">多文件上传</label>
|
<label class="font-noraml">多文件上传</label>
|
||||||
<div class="file-loading">
|
<div class="file-loading">
|
||||||
<input id="fileinput-demo-1" type="file" multiple>
|
<input id="multipleFile" name="files" type="file" multiple>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -38,25 +38,36 @@
|
||||||
</div>
|
</div>
|
||||||
<th:block th:include="include :: footer" />
|
<th:block th:include="include :: footer" />
|
||||||
<th:block th:include="include :: bootstrap-fileinput-js" />
|
<th:block th:include="include :: bootstrap-fileinput-js" />
|
||||||
<script type="text/javascript">
|
<script th:inline="javascript">
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$("#fileinput-demo-1").fileinput({
|
// 单图上传
|
||||||
'theme': 'explorer-fas',
|
$("#singleFile").fileinput({
|
||||||
'uploadUrl': '#',
|
uploadUrl: ctx + 'common/upload',
|
||||||
overwriteInitial: false,
|
maxFileCount: 1,
|
||||||
initialPreviewAsData: true,
|
autoReplace: true
|
||||||
initialPreview: [
|
}).on('fileuploaded', function (event, data, previewId, index) {
|
||||||
"/img/profile.jpg"
|
var rsp = data.response;
|
||||||
]
|
log.info("return url:" + rsp.url)
|
||||||
});
|
log.info("reutrn fileName:" + rsp.fileName)
|
||||||
|
}).on('fileremoved', function (event, id, index) {
|
||||||
$("#fileinput-demo-1").on("fileuploaded", function(event, data, proviewId, index) {
|
$("input[name='" + event.currentTarget.id + "']").val('')
|
||||||
console.info(event);
|
})
|
||||||
console.info(data);
|
|
||||||
console.info(proviewId);
|
|
||||||
console.info(index);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
// 多图上传
|
||||||
|
$("#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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -265,6 +265,7 @@ public class SysUserServiceImpl implements ISysUserService
|
||||||
* @param roleIds 角色组
|
* @param roleIds 角色组
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void insertUserAuth(Long userId, Long[] roleIds)
|
public void insertUserAuth(Long userId, Long[] roleIds)
|
||||||
{
|
{
|
||||||
userRoleMapper.deleteUserRoleByUserId(userId);
|
userRoleMapper.deleteUserRoleByUserId(userId);
|
||||||
|
|
Loading…
Reference in New Issue