diff --git a/ZR.Admin.WebApi/Controllers/CommonController.cs b/ZR.Admin.WebApi/Controllers/CommonController.cs index 1cf5167..073cb24 100644 --- a/ZR.Admin.WebApi/Controllers/CommonController.cs +++ b/ZR.Admin.WebApi/Controllers/CommonController.cs @@ -1,5 +1,6 @@ using Infrastructure; using Infrastructure.Attribute; +using Infrastructure.Extensions; using Infrastructure.Model; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -96,16 +97,19 @@ namespace ZR.Admin.WebApi.Controllers /// /// /// 存储目录 + /// 文件名 /// 上传类型 1、发送邮件 /// [HttpPost()] [Verify] [ActionPermissionFilter(Permission = "common")] - public IActionResult UploadFile([FromForm(Name = "file")] IFormFile formFile, string fileDir = "uploads", int uploadType = 0) + public IActionResult UploadFile([FromForm(Name = "file")] IFormFile formFile, string fileName = "", string fileDir = "uploads", int uploadType = 0) { if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传文件不能为空"); string fileExt = Path.GetExtension(formFile.FileName); - string fileName = FileUtil.HashFileName(Guid.NewGuid().ToString()).ToLower() + fileExt; + string hashFileName = FileUtil.HashFileName(Guid.NewGuid().ToString()).ToLower(); + fileName = (fileName.IsEmpty() ? hashFileName : fileName) + fileExt; + fileDir = fileDir.IsEmpty() ? "uploads" : fileDir; string filePath = FileUtil.GetdirPath(fileDir); string finalFilePath = Path.Combine(WebHostEnvironment.WebRootPath, filePath, fileName); finalFilePath = finalFilePath.Replace("\\", "/").Replace("//", "/"); diff --git a/ZR.Admin.WebApi/Controllers/System/SysFileController.cs b/ZR.Admin.WebApi/Controllers/System/SysFileController.cs index 05f2537..18597c6 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysFileController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysFileController.cs @@ -1,11 +1,8 @@ using Microsoft.AspNetCore.Mvc; using SqlSugar; -using Infrastructure; using Infrastructure.Attribute; using Infrastructure.Enums; using Infrastructure.Model; -using Mapster; -using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Common; using ZR.Model.System; @@ -66,66 +63,66 @@ namespace ZR.Admin.WebApi.Controllers return SUCCESS(response); } - /// - /// 添加文件存储 - /// - /// - [HttpPost] - [ActionPermissionFilter(Permission = "tool:file:add")] - [Log(Title = "文件存储", BusinessType = BusinessType.INSERT)] - public IActionResult AddSysFile([FromBody] SysFileDto parm) - { - if (parm == null) - { - throw new CustomException("请求参数错误"); - } - //从 Dto 映射到 实体 - var model = parm.Adapt().ToCreate(HttpContext); + ///// + ///// 添加文件存储 + ///// + ///// + //[HttpPost] + //[ActionPermissionFilter(Permission = "tool:file:add")] + //[Log(Title = "文件存储", BusinessType = BusinessType.INSERT)] + //public IActionResult AddSysFile([FromBody] SysFileDto parm) + //{ + // if (parm == null) + // { + // throw new CustomException("请求参数错误"); + // } + // //从 Dto 映射到 实体 + // var model = parm.Adapt().ToCreate(HttpContext); - var response = _SysFileService.Insert(model, it => new - { - it.FileName, - it.FileUrl, - it.StorePath, - it.FileSize, - it.FileExt, - it.Create_by, - it.Create_time, - it.StoreType, - it.AccessUrl, - }); - return ToResponse(response); - } + // var response = _SysFileService.Insert(model, it => new + // { + // it.FileName, + // it.FileUrl, + // it.StorePath, + // it.FileSize, + // it.FileExt, + // it.Create_by, + // it.Create_time, + // it.StoreType, + // it.AccessUrl, + // }); + // return ToResponse(response); + //} - /// - /// 更新文件存储 - /// - /// - [HttpPut] - [ActionPermissionFilter(Permission = "tool:file:update")] - [Log(Title = "文件存储", BusinessType = BusinessType.UPDATE)] - public IActionResult UpdateSysFile([FromBody] SysFileDto parm) - { - if (parm == null) - { - throw new CustomException("请求实体不能为空"); - } - //从 Dto 映射到 实体 - var model = parm.Adapt().ToUpdate(HttpContext); + ///// + ///// 更新文件存储 + ///// + ///// + //[HttpPut] + //[ActionPermissionFilter(Permission = "tool:file:update")] + //[Log(Title = "文件存储", BusinessType = BusinessType.UPDATE)] + //public IActionResult UpdateSysFile([FromBody] SysFileDto parm) + //{ + // if (parm == null) + // { + // throw new CustomException("请求实体不能为空"); + // } + // //从 Dto 映射到 实体 + // var model = parm.Adapt().ToUpdate(HttpContext); - var response = _SysFileService.Update(w => w.Id == model.Id, it => new SysFile() - { - //Update 字段映射 - FileUrl = model.FileUrl, - StorePath = model.StorePath, - FileSize = model.FileSize, - FileExt = model.FileExt, - StoreType = model.StoreType, - AccessUrl = model.AccessUrl, - }); + // var response = _SysFileService.Update(w => w.Id == model.Id, it => new SysFile() + // { + // //Update 字段映射 + // FileUrl = model.FileUrl, + // StorePath = model.StorePath, + // FileSize = model.FileSize, + // FileExt = model.FileExt, + // StoreType = model.StoreType, + // AccessUrl = model.AccessUrl, + // }); - return ToResponse(response); - } + // return ToResponse(response); + //} /// /// 删除文件存储 diff --git a/ZR.Vue/src/components/FileUpload/index.vue b/ZR.Vue/src/components/FileUpload/index.vue index fecc8ee..097d485 100644 --- a/ZR.Vue/src/components/FileUpload/index.vue +++ b/ZR.Vue/src/components/FileUpload/index.vue @@ -8,8 +8,8 @@
请上传 - - + 大小不超过 {{ fileSize }}MB + 格式为 {{ fileType.join("/") }} 的文件
diff --git a/ZR.Vue/src/views/tool/file/index.vue b/ZR.Vue/src/views/tool/file/index.vue index 1086ce5..bc21521 100644 --- a/ZR.Vue/src/views/tool/file/index.vue +++ b/ZR.Vue/src/views/tool/file/index.vue @@ -20,14 +20,11 @@ - 上传文件 + 上传文件 - - 删除 + + 删除 @@ -58,12 +55,12 @@ - + @@ -73,11 +70,11 @@ - + @@ -99,14 +96,14 @@ - + -