完善基础代码
This commit is contained in:
parent
d9ef706d0e
commit
b693d3472c
@ -10,5 +10,5 @@ package ink.wgink.module.file.config.properties;
|
||||
* @Date: 2020/5/31 16:50
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class FileMediaAppMaxDurationProperties extends com.cm.common.config.properties.FileMediaBaseMaxDurationProperties {
|
||||
public class FileMediaAppMaxDurationProperties extends FileMediaBaseMaxDurationProperties {
|
||||
}
|
||||
|
@ -10,5 +10,5 @@ package ink.wgink.module.file.config.properties;
|
||||
* @Date: 2020/5/31 16:50
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class FileMediaBackendMaxDurationProperties extends com.cm.common.config.properties.FileMediaBaseMaxDurationProperties {
|
||||
public class FileMediaBackendMaxDurationProperties extends FileMediaBaseMaxDurationProperties {
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ package ink.wgink.module.file.config.properties;
|
||||
public class FileMediaMaxDurationProperties {
|
||||
|
||||
private FileMediaBackendMaxDurationProperties backend;
|
||||
private com.cm.common.config.properties.FileMediaAppMaxDurationProperties app;
|
||||
private FileMediaAppMaxDurationProperties app;
|
||||
private FileMediaWechatMaxDurationProperties wechat;
|
||||
|
||||
public FileMediaBackendMaxDurationProperties getBackend() {
|
||||
@ -24,11 +24,11 @@ public class FileMediaMaxDurationProperties {
|
||||
this.backend = backend;
|
||||
}
|
||||
|
||||
public com.cm.common.config.properties.FileMediaAppMaxDurationProperties getApp() {
|
||||
public FileMediaAppMaxDurationProperties getApp() {
|
||||
return app;
|
||||
}
|
||||
|
||||
public void setApp(com.cm.common.config.properties.FileMediaAppMaxDurationProperties app) {
|
||||
public void setApp(FileMediaAppMaxDurationProperties app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
|
@ -10,5 +10,5 @@ package ink.wgink.module.file.config.properties;
|
||||
* @Date: 2020/5/31 16:50
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class FileMediaWechatMaxDurationProperties extends com.cm.common.config.properties.FileMediaBaseMaxDurationProperties {
|
||||
public class FileMediaWechatMaxDurationProperties extends FileMediaBaseMaxDurationProperties {
|
||||
}
|
||||
|
@ -0,0 +1,172 @@
|
||||
package ink.wgink.module.file.controller.api;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.common.base.DefaultBaseController;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.file.config.properties.FileProperties;
|
||||
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||
import ink.wgink.module.file.pojo.dtos.FileDTO;
|
||||
import ink.wgink.module.file.pojo.dtos.FileInfoDTO;
|
||||
import ink.wgink.module.file.service.IFileService;
|
||||
import ink.wgink.pojo.ListPage;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.pojo.result.SuccessResult;
|
||||
import ink.wgink.pojo.result.SuccessResultData;
|
||||
import ink.wgink.pojo.result.SuccessResultList;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: FileController
|
||||
* @Description: 文件处理
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/3/10 7:03 PM
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "文件管理接口")
|
||||
@RestController
|
||||
@RequestMapping(ISystemConstant.API_PREFIX + "/file")
|
||||
public class FileController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private IFileService fileService;
|
||||
@Autowired
|
||||
private FileProperties fileProperties;
|
||||
|
||||
@ApiOperation(value = "文件分页列表", notes = "文件分页列表接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
|
||||
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"),
|
||||
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"),
|
||||
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"),
|
||||
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("listpageinfo")
|
||||
public SuccessResultList<List<FileInfoDTO>> listPageInfo(ListPage page) {
|
||||
Map<String, Object> params = requestParams();
|
||||
page.setParams(params);
|
||||
return fileService.listPageInfo(page);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除文章类别(id列表)", notes = "删除文章类别(id列表)接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "ids", value = "ID列表,用下划线分隔", paramType = "path", example = "1_2_3")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@DeleteMapping("remove/{isRemoveSource}/{ids}")
|
||||
public synchronized SuccessResult remove(@PathVariable() Integer isRemoveSource, @PathVariable("ids") String ids) {
|
||||
if (isRemoveSource == 0) {
|
||||
fileService.remove(ids);
|
||||
}
|
||||
if (isRemoveSource == 1) {
|
||||
fileService.delete(ids);
|
||||
}
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传文件", notes = "上传文件接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "file", value = "文件name", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadfile")
|
||||
public SuccessResultData<String> uploadFile(@RequestParam("file") MultipartFile file) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(file, UploadTypeEnum.FILE, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传图片", notes = "上传图片接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "image", value = "文件name", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadimage")
|
||||
public SuccessResultData<String> uploadImage(@RequestParam("image") MultipartFile image) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(image, UploadTypeEnum.IMAGE, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传视频", notes = "上传视频接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "video", value = "文件video", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadvideo")
|
||||
public SuccessResultData<String> uploadVideo(@RequestParam("video") MultipartFile video) {
|
||||
if (fileProperties.getMediaMaxDuration() != null && fileProperties.getMediaMaxDuration().getBackend() != null) {
|
||||
fileService.checkVideoDurationAllow(video, fileProperties.getMediaMaxDuration().getBackend().getVideo());
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(video, UploadTypeEnum.VIDEO, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传音频", notes = "上传音频接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "audio", value = "文件audio", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadaudio")
|
||||
public SuccessResultData<String> uploadAudio(@RequestParam("audio") MultipartFile audio) {
|
||||
if (fileProperties.getMediaMaxDuration() != null && fileProperties.getMediaMaxDuration().getBackend() != null) {
|
||||
fileService.checkAudioDurationAllow(audio, fileProperties.getMediaMaxDuration().getBackend().getAudio());
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(audio, UploadTypeEnum.AUDIO, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "文件列表", notes = "文件列表接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "ids", value = "id列表,逗号分隔", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("list")
|
||||
public List<FileDTO> listFileByFileId(@RequestParam("ids") String ids) {
|
||||
List<String> idList = Arrays.asList(ids.split(","));
|
||||
return fileService.list(idList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param uploadFile
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
private SuccessResultData<String> uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) {
|
||||
return fileService.uploadSingle(uploadFile, uploadTypeEnum, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 百度富文本编辑器
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping("ueditor")
|
||||
public JSONObject uEditor(MultipartFile file, HttpServletRequest request) throws IOException {
|
||||
Map<String, Object> params = requestParams();
|
||||
return fileService.uEditor(file, request, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传图片", notes = "上传图片接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "image", value = "文件name", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("wangeditorimage")
|
||||
public JSONObject wangEditorImage(MultipartFile image, HttpServletRequest request) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return fileService.wangEditorImage(image, UploadTypeEnum.IMAGE, params);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
package ink.wgink.module.file.controller.app.api;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import ink.wgink.common.base.DefaultBaseController;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.file.config.properties.FileProperties;
|
||||
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||
import ink.wgink.module.file.pojo.dtos.FileDTO;
|
||||
import ink.wgink.module.file.service.IFileService;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.pojo.result.SuccessResultData;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: FileAppController
|
||||
* @Description: APP文件上传
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019-08-02 15:38
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "文件管理接口")
|
||||
@RestController
|
||||
@RequestMapping(ISystemConstant.APP_PREFIX + "/file")
|
||||
public class FileAppController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private IFileService fileService;
|
||||
@Autowired
|
||||
private FileProperties fileProperties;
|
||||
|
||||
@ApiOperation(value = "上传文件", notes = "上传文件接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
|
||||
@ApiImplicitParam(name = "file", value = "文件name", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadfile")
|
||||
public SuccessResultData<String> uploadFile(@RequestHeader("token") String token, @RequestParam("file") MultipartFile file) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(token, file, UploadTypeEnum.FILE, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传图片", notes = "上传图片接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
|
||||
@ApiImplicitParam(name = "image", value = "文件name", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadimage")
|
||||
public SuccessResultData<String> uploadImage(@RequestHeader("token") String token, @RequestParam("image") MultipartFile image) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(token, image, UploadTypeEnum.IMAGE, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传视频", notes = "上传视频接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
|
||||
@ApiImplicitParam(name = "video", value = "文件video", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadvideo")
|
||||
public SuccessResultData<String> uploadVideo(@RequestHeader("token") String token, @RequestParam("video") MultipartFile video) {
|
||||
if (fileProperties.getMediaMaxDuration() != null && fileProperties.getMediaMaxDuration().getApp() != null) {
|
||||
fileService.checkVideoDurationAllow(video, fileProperties.getMediaMaxDuration().getApp().getVideo());
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(token, video, UploadTypeEnum.VIDEO, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传音频", notes = "上传音频接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
|
||||
@ApiImplicitParam(name = "audio", value = "文件audio", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadaudio")
|
||||
public SuccessResultData<String> uploadAudio(@RequestHeader("token") String token, @RequestParam("audio") MultipartFile audio) {
|
||||
if (fileProperties.getMediaMaxDuration() != null && fileProperties.getMediaMaxDuration().getApp() != null) {
|
||||
fileService.checkAudioDurationAllow(audio, fileProperties.getMediaMaxDuration().getApp().getAudio());
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(token, audio, UploadTypeEnum.AUDIO, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传图片", notes = "上传图片接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "image", value = "文件name", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("wangeditorimage")
|
||||
public JSONObject wangEditorImage(MultipartFile image, HttpServletRequest request) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return fileService.wangEditorImage(image, UploadTypeEnum.IMAGE, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "文件列表", notes = "文件列表接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "ids", value = "id列表,逗号分隔", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("list")
|
||||
public List<FileDTO> listFileByFileId(@RequestParam("ids") String ids) {
|
||||
List<String> idList = Arrays.asList(ids.split(","));
|
||||
return fileService.list(idList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param uploadFile
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
private SuccessResultData<String> uploadSingle(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) {
|
||||
return fileService.uploadSingle(token, uploadFile, uploadTypeEnum, params);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
package ink.wgink.module.file.controller.route;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseController;
|
||||
import ink.wgink.exceptions.ParamsException;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.file.config.properties.FileProperties;
|
||||
import ink.wgink.module.file.service.IFileService;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import io.swagger.annotations.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: FileController
|
||||
* @Description: 文件
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/3/11 2:45 PM
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "文件管理接口")
|
||||
@Controller
|
||||
@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/file")
|
||||
public class FileRouteController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private IFileService fileService;
|
||||
@Autowired
|
||||
private FileProperties fileProperties;
|
||||
|
||||
/**
|
||||
* 文件页面
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("listinfo")
|
||||
public ModelAndView listFileInfo() {
|
||||
ModelAndView mv = new ModelAndView("file/list-info");
|
||||
return mv;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "打开文件上传", notes = "打开文件上传接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "uploadType", value = "文件类型,1:文件,2:图片,3:视频,4:音频", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("uploadfile/{uploadType}")
|
||||
public ModelAndView uploadFile(@PathVariable("uploadType") String uploadType) {
|
||||
ModelAndView mv = new ModelAndView("file/file-upload");
|
||||
return getUploadFileModelAndView(mv, uploadType);
|
||||
}
|
||||
|
||||
private ModelAndView getUploadFileModelAndView(ModelAndView mv, String uploadType) {
|
||||
if (!IFileService.UPLOAD_FILE_TYPE.equals(uploadType) &&
|
||||
!IFileService.UPLOAD_IMAGE_TYPE.equals(uploadType) &&
|
||||
!IFileService.UPLOAD_VIDEO_TYPE.equals(uploadType) &&
|
||||
!IFileService.UPLOAD_AUDIO_TYPE.equals(uploadType)) {
|
||||
throw new ParamsException("参数错误");
|
||||
}
|
||||
if (IFileService.UPLOAD_FILE_TYPE.equals(uploadType)) {
|
||||
mv.addObject("uploadPath", "uploadfile");
|
||||
mv.addObject("updateInputName", "file");
|
||||
mv.addObject("allowFiles", fileProperties.getFileTypes());
|
||||
}
|
||||
if (IFileService.UPLOAD_IMAGE_TYPE.equals(uploadType)) {
|
||||
mv.addObject("uploadPath", "uploadimage");
|
||||
mv.addObject("updateInputName", "image");
|
||||
mv.addObject("allowFiles", fileProperties.getImageTypes());
|
||||
}
|
||||
if (IFileService.UPLOAD_VIDEO_TYPE.equals(uploadType)) {
|
||||
mv.addObject("uploadPath", "uploadvideo");
|
||||
mv.addObject("updateInputName", "video");
|
||||
mv.addObject("allowFiles", fileProperties.getVideoTypes());
|
||||
}
|
||||
if (IFileService.UPLOAD_AUDIO_TYPE.equals(uploadType)) {
|
||||
mv.addObject("uploadPath", "uploadaudio");
|
||||
mv.addObject("updateInputName", "audio");
|
||||
mv.addObject("allowFiles", fileProperties.getAudioTypes());
|
||||
}
|
||||
mv.addObject("uploadType", uploadType);
|
||||
mv.addObject("maxFileCount", fileProperties.getMaxFileCount());
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("uploadimage")
|
||||
public ModelAndView uploadImage() {
|
||||
Map<String, Object> params = requestParams();
|
||||
ModelAndView mv = new ModelAndView("file/image-upload");
|
||||
return getUploadImageModelAndView(mv, params);
|
||||
}
|
||||
|
||||
private ModelAndView getUploadImageModelAndView(ModelAndView mv, Map<String, Object> params) {
|
||||
if (!StringUtils.isBlank(params.get("fileId") == null ? null : params.get("fileId").toString())) {
|
||||
mv.addObject("fileId", params.get("fileId"));
|
||||
} else {
|
||||
mv.addObject("fileId", "");
|
||||
}
|
||||
return mv;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "下载文件", notes = "下载文件接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "isOpen", value = "是否打开,true和false", paramType = "path"),
|
||||
@ApiImplicitParam(name = "fileId", value = "文件ID", paramType = "path")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("download/{isOpen}/{fileId}")
|
||||
public void downLoad(HttpServletRequest request, HttpServletResponse response, @PathVariable("isOpen") String isOpen, @PathVariable("fileId") String fileId) {
|
||||
if (!ISystemConstant.IS_TRUE.equals(isOpen) && !ISystemConstant.IS_FALSE.equals(isOpen)) {
|
||||
throw new ParamsException("参数错误");
|
||||
}
|
||||
if (fileId.indexOf(".") > 0) {
|
||||
fileId = fileId.split("\\.")[0];
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
params.put("fileId", fileId);
|
||||
params.put("isOpen", isOpen);
|
||||
fileService.downLoadFile(request, response, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示文件
|
||||
*
|
||||
* @param type
|
||||
* @param fileId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("show/{type}/{fileId}")
|
||||
public ModelAndView show(@PathVariable("type") String type, @PathVariable("fileId") String fileId) {
|
||||
ModelAndView mv = new ModelAndView("file/show");
|
||||
mv.addObject("type", type);
|
||||
mv.addObject("fileId", fileId);
|
||||
return mv;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package ink.wgink.module.file.controller.wechat;
|
||||
|
||||
import ink.wgink.common.base.DefaultBaseController;
|
||||
import ink.wgink.interfaces.consts.ISystemConstant;
|
||||
import ink.wgink.module.file.config.properties.FileProperties;
|
||||
import ink.wgink.module.file.enums.UploadTypeEnum;
|
||||
import ink.wgink.module.file.pojo.dtos.FileDTO;
|
||||
import ink.wgink.module.file.service.IFileService;
|
||||
import ink.wgink.pojo.result.ErrorResult;
|
||||
import ink.wgink.pojo.result.SuccessResultData;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: FileWechatController
|
||||
* @Description: 微信文件
|
||||
* @Author: WangGeng
|
||||
* @Date: 2020/3/8 9:39 上午
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Api(tags = ISystemConstant.API_TAGS_WECHAT_PREFIX + "文件管理接口")
|
||||
@RestController
|
||||
@RequestMapping(ISystemConstant.WECHAT_PREFIX + "/file")
|
||||
public class FileWechatController extends DefaultBaseController {
|
||||
|
||||
@Autowired
|
||||
private IFileService fileService;
|
||||
@Autowired
|
||||
private FileProperties fileProperties;
|
||||
|
||||
@ApiOperation(value = "上传文件", notes = "上传文件接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
|
||||
@ApiImplicitParam(name = "file", value = "文件name", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadfile")
|
||||
public SuccessResultData<String> uploadFile(@RequestHeader("token") String token, @RequestParam("file") MultipartFile file) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(token, file, UploadTypeEnum.FILE, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传图片", notes = "上传图片接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
|
||||
@ApiImplicitParam(name = "image", value = "文件name", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadimage")
|
||||
public SuccessResultData<String> uploadImage(@RequestHeader("token") String token, @RequestParam("image") MultipartFile image) {
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(token, image, UploadTypeEnum.IMAGE, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传视频", notes = "上传视频接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
|
||||
@ApiImplicitParam(name = "video", value = "文件video", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadvideo")
|
||||
public SuccessResultData<String> uploadVideo(@RequestHeader("token") String token, @RequestParam("video") MultipartFile video) {
|
||||
if (fileProperties.getMediaMaxDuration() != null && fileProperties.getMediaMaxDuration().getWechat() != null) {
|
||||
fileService.checkVideoDurationAllow(video, fileProperties.getMediaMaxDuration().getWechat().getVideo());
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(token, video, UploadTypeEnum.VIDEO, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "上传音频", notes = "上传音频接口")
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
|
||||
@ApiImplicitParam(name = "audio", value = "文件audio", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("uploadaudio")
|
||||
public SuccessResultData<String> uploadAudio(@RequestHeader("token") String token, @RequestParam("audio") MultipartFile audio) {
|
||||
if (fileProperties.getMediaMaxDuration() != null && fileProperties.getMediaMaxDuration().getWechat() != null) {
|
||||
fileService.checkAudioDurationAllow(audio, fileProperties.getMediaMaxDuration().getWechat().getAudio());
|
||||
}
|
||||
Map<String, Object> params = requestParams();
|
||||
return uploadSingle(token, audio, UploadTypeEnum.AUDIO, params);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "文件列表", notes = "文件列表接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "ids", value = "id列表,逗号分隔", paramType = "query")
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("list")
|
||||
public List<FileDTO> list(@RequestParam("ids") String ids) {
|
||||
List<String> idList = Arrays.asList(ids.split(","));
|
||||
return fileService.list(idList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param uploadFile
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
private SuccessResultData<String> uploadSingle(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map<String, Object> params) {
|
||||
return fileService.uploadSingle(token, uploadFile, uploadTypeEnum, params);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
<!doctype html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<base th:href="${#request.getContextPath() + '/'} ">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta charset="UTF-8"/>
|
||||
<link rel="stylesheet" type="text/css" href="assets/js/vendor/bootstrap/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" type="text/css" href="assets/js/vendor/bootstrap-fileupload/css/fileinput.min.css"/>
|
||||
<style>
|
||||
.krajee-default.file-preview-frame .kv-file-content {height: 150px !important;}
|
||||
.krajee-default.file-preview-frame .file-thumbnail-footer {height: 70px !important;;}
|
||||
.krajee-default .file-footer-caption {margin-bottom:30px !important;}
|
||||
.krajee-default .file-thumb-progress .progress, .krajee-default .file-thumb-progress .progress-bar {height: 20px !important;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content" class="edit-content" style="padding: 5px;">
|
||||
<div class="tile color">
|
||||
<form id="form" method="post" class="form-horizontal" role="form" onsubmit="return doSubmitForm()">
|
||||
<input id="uploadFile" th:name="${updateInputName}" type="file" multiple data-theme="fas" data-preview-file-type="text">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" id="uploadUrl" th:value="'api/file/'+ ${uploadPath}"/>
|
||||
<input type="hidden" id="uploadType" th:value="${uploadType}"/>
|
||||
<input type="hidden" id="allowFiles" th:value="${allowFiles}"/>
|
||||
<input type="hidden" id="maxFileCount" th:value="${maxFileCount}"/>
|
||||
<script type="text/javascript" src="assets/js/jquery-3.5.1.min.js"></script>
|
||||
<script type="text/javascript" src="assets/js/vendor/bootstrap/js/bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="assets/js/vendor/bootstrap-fileupload/js/fileinput.js"></script>
|
||||
<script type="text/javascript" src="assets/js/vendor/bootstrap-fileupload/js/locales/zh.js"></script>
|
||||
<script type="text/javascript">
|
||||
var customType = top.restAjax.params(window.location.href).customType;
|
||||
var uploadFileArray = [];
|
||||
function closeBox() {
|
||||
top.dialog.closeBox();
|
||||
}
|
||||
function doSubmitForm() {
|
||||
return false;
|
||||
}
|
||||
|
||||
$(function () {
|
||||
if ('' == $('#uploadType').val() || '-1' == $('#uploadType').val()) {
|
||||
top.dialog.msg('文件上传类型错误');
|
||||
}
|
||||
var maxFileCount = top.dialog.maxFileCount == null ? $('#maxFileCount').val() : top.dialog.maxFileCount;
|
||||
$('#uploadFile').fileinput({
|
||||
language: 'zh', // 中文
|
||||
uploadUrl: $('#uploadUrl').val(), // 服务器地址
|
||||
allowedFileExtensions: customType ? customType.split(',') : $('#allowFiles').val().split(','), // 文件后缀
|
||||
showUpload: false, // 显示上传按钮
|
||||
showRemove: false, // 显示删除按钮
|
||||
showPreview: true, // 是否预览
|
||||
showCaption: false, // 是否标题
|
||||
showClose: false, // 右上角关闭
|
||||
showCancel: true, // 取消上传
|
||||
dropZoneEnabled: true, // 是否拖拽区域
|
||||
minFileCount: 0,
|
||||
maxFileCount: maxFileCount, // 表示允许同时上传的最大文件个数
|
||||
enctype: 'multipart/form-data',
|
||||
previewFileType: 'any' // 预览文件格式
|
||||
}).on('fileuploaded', function (event, data, previewId, index) {
|
||||
var id = data.response;
|
||||
uploadFileArray.push(id);
|
||||
top.dialog.dialogData.uploadFileArray = uploadFileArray;
|
||||
if(uploadFileArray.length >= maxFileCount) {
|
||||
$('.btn-file').hide();
|
||||
}
|
||||
}).on('filesuccessremove', function(event, previewId, index) {
|
||||
uploadFileArray.splice(index, 1);
|
||||
if(uploadFileArray.length < maxFileCount) {
|
||||
$('.btn-file').show();
|
||||
}
|
||||
top.dialog.dialogData.uploadFileArray = uploadFileArray;
|
||||
}).on('fileerror', function(event, data, msg) {
|
||||
top.dialog.msg(data.response.msg);
|
||||
});
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
174
module-file/src/main/resources/templates/file/image-upload.html
Normal file
174
module-file/src/main/resources/templates/file/image-upload.html
Normal file
@ -0,0 +1,174 @@
|
||||
<!doctype html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<base th:href="${#request.getContextPath() + '/'} ">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta charset="UTF-8"/>
|
||||
<link rel="stylesheet" type="text/css" href="assets/fonts/font-awesome/css/font-awesome.css"/>
|
||||
<link rel="stylesheet" type="text/css" href="assets/js/vendor/bootstrap/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" type="text/css" href="assets/js/vendor/cropper/cropper.min.css"/>
|
||||
<style>
|
||||
.upload-image {height: 100%; opacity: 0;}
|
||||
.upload-image-preview {width: 200px;height: 200px;overflow: hidden;margin: 0 20px;display: inline-block;}
|
||||
#imageBox {height: 418px;overflow: auto;background-color: #F1F1F1;}
|
||||
#imagePreviewBox .upload-image-preview {background-color: #F1F1F1;}
|
||||
</style>
|
||||
</head>
|
||||
<div>
|
||||
<div id="content" class="edit-content" style="padding: 5px; opacity: 0;">
|
||||
<div id="imageBox" class="col-xs-8">
|
||||
<img id="image" class="upload-image" src="assets/images/profile-photo.jpg" th:if="${fileId eq null or fileId eq ''}">
|
||||
<img id="image" class="upload-image" th:src="${'route/file/download/false/'+ fileId}" th:if="${fileId ne null and fileId ne ''}">
|
||||
</div>
|
||||
<div id="imagePreviewBox" class="col-xs-4">
|
||||
<div class="upload-image-preview"></div>
|
||||
</div>
|
||||
<div class="col-xs-4" style="text-align: center;">
|
||||
<button id="dragBtn" type="button" class="btn btn-danger fa fa-arrows" onclick="dragImage()" title="移动"></button>
|
||||
<button type="button" class="btn btn-danger fa fa-search-plus" onclick="zoomPlus()" title="放大图片"></button>
|
||||
<button type="button" class="btn btn-danger fa fa-search-minus" onclick="zoomMinus()" title="缩小图片"></button>
|
||||
<button type="button" class="btn btn-danger fa fa-refresh" onclick="reset()" title="重置图片"></button>
|
||||
</div>
|
||||
<div class="col-xs-4" style="margin-top: 5px; text-align: center;">
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-danger fa fa-undo" onclick="rateLeft()" type="button" title="向左旋转90°"> 向左旋转
|
||||
</button>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-danger fa fa-repeat" onclick="rateRight()" type="button" title="向右旋转90°"> 向右旋转
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-4" style="margin-top: 5px; text-align: center;">
|
||||
<div class="btn-group">
|
||||
<form id="uploadFileForm" action="#" style="display: none;">
|
||||
<input type="file" id="uploadImage" name="image" accept="image/jpeg,image/gif,image/png,image/jpg"
|
||||
onchange="doUploadFile()"/>
|
||||
</form>
|
||||
<button class="btn btn-primary btn-block fa fa-upload" type="button" onclick="openUploadImage()"> 上传图片
|
||||
</button>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-primary btn-block fa fa-save" type="button" onclick="doCrop()"> 裁剪上传</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="assets/js/jquery-3.5.1.min.js"></script>
|
||||
<script type="text/javascript" src="assets/js/vendor/bootstrap/js/bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="assets/js/vendor/cropper/cropper.min.js"></script>
|
||||
<script type="text/javascript" src="assets/js/common.js"></script>
|
||||
<script type="text/javascript">
|
||||
var fileArray = [];
|
||||
|
||||
function closeBox() {
|
||||
top.dialog.closeBox();
|
||||
}
|
||||
|
||||
function doSubmitForm() {
|
||||
return false;
|
||||
}
|
||||
|
||||
var cropper;
|
||||
|
||||
// 放大
|
||||
function zoomPlus() {
|
||||
cropper.zoom(0.1);
|
||||
}
|
||||
|
||||
// 缩小
|
||||
function zoomMinus() {
|
||||
cropper.zoom(-0.1);
|
||||
|
||||
}
|
||||
|
||||
// 逆时针90
|
||||
function rateLeft() {
|
||||
cropper.rotate(-90);
|
||||
}
|
||||
|
||||
// 顺时针90
|
||||
function rateRight() {
|
||||
cropper.rotate(90);
|
||||
}
|
||||
|
||||
// 重置
|
||||
function reset() {
|
||||
cropper.reset();
|
||||
}
|
||||
|
||||
// 图片移动
|
||||
var isDrag = false;
|
||||
|
||||
function dragImage() {
|
||||
if (!isDrag) {
|
||||
cropper.setDragMode('move');
|
||||
isDrag = true;
|
||||
$('#dragBtn').addClass('btn-default');
|
||||
$('#dragBtn').removeClass('btn-danger');
|
||||
} else {
|
||||
cropper.setDragMode('crop');
|
||||
isDrag = false;
|
||||
$('#dragBtn').addClass('btn-danger');
|
||||
$('#dragBtn').removeClass('btn-default');
|
||||
}
|
||||
}
|
||||
|
||||
// 打开上传图片
|
||||
function openUploadImage() {
|
||||
$('#uploadImage').click();
|
||||
}
|
||||
|
||||
// 上传文件
|
||||
function doUploadFile() {
|
||||
var loadLayerIndex;
|
||||
var formData = new FormData($('#uploadFileForm')[0]);
|
||||
top.restAjax.postFile('api/file/uploadimage', formData, {}, function (code, data) {
|
||||
top.dialog.msg('上传成功');
|
||||
cropper.replace('route/file/download/false/' + data.data, false);
|
||||
top.dialog.dialogData.uploadImage = data.data;
|
||||
}, function(code, data) {
|
||||
top.dialog.msg(data.msg);
|
||||
}, function() {
|
||||
loadLayerIndex = top.dialog.msg(top.dataMessage.uploading, {icon: 16, time: 0, shade: 0.3});
|
||||
}, function() {
|
||||
top.dialog.close(loadLayerIndex);
|
||||
});
|
||||
}
|
||||
|
||||
// 裁剪
|
||||
function doCrop() {
|
||||
cropper.getCroppedCanvas().toBlob(function (cropBlob) {
|
||||
var formData = new FormData();
|
||||
formData.append("image", cropBlob);
|
||||
var loadLayerIndex;
|
||||
top.restAjax.postFile('api/file/uploadimage', formData, {}, function (code, data) {
|
||||
top.dialog.msg('裁剪成功');
|
||||
cropper.replace('route/file/download/false/' + data.data, false);
|
||||
top.dialog.dialogData.uploadImage = data.data;
|
||||
}, function(code, data) {
|
||||
top.dialog.msg(data.msg);
|
||||
}, function() {
|
||||
loadLayerIndex = top.dialog.msg(top.dataMessage.uploading, {icon: 16, time: 0, shade: 0.3});
|
||||
}, function() {
|
||||
top.dialog.close(loadLayerIndex);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$(function () {
|
||||
top.dialog.dialogData.uploadImage = '';
|
||||
var image = document.getElementById('image');
|
||||
cropper = new Cropper(image, {
|
||||
aspectRatio: 1 / 1,
|
||||
viewMode: 1,
|
||||
preview: '.upload-image-preview',
|
||||
minContainerHeight: 430,
|
||||
maxContainerHeight: 430,
|
||||
crop(event) {},
|
||||
});
|
||||
$('#content').fadeTo(1000, 1);
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
334
module-file/src/main/resources/templates/file/list-info.html
Normal file
334
module-file/src/main/resources/templates/file/list-info.html
Normal file
@ -0,0 +1,334 @@
|
||||
<!doctype html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<base th:href="${#request.getContextPath() + '/'} ">
|
||||
<meta charset="utf-8">
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
|
||||
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
|
||||
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
|
||||
<link rel="stylesheet" type="text/css" href="assets/js/vendor/viewer/viewer.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-fluid layui-anim layui-anim-fadein">
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-md12">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body" id="cardBody">
|
||||
<div class="test-table-reload-btn" style="margin-bottom: 10px;">
|
||||
<div class="layui-inline">
|
||||
<input type="text" id="keywords" class="layui-input search-item" placeholder="输入关键字">
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<input type="text" id="startTime" class="layui-input search-item" placeholder="开始时间" readonly>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<input type="text" id="endTime" class="layui-input search-item" placeholder="结束时间" readonly>
|
||||
</div>
|
||||
<button type="button" id="search" class="layui-btn layui-btn-sm">
|
||||
<i class="fa fa-lg fa-search"></i> 搜索
|
||||
</button>
|
||||
</div>
|
||||
<table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
|
||||
<!-- 表头按钮组 -->
|
||||
<script type="text/html" id="headerToolBar">
|
||||
<div class="layui-btn-group">
|
||||
<button type="button" class="layui-btn layui-btn-danger layui-btn-sm" lay-event="removeEvent">
|
||||
<i class="fa fa-lg fa-trash"></i> 删除
|
||||
</button>
|
||||
</div>
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="videoBoxBackGround" style="position: fixed;z-index: 1000;top: 0;left: 0;width: 100%;height: 100%;background-color: rgba(0,0,0,0.6); display: none;">
|
||||
<div role="button" class="viewer-button viewer-close video-close-btn"></div>
|
||||
<div id="videoBox" style="width: 600px; height: 400px; position: absolute; left: 50%; top: 50%; margin-left: -300px; margin-top: -200px;">
|
||||
<div id="video" style="width: 100%; height: 100%"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="assets/js/vendor/ckplayer/ckplayer/ckplayer.js"></script>
|
||||
<script src="assets/js/vendor/viewer/viewer.min.js"></script>
|
||||
<script src="assets/layuiadmin/layui/layui.js"></script>
|
||||
<script type="text/javascript">
|
||||
layui.config({
|
||||
base: 'assets/layuiadmin/'
|
||||
}).extend({
|
||||
index: 'lib/index'
|
||||
}).use(['index', 'table', 'laydate', 'common'], function() {
|
||||
var $ = layui.$;
|
||||
var $win = $(window);
|
||||
var table = layui.table;
|
||||
var admin = layui.admin;
|
||||
var laydate = layui.laydate;
|
||||
var common = layui.common;
|
||||
var resizeTimeout = null;
|
||||
var tableUrl = 'api/file/listpageinfo';
|
||||
var viewer = new Viewer(document.getElementById('cardBody'), {navbar: true});;
|
||||
var viewerTimeout;
|
||||
var imageTypeArray = ['png','jpg','jpeg','gif','blob'];
|
||||
var imageIdArray = [];
|
||||
var ckPlayerFileId;
|
||||
var ckPlayer = new ckplayer({
|
||||
container: '#video',
|
||||
variable: 'player',
|
||||
flashplayer: false,
|
||||
video: {
|
||||
file: '',
|
||||
type: 'video/mp4'
|
||||
},
|
||||
});
|
||||
// 是图片类型
|
||||
function isImageType(type) {
|
||||
for(var i = 0, item; item = imageTypeArray[i++];) {
|
||||
if(item === type) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 初始化表格
|
||||
function initTable() {
|
||||
table.render({
|
||||
elem: '#dataTable',
|
||||
id: 'dataTable',
|
||||
url: top.restAjax.path(tableUrl, []),
|
||||
width: admin.screen() > 1 ? '100%' : '',
|
||||
height: $win.height() - 90,
|
||||
limit: 20,
|
||||
limits: [20, 40, 60, 80, 100, 200],
|
||||
toolbar: '#headerToolBar',
|
||||
request: {
|
||||
pageName: 'page',
|
||||
limitName: 'rows'
|
||||
},
|
||||
cols: [
|
||||
[
|
||||
{type:'checkbox', fixed: 'left'},
|
||||
{field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '<span>{{d.LAY_INDEX}}</span>'},
|
||||
{field: 'fileId', width: 300, title: 'ID', align:'center',
|
||||
templet: function(row) {
|
||||
var rowData = row[this.field];
|
||||
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
|
||||
return '-';
|
||||
}
|
||||
return rowData;
|
||||
}
|
||||
},
|
||||
{field: 'fileName', width: 400, title: '文件名称', align:'center',
|
||||
templet: function(row) {
|
||||
var rowData = row[this.field];
|
||||
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
|
||||
return '-';
|
||||
}
|
||||
var icon = '<i class="fa fa-download"></i>';
|
||||
var result = '';
|
||||
if(isImageType(row.fileType)) {
|
||||
result += '<img src="route/file/downloadfile/true/'+ row.fileId +'" style="display: none;"/>';
|
||||
imageIdArray.push(row.fileId);
|
||||
icon = '<i class="fa fa-image"></i>';
|
||||
} else if(row.fileType === 'mp4') {
|
||||
icon = '<i class="fa fa-video-camera"></i>';
|
||||
}
|
||||
result += '<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="searchFileEvent"> '+ icon +' '+ rowData +'</button>'
|
||||
if(viewerTimeout) {
|
||||
clearTimeout(viewerTimeout);
|
||||
}
|
||||
viewerTimeout = setTimeout(function() {
|
||||
viewer.update();
|
||||
}, 1000);
|
||||
return result;
|
||||
}
|
||||
},
|
||||
{field: 'fileUrl', width: 500, title: '相对位置', align:'center',
|
||||
templet: function(row) {
|
||||
var rowData = row[this.field];
|
||||
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
|
||||
return '-';
|
||||
}
|
||||
return rowData;
|
||||
}
|
||||
},
|
||||
{field: 'fileType', width: 100, title: '文件类型', align:'center',
|
||||
templet: function(row) {
|
||||
var rowData = row[this.field];
|
||||
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
|
||||
return '-';
|
||||
}
|
||||
return rowData;
|
||||
}
|
||||
},
|
||||
{field: 'fileSize', width: 120, title: '文件大小', align:'center',
|
||||
templet: function(row) {
|
||||
var rowData = row[this.field];
|
||||
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
|
||||
return '-';
|
||||
}
|
||||
return rowData;
|
||||
}
|
||||
},
|
||||
{field: 'fileSummary', width: 350, title: '文件描述', align:'center',
|
||||
templet: function(row) {
|
||||
var rowData = row[this.field];
|
||||
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
|
||||
return '-';
|
||||
}
|
||||
return rowData;
|
||||
}
|
||||
},
|
||||
{field: 'isSourceFile', width: 100, title: '保存类型', align:'center',
|
||||
templet: function(row) {
|
||||
if(!row.fileSummary) {
|
||||
return '无';
|
||||
}
|
||||
if(row.fileSummary.indexOf('MD5:') == 0) {
|
||||
return '源文件';
|
||||
}
|
||||
if(row.fileSummary.indexOf('REF:') == 0) {
|
||||
return '引用';
|
||||
}
|
||||
return '错误';
|
||||
}
|
||||
},
|
||||
]
|
||||
],
|
||||
page: true,
|
||||
parseData: function(data) {
|
||||
imageIdArray.splice(0, imageIdArray.length);
|
||||
return {
|
||||
'code': 0,
|
||||
'msg': '',
|
||||
'count': data.total,
|
||||
'data': data.rows
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
// 重载表格
|
||||
function reloadTable(currentPage) {
|
||||
table.reload('dataTable', {
|
||||
url: top.restAjax.path(tableUrl, []),
|
||||
where: {
|
||||
keywords: $('#keywords').val(),
|
||||
startTime: $('#startTime').val(),
|
||||
endTime: $('#endTime').val()
|
||||
},
|
||||
page: {
|
||||
curr: currentPage
|
||||
},
|
||||
height: $win.height() - 90,
|
||||
});
|
||||
}
|
||||
// 初始化日期
|
||||
function initDate() {
|
||||
// 日期选择
|
||||
laydate.render({
|
||||
elem: '#startTime',
|
||||
format: 'yyyy-MM-dd'
|
||||
});
|
||||
laydate.render({
|
||||
elem: '#endTime',
|
||||
format: 'yyyy-MM-dd'
|
||||
});
|
||||
}
|
||||
// 删除
|
||||
function removeFile(isRemoveSource, ids) {
|
||||
var layIndex;
|
||||
top.restAjax.delete(top.restAjax.path('api/file/remove/{isRemoveSource}/{ids}', [isRemoveSource, ids]), {}, null, function (code, data) {
|
||||
top.dialog.msg(top.dataMessage.deleteSuccess, {time: 1000});
|
||||
reloadTable();
|
||||
}, function (code, data) {
|
||||
top.dialog.msg(data.msg);
|
||||
}, function () {
|
||||
layIndex = top.dialog.msg(top.dataMessage.deleting, {icon: 16, time: 0, shade: 0.3});
|
||||
}, function () {
|
||||
top.dialog.close(layIndex);
|
||||
});
|
||||
}
|
||||
function removeData(ids) {
|
||||
top.dialog.msg(top.dataMessage.delete, {
|
||||
time: 0,
|
||||
btn: [top.dataMessage.button.yes, '同时删除文件(不可逆)', top.dataMessage.button.no],
|
||||
shade: 0.3,
|
||||
btn1: function (index) {
|
||||
top.dialog.close(index);
|
||||
removeFile(0, ids);
|
||||
},
|
||||
btn2: function(index) {
|
||||
top.dialog.close(index);
|
||||
removeFile(1, ids);
|
||||
},
|
||||
btn3: function(index) {
|
||||
top.dialog.close(index);
|
||||
}
|
||||
});
|
||||
}
|
||||
initTable();
|
||||
initDate();
|
||||
// 事件 - 页面变化
|
||||
$win.on('resize', function() {
|
||||
clearTimeout(resizeTimeout);
|
||||
resizeTimeout = setTimeout(function() {
|
||||
reloadTable();
|
||||
}, 500);
|
||||
});
|
||||
// 事件 - 搜索
|
||||
$(document).on('click', '#search', function() {
|
||||
reloadTable(1);
|
||||
});
|
||||
// 事件 - 增删改
|
||||
table.on('toolbar(dataTable)', function(obj) {
|
||||
var layEvent = obj.event;
|
||||
var checkStatus = table.checkStatus('dataTable');
|
||||
var checkDatas = checkStatus.data;
|
||||
if(layEvent === 'removeEvent') {
|
||||
if(checkDatas.length === 0) {
|
||||
top.dialog.msg(top.dataMessage.table.selectDelete);
|
||||
} else {
|
||||
var ids = '';
|
||||
for(var i = 0, item; item = checkDatas[i++];) {
|
||||
if(i > 1) {
|
||||
ids += '_';
|
||||
}
|
||||
ids += item['fileId'];
|
||||
}
|
||||
removeData(ids);
|
||||
}
|
||||
}
|
||||
});
|
||||
table.on('tool(dataTable)', function(obj) {
|
||||
var data = obj.data;
|
||||
var event = obj.event;
|
||||
if(event === 'searchFileEvent') {
|
||||
if(isImageType(data.fileType)) {
|
||||
for(var i = 0; i < imageIdArray.length; i++) {
|
||||
if(data.fileId === imageIdArray[i]) {
|
||||
viewer.view(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if(data.fileType === 'mp4') {
|
||||
$('#videoBoxBackGround').show();
|
||||
if(ckPlayerFileId == data.fileId) {
|
||||
return;
|
||||
}
|
||||
ckPlayer.newVideo({
|
||||
video: 'route/file/download/true/'+ data.fileId
|
||||
});
|
||||
ckPlayerFileId = data.fileId;
|
||||
}
|
||||
}
|
||||
});
|
||||
$('.video-close-btn').on('click', function() {
|
||||
ckPlayer.videoPause();
|
||||
$('#videoBoxBackGround').hide();
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
24
module-file/src/main/resources/templates/file/show.html
Normal file
24
module-file/src/main/resources/templates/file/show.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!doctype html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<base th:href="${#request.getContextPath() + '/'} ">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta charset="UTF-8"/>
|
||||
<link rel="stylesheet" type="text/css" href="assets/js/vendor/bootstrap/css/bootstrap.min.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="assets/css/minimal.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="assets/css/system.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content" class="edit-content" style="padding: 5px;">
|
||||
<div class="tile color">
|
||||
<img th:if="${type == 'image'}" th:src="@{'route/file/downloadfile/false/'+ ${fileId}}" alt="加载失败" style="width: 100%;"/>
|
||||
<video th:if="${type == 'video'}" controls style="width:100%;">
|
||||
<source th:src="@{'route/file/downloadfile/false/'+ ${fileId}}" type="video/mp4">
|
||||
您的浏览器不支持 video 标签。
|
||||
</video>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="assets/js/jquery-3.5.1.min.js"></script>
|
||||
<script type="text/javascript" src="assets/js/vendor/bootstrap/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
</html>
|
94
module-file/src/main/resources/ueditorconfig.json
Normal file
94
module-file/src/main/resources/ueditorconfig.json
Normal file
@ -0,0 +1,94 @@
|
||||
/* 前后端通信相关的配置,注释只允许使用多行方式 */
|
||||
{
|
||||
/* 上传图片配置项 */
|
||||
"imageActionName": "uploadimage", /* 执行上传图片的action名称 */
|
||||
"imageFieldName": "file", /* 提交的图片表单名称 */
|
||||
"imageMaxSize": 102400000, /* 上传大小限制,单位B */
|
||||
"imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上传图片格式显示 */
|
||||
"imageCompressEnable": true, /* 是否压缩图片,默认是true */
|
||||
"imageCompressBorder": 1600, /* 图片压缩最长边限制 */
|
||||
"imageInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
"imageUrlPrefix": "", /* 图片访问路径前缀 */
|
||||
"imagePathFormat": "/files/images/{yyyy}{mm}{dd}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
/* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */
|
||||
/* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */
|
||||
/* {time} 会替换成时间戳 */
|
||||
/* {yyyy} 会替换成四位年份 */
|
||||
/* {yy} 会替换成两位年份 */
|
||||
/* {mm} 会替换成两位月份 */
|
||||
/* {dd} 会替换成两位日期 */
|
||||
/* {hh} 会替换成两位小时 */
|
||||
/* {ii} 会替换成两位分钟 */
|
||||
/* {ss} 会替换成两位秒 */
|
||||
/* 非法字符 \ : * ? " < > | */
|
||||
/* 具请体看线上文档: fex.baidu.com/ueditor/#use-format_upload_filename */
|
||||
|
||||
/* 涂鸦图片上传配置项 */
|
||||
"scrawlActionName": "uploadimage", /* 执行上传涂鸦的action名称 */
|
||||
"scrawlFieldName": "file", /* 提交的图片表单名称 */
|
||||
"scrawlPathFormat": "/files/images/{yyyy}{mm}{dd}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"scrawlMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"scrawlUrlPrefix": "", /* 图片访问路径前缀 */
|
||||
"scrawlInsertAlign": "none",
|
||||
|
||||
/* 截图工具上传 */
|
||||
"snapscreenActionName": "uploadimage", /* 执行上传截图的action名称 */
|
||||
"snapscreenPathFormat": "/files/images/{yyyy}{mm}{dd}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"snapscreenUrlPrefix": "", /* 图片访问路径前缀 */
|
||||
"snapscreenInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
|
||||
/* 抓取远程图片配置 */
|
||||
"catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"],
|
||||
"catcherActionName": "uploadimage", /* 执行抓取远程图片的action名称 */
|
||||
"catcherFieldName": "file", /* 提交的图片列表表单名称 */
|
||||
"catcherPathFormat": "/files/images/{yyyy}{mm}{dd}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"catcherUrlPrefix": "", /* 图片访问路径前缀 */
|
||||
"catcherMaxSize": 2048000, /* 上传大小限制,单位B */
|
||||
"catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 抓取图片格式显示 */
|
||||
|
||||
/* 上传视频配置 */
|
||||
"videoActionName": "uploadvideo", /* 执行上传视频的action名称 */
|
||||
"videoFieldName": "file", /* 提交的视频表单名称 */
|
||||
"videoPathFormat": "/files/videos/{yyyy}{mm}{dd}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"videoUrlPrefix": "", /* 视频访问路径前缀 */
|
||||
"videoMaxSize": 10240000000, /* 上传大小限制,单位B,默认100MB */
|
||||
"videoAllowFiles": [
|
||||
".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
|
||||
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"], /* 上传视频格式显示 */
|
||||
|
||||
/* 上传文件配置 */
|
||||
"fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */
|
||||
"fileFieldName": "file", /* 提交的文件表单名称 */
|
||||
"filePathFormat": "/files/files/{yyyy}{mm}{dd}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
|
||||
"fileUrlPrefix": "", /* 文件访问路径前缀 */
|
||||
"fileMaxSize": 51200000, /* 上传大小限制,单位B,默认50MB */
|
||||
"fileAllowFiles": [
|
||||
".png", ".jpg", ".jpeg", ".gif", ".bmp",
|
||||
".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
|
||||
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
|
||||
".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso", ".apk",
|
||||
".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
|
||||
], /* 上传文件格式显示 */
|
||||
|
||||
/* 列出指定目录下的图片 */
|
||||
"imageManagerActionName": "listimage", /* 执行图片管理的action名称 */
|
||||
"imageManagerListPath": "/files/images/", /* 指定要列出图片的目录 */
|
||||
"imageManagerListSize": 20, /* 每次列出文件数量 */
|
||||
"imageManagerUrlPrefix": "", /* 图片访问路径前缀 */
|
||||
"imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */
|
||||
"imageManagerAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 列出的文件类型 */
|
||||
|
||||
/* 列出指定目录下的文件 */
|
||||
"fileManagerActionName": "listfile", /* 执行文件管理的action名称 */
|
||||
"fileManagerListPath": "/files/files/", /* 指定要列出文件的目录 */
|
||||
"fileManagerUrlPrefix": "", /* 文件访问路径前缀 */
|
||||
"fileManagerListSize": 20, /* 每次列出文件数量 */
|
||||
"fileManagerAllowFiles": [
|
||||
".png", ".jpg", ".jpeg", ".gif", ".bmp",
|
||||
".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
|
||||
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
|
||||
".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
|
||||
".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
|
||||
] /* 列出的文件类型 */
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user