diff --git a/ZR.Admin.WebApi/Controllers/CommonController.cs b/ZR.Admin.WebApi/Controllers/CommonController.cs index 379f7ff..678b629 100644 --- a/ZR.Admin.WebApi/Controllers/CommonController.cs +++ b/ZR.Admin.WebApi/Controllers/CommonController.cs @@ -175,7 +175,7 @@ namespace ZR.Admin.WebApi.Controllers return ToResponse(ResultCode.CUSTOM_ERROR, "上传文件过大,不能超过 " + (MaxContentLength / 1024).ToString() + " MB"); } - (bool, string, string) result = SysFileService.SaveFile(fileDir, formFile); + (bool, string, string) result = SysFileService.SaveFile(fileDir, formFile, fileName); long fileId = SysFileService.InsertFile(new SysFile() { AccessUrl = result.Item2, diff --git a/ZR.Admin.WebApi/Controllers/System/SysFileController.cs b/ZR.Admin.WebApi/Controllers/System/SysFileController.cs index 18597c6..2044973 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysFileController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysFileController.cs @@ -43,6 +43,7 @@ namespace ZR.Admin.WebApi.Controllers predicate = predicate.AndIF(parm.BeginCreate_time != null, it => it.Create_time >= parm.BeginCreate_time); predicate = predicate.AndIF(parm.EndCreate_time != null, it => it.Create_time <= parm.EndCreate_time); predicate = predicate.AndIF(parm.StoreType != null, m => m.StoreType == parm.StoreType); + predicate = predicate.AndIF(parm.FileId != null, m => m.Id == parm.FileId); //搜索条件查询语法参考Sqlsugar var response = _SysFileService.GetPages(predicate.ToExpression(), parm); @@ -59,7 +60,7 @@ namespace ZR.Admin.WebApi.Controllers public IActionResult GetSysFile(int Id) { var response = _SysFileService.GetFirst(x => x.Id == Id); - + return SUCCESS(response); } diff --git a/ZR.Model/System/Dto/SysFileQueryDto.cs b/ZR.Model/System/Dto/SysFileQueryDto.cs index 4cfa45d..c86b135 100644 --- a/ZR.Model/System/Dto/SysFileQueryDto.cs +++ b/ZR.Model/System/Dto/SysFileQueryDto.cs @@ -25,5 +25,6 @@ namespace ZR.Model.System.Dto public DateTime? BeginCreate_time { get; set; } public DateTime? EndCreate_time { get; set; } public int? StoreType { get; set; } + public int? FileId { get; set; } } } diff --git a/ZR.Service/System/IService/ISysFileService.cs b/ZR.Service/System/IService/ISysFileService.cs index e3971a3..6b8c319 100644 --- a/ZR.Service/System/IService/ISysFileService.cs +++ b/ZR.Service/System/IService/ISysFileService.cs @@ -16,7 +16,7 @@ namespace ZR.Service.System.IService /// /// 结果、地址、文件名 (bool, string, string) SaveFile(string picdir, IFormFile formFile); - + (bool, string, string) SaveFile(string picdir, IFormFile formFile, string customFileName); /// /// 按时间来创建文件夹 /// diff --git a/ZR.Service/System/SysFileService.cs b/ZR.Service/System/SysFileService.cs index e189b0f..dce4638 100644 --- a/ZR.Service/System/SysFileService.cs +++ b/ZR.Service/System/SysFileService.cs @@ -10,6 +10,7 @@ using System.Security.Cryptography; using System.Net; using ZR.Model.System; using ZR.Repository.System; +using Infrastructure.Extensions; namespace ZR.Service.System { @@ -35,9 +36,13 @@ namespace ZR.Service.System /// public (bool, string, string) SaveFile(string picdir, IFormFile formFile) { - // eg: idcard/2020/08/18 + return SaveFile(picdir, formFile, ""); + } + public (bool, string, string) SaveFile(string picdir, IFormFile formFile, string customFileName) + { + // eg: uploads/2020/08/18 string dir = GetdirPath(picdir.ToString()); - string tempName = HashFileName(); + string tempName = customFileName.IsEmpty() ? HashFileName() : customFileName; string fileExt = Path.GetExtension(formFile.FileName); string fileName = $"{tempName}{fileExt}"; string webUrl = $"{domainUrl}/{dir}/{fileName}"; @@ -46,7 +51,6 @@ namespace ZR.Service.System return (statusCode == HttpStatusCode.OK, webUrl, fileName); } - public string GetdirPath(string path = "") { DateTime date = DateTime.Now; diff --git a/ZR.Vue/src/components/FileUpload/index.vue b/ZR.Vue/src/components/FileUpload/index.vue index d22cea3..80129f2 100644 --- a/ZR.Vue/src/components/FileUpload/index.vue +++ b/ZR.Vue/src/components/FileUpload/index.vue @@ -162,7 +162,7 @@ export default { } this.msgSuccess("上传成功"); this.fileList.push({ name: res.data.fileName, url: res.data.url, path: res.data.path }); - this.$emit("input", this.column, this.listToString(this.fileList)); + this.$emit("input", this.column, this.listToString(this.fileList), res.data); }, // 上传进度 uploadProcess(event, file, fileList) { diff --git a/ZR.Vue/src/views/tool/file/index.vue b/ZR.Vue/src/views/tool/file/index.vue index f10fba7..463b26c 100644 --- a/ZR.Vue/src/views/tool/file/index.vue +++ b/ZR.Vue/src/views/tool/file/index.vue @@ -2,6 +2,9 @@
+ + + @@ -11,11 +14,10 @@ - - + 搜索 重置 - + @@ -168,6 +170,7 @@ export default { pageNum: 1, pageSize: 20, storeType: 1, + fileId: undefined, }, // 弹出层标题 title: "", @@ -257,12 +260,12 @@ export default { reset() { this.form = { fileName: "", - fileUrl: undefined, + fileUrl: "", storePath: "uploads", - fileSize: undefined, - fileExt: undefined, + fileSize: 0, + fileExt: "", storeType: 1, - accessUrl: undefined, + accessUrl: "", }; this.resetForm("form"); }, @@ -317,9 +320,9 @@ export default { }); }, //上传成功方法 - handleUploadSuccess(columnName, filelist) { + handleUploadSuccess(columnName, filelist, data) { this.form[columnName] = filelist; - + this.queryParams.fileId = data.fileId; this.open = false; this.getList(); }, @@ -328,7 +331,7 @@ export default { return this.selectDictLabel(this.storeTypeOptions, row.storeType); }, handleSelectStore(val) { - this.queryParams.storeType = val; + this.queryParams.storeType = val; if (val == 1) { this.uploadUrl = "/common/uploadFile"; } else if (val == 2) {