mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	Merge remote-tracking branch 'origin/fix/master' into feature/1.8.0-uniapp
This commit is contained in:
		| @@ -3,12 +3,13 @@ package cn.iocoder.yudao.module.infra.controller.admin.file; | |||||||
| import cn.hutool.core.io.FileUtil; | import cn.hutool.core.io.FileUtil; | ||||||
| import cn.hutool.core.io.IoUtil; | import cn.hutool.core.io.IoUtil; | ||||||
| import cn.hutool.core.util.IdUtil; | import cn.hutool.core.util.IdUtil; | ||||||
|  | import cn.hutool.core.util.StrUtil; | ||||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
| import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO; | import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileRespVO; | import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FileRespVO; | ||||||
| import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.SimpleUploadRespVO; | import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.UploadRespVO; | ||||||
| import cn.iocoder.yudao.module.infra.convert.file.FileConvert; | import cn.iocoder.yudao.module.infra.convert.file.FileConvert; | ||||||
| import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; | import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO; | ||||||
| import cn.iocoder.yudao.module.infra.service.file.FileService; | import cn.iocoder.yudao.module.infra.service.file.FileService; | ||||||
| @@ -45,24 +46,20 @@ public class FileController { | |||||||
|             @ApiImplicitParam(name = "file", value = "文件附件", required = true, dataTypeClass = MultipartFile.class), |             @ApiImplicitParam(name = "file", value = "文件附件", required = true, dataTypeClass = MultipartFile.class), | ||||||
|             @ApiImplicitParam(name = "path", value = "文件路径", example = "yudaoyuanma.png", dataTypeClass = String.class) |             @ApiImplicitParam(name = "path", value = "文件路径", example = "yudaoyuanma.png", dataTypeClass = String.class) | ||||||
|     }) |     }) | ||||||
|     public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file, |     public CommonResult<UploadRespVO> uploadFile(@RequestParam("file") MultipartFile file, | ||||||
|                                            @RequestParam("path") String path) throws Exception { |                                                  @RequestParam(value = "path", required = false) String path) | ||||||
|         return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream()))); |             throws Exception { | ||||||
|  |         // 如果路径没传, 系统生成随机路径 | ||||||
|  |         if (StrUtil.isBlank(path)) { | ||||||
|  |             // TODO 生成带日期的路径, 目前 #getFileContent 不支持 | ||||||
|  |             path = IdUtil.fastSimpleUUID() + StrUtil.DOT + FileUtil.extName(file.getOriginalFilename()); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|     @PostMapping("/simple-upload") |  | ||||||
|     @ApiOperation("简单上传文件") |  | ||||||
|     @ApiImplicitParams({ |  | ||||||
|             @ApiImplicitParam(name = "file", value = "文件附件", required = true, dataTypeClass = MultipartFile.class), |  | ||||||
|     }) |  | ||||||
|     public CommonResult<SimpleUploadRespVO> uploadFile(@RequestParam("file") MultipartFile file) throws Exception { |  | ||||||
|         SimpleUploadRespVO simpleUploadRespVO = new SimpleUploadRespVO(); |  | ||||||
|         simpleUploadRespVO.setFileName(file.getOriginalFilename()); |  | ||||||
|         // TODO 日期路径, 随机文件名 |  | ||||||
|         String path = IdUtil.fastSimpleUUID() + "." + FileUtil.extName(file.getOriginalFilename()); |  | ||||||
|         String fileUrl = fileService.createFile(path, IoUtil.readBytes(file.getInputStream())); |         String fileUrl = fileService.createFile(path, IoUtil.readBytes(file.getInputStream())); | ||||||
|         simpleUploadRespVO.setFileUrl(fileUrl); |         // 返回结果 | ||||||
|         return success(simpleUploadRespVO); |         UploadRespVO uploadRespVO = new UploadRespVO(); | ||||||
|  |         uploadRespVO.setFileName(file.getOriginalFilename()); | ||||||
|  |         uploadRespVO.setFileUrl(fileUrl); | ||||||
|  |         return success(uploadRespVO); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @DeleteMapping("/delete") |     @DeleteMapping("/delete") | ||||||
|   | |||||||
| @@ -5,8 +5,8 @@ import io.swagger.annotations.ApiModelProperty; | |||||||
| import lombok.Data; | import lombok.Data; | ||||||
| 
 | 
 | ||||||
| @Data | @Data | ||||||
| @ApiModel(value = "管理后台 - 简单上传文件 VO", description = "简单上传文件, 不需要 path") | @ApiModel(value = "管理后台 - 上传文件 VO") | ||||||
| public class SimpleUploadRespVO { | public class UploadRespVO { | ||||||
| 
 | 
 | ||||||
|     @ApiModelProperty(value = "文件名", required = true, example = "yudao.jpg") |     @ApiModelProperty(value = "文件名", required = true, example = "yudao.jpg") | ||||||
|     private String fileName; |     private String fileName; | ||||||
| @@ -76,8 +76,9 @@ export default { | |||||||
|       dialogImageUrl: "", |       dialogImageUrl: "", | ||||||
|       dialogVisible: false, |       dialogVisible: false, | ||||||
|       hideUpload: false, |       hideUpload: false, | ||||||
|  |       // todo /infra/file/upload 返回的都是带 host 的可访问地址, baseUrl 有点没必要 | ||||||
|       baseUrl: process.env.VUE_APP_BASE_API, |       baseUrl: process.env.VUE_APP_BASE_API, | ||||||
|       uploadImgUrl: process.env.VUE_APP_BASE_API + "/admin-api/infra/file/simple-upload", // 上传的图片服务器地址 |       uploadImgUrl: process.env.VUE_APP_BASE_API + "/admin-api/infra/file/upload", // 上传的图片服务器地址 | ||||||
|       headers: { |       headers: { | ||||||
|         Authorization: "Bearer " + getToken(), |         Authorization: "Bearer " + getToken(), | ||||||
|       }, |       }, | ||||||
| @@ -187,7 +188,8 @@ export default { | |||||||
|       let strs = ""; |       let strs = ""; | ||||||
|       separator = separator || ","; |       separator = separator || ","; | ||||||
|       for (let i in list) { |       for (let i in list) { | ||||||
|         strs += list[i].url.replace(this.baseUrl, "") + separator; |         // 由于 infra-file 返回带有 host , 不需要替换 baseUrl // .replace(this.baseUrl, "") | ||||||
|  |         strs += list[i].url + separator; | ||||||
|       } |       } | ||||||
|       return strs != '' ? strs.substr(0, strs.length - 1) : ''; |       return strs != '' ? strs.substr(0, strs.length - 1) : ''; | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 JeromeSoar
					JeromeSoar