From 11912813a2ce8578922a29a99954281a010feb9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 24 Mar 2022 18:05:52 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=9D=83=E9=99=90=E4=BB=8E=E7=BC=93=E5=AD=98=E4=B8=AD=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E4=B8=8D=E5=AD=98=E5=85=A5jwt=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/System/SysLoginController.cs | 12 ++++---- .../Controllers/System/SysUserController.cs | 5 ++-- .../Extensions/HttpContextExtension.cs | 21 -------------- ZR.Admin.WebApi/Framework/JwtUtil.cs | 28 +++++++++++++++++-- ZR.Model/System/LoginUser.cs | 2 +- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index 3694650..2b89b4c 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -86,8 +86,8 @@ namespace ZR.Admin.WebApi.Controllers.System List permissions = permissionService.GetMenuPermission(user); LoginUser loginUser = new(user, roles, permissions); - CacheHelper.SetCache(GlobalConstant.UserPermKEY + user.UserId, loginUser); - return SUCCESS(JwtUtil.GenerateJwtToken(HttpContext.AddClaims(loginUser), jwtSettings.JwtSettings)); + CacheHelper.SetCache(GlobalConstant.UserPermKEY + user.UserId, permissions); + return SUCCESS(JwtUtil.GenerateJwtToken(JwtUtil.AddClaims(loginUser), jwtSettings.JwtSettings)); } /// @@ -103,11 +103,11 @@ namespace ZR.Admin.WebApi.Controllers.System // //注销登录的用户,相当于ASP.NET中的FormsAuthentication.SignOut // await HttpContext.SignOutAsync(); //}).Wait(); - var id = HttpContext.GetUId(); + var userid = HttpContext.GetUId(); var name = HttpContext.GetName(); - - CacheHelper.Remove(GlobalConstant.UserPermKEY + id); - return SUCCESS(new { name , id}); + + CacheHelper.Remove(GlobalConstant.UserPermKEY + userid); + return SUCCESS(new { name , id = userid }); } /// diff --git a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs index 5f8420b..9f6b0a5 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysUserController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysUserController.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.IO; using System.Linq; +using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Common; using ZR.Model; @@ -94,7 +95,7 @@ namespace ZR.Admin.WebApi.Controllers.System return ToResponse(ApiResult.Error($"新增用户 '{user.UserName}'失败,登录账号已存在")); } - user.Create_by = User.Identity.Name; + user.Create_by = HttpContext.GetName(); user.Password = NETCore.Encrypt.EncryptProvider.Md5(user.Password); return ToResponse(UserService.InsertUser(user)); @@ -112,7 +113,7 @@ namespace ZR.Admin.WebApi.Controllers.System { if (user == null || user.UserId <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } - user.Update_by = User.Identity.Name; + user.Update_by = HttpContext.GetName(); int upResult = UserService.UpdateUser(user); return ToResponse(upResult); diff --git a/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs b/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs index 2df4734..2103a91 100644 --- a/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs +++ b/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs @@ -130,27 +130,6 @@ namespace ZR.Admin.WebApi.Extensions return context != null ? context.Request.Path.Value : ""; } - /// - ///组装Claims - /// - /// - /// - /// - public static List AddClaims(this HttpContext context, LoginUser user) - { - //1、创建Cookie保存用户信息,使用claim - var claims = new List() - { - new Claim(ClaimTypes.PrimarySid, user.UserId.ToString()), - new Claim(ClaimTypes.Name, user.UserName), - new Claim(ClaimTypes.UserData, JsonConvert.SerializeObject(user)) - }; - - //写入Cookie - //WhiteCookie(context, claims); - return claims; - } - private static void WhiteCookie(HttpContext context, List claims) { //2.创建声明主题 指定认证方式 这里使用cookie diff --git a/ZR.Admin.WebApi/Framework/JwtUtil.cs b/ZR.Admin.WebApi/Framework/JwtUtil.cs index 3af5a6f..c846536 100644 --- a/ZR.Admin.WebApi/Framework/JwtUtil.cs +++ b/ZR.Admin.WebApi/Framework/JwtUtil.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Security.Claims; using System.Text; using ZR.Admin.WebApi.Extensions; +using ZR.Common; using ZR.Model.System; namespace ZR.Admin.WebApi.Framework @@ -129,8 +130,9 @@ namespace ZR.Admin.WebApi.Framework try { var userData = jwtToken.FirstOrDefault(x => x.Type == ClaimTypes.UserData).Value; - - LoginUser loginUser = JsonConvert.DeserializeObject(userData); + var loginUser = JsonConvert.DeserializeObject(userData); + var permissions = CacheHelper.GetCache(GlobalConstant.UserPermKEY + loginUser?.UserId); + loginUser.Permissions = (List)permissions; return loginUser; } catch (Exception ex) @@ -139,5 +141,27 @@ namespace ZR.Admin.WebApi.Framework return null; } } + + /// + ///组装Claims + /// + /// + /// + public static List AddClaims(LoginUser user) + { + user.Permissions = new List(); + //1、创建Cookie保存用户信息,使用claim + var claims = new List() + { + new Claim(ClaimTypes.PrimarySid, user.UserId.ToString()), + new Claim(ClaimTypes.Name, user.UserName), + new Claim(ClaimTypes.UserData, JsonConvert.SerializeObject(user)) + }; + + //写入Cookie + //WhiteCookie(context, claims); + return claims; + } + } } diff --git a/ZR.Model/System/LoginUser.cs b/ZR.Model/System/LoginUser.cs index 9b5e797..013a9d1 100644 --- a/ZR.Model/System/LoginUser.cs +++ b/ZR.Model/System/LoginUser.cs @@ -24,7 +24,7 @@ namespace ZR.Model.System /// /// 权限集合 /// - public List Permissions { get; set; } + public List Permissions { get; set; } = new List(); public LoginUser() { } From e657ebca2e65ab3d1bdba553f0e3492900c74d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 24 Mar 2022 18:31:05 +0800 Subject: [PATCH 02/11] update JwtUtil.cs --- ZR.Admin.WebApi/Framework/JwtUtil.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ZR.Admin.WebApi/Framework/JwtUtil.cs b/ZR.Admin.WebApi/Framework/JwtUtil.cs index c846536..eb37c83 100644 --- a/ZR.Admin.WebApi/Framework/JwtUtil.cs +++ b/ZR.Admin.WebApi/Framework/JwtUtil.cs @@ -132,6 +132,7 @@ namespace ZR.Admin.WebApi.Framework var userData = jwtToken.FirstOrDefault(x => x.Type == ClaimTypes.UserData).Value; var loginUser = JsonConvert.DeserializeObject(userData); var permissions = CacheHelper.GetCache(GlobalConstant.UserPermKEY + loginUser?.UserId); + if (permissions == null) return null; loginUser.Permissions = (List)permissions; return loginUser; } From 92711679b310716a90d7adf3772d67cce621f81d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 24 Mar 2022 18:36:28 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E6=8F=90=E4=BE=9BAnt=20Design=20Vue=20?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b7c512b..7845f55 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ * 后端采用Net5、Sqlsugar、MySQL。 * 权限认证使用Jwt,支持多终端认证系统。 * 支持加载动态权限菜单,多方式轻松权限控制 +* 提供了技术栈(Ant Design Vue)版[Ant Design Vue](https://gitee.com/billzh/mc-dull.git) * 七牛云通用云产品优惠券:[点我进入](https://s.qiniu.com/FzEfay)。 * 腾讯云秒杀场:[点我进入](https://curl.qcloud.com/4yEoRquq)。 * 腾讯云优惠券:[点我领取](https://curl.qcloud.com/5J4nag8D)。 From a88fd3a18df0dff432131fbb75b0810ff39c4f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Thu, 24 Mar 2022 21:05:39 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=94=B9=E7=94=A8=E5=BC=82=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Service/System/SysTasksLogService.cs | 4 ++-- ZR.Tasks/TaskScheduler/JobBase.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ZR.Service/System/SysTasksLogService.cs b/ZR.Service/System/SysTasksLogService.cs index 4e66a94..0aa6cd2 100644 --- a/ZR.Service/System/SysTasksLogService.cs +++ b/ZR.Service/System/SysTasksLogService.cs @@ -23,7 +23,7 @@ namespace ZR.Service.System public SysTasksLog AddTaskLog(string jobId, SysTasksLog logModel) { //获取任务信息 - var model = _tasksQzService.GetId(jobId); + var model = _tasksQzService.GetSingleAsync(f => f.ID == jobId).Result; if (model != null) { @@ -33,7 +33,7 @@ namespace ZR.Service.System logModel.CreateTime = DateTime.Now; } - Add(logModel); + InsertAsync(logModel); return logModel; } diff --git a/ZR.Tasks/TaskScheduler/JobBase.cs b/ZR.Tasks/TaskScheduler/JobBase.cs index 38a0780..3de1997 100644 --- a/ZR.Tasks/TaskScheduler/JobBase.cs +++ b/ZR.Tasks/TaskScheduler/JobBase.cs @@ -78,11 +78,11 @@ namespace ZR.Tasks //成功后执行次数+1 if (logModel.Status == "0") { - taskQzService.Update(f => f.ID == job.Key.Name, f => new SysTasksQz() + taskQzService.UpdateAsync(f => new SysTasksQz() { RunTimes = f.RunTimes + 1, LastRunTime = DateTime.Now - }); + }, f => f.ID == job.Key.Name); } logger.Info($"执行任务【{job.Key.Name}|{logModel.JobName}】结果={logModel.JobMessage}"); } From 494ccdbb886ac178d653517ef8ef4accee039b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Fri, 25 Mar 2022 13:40:34 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=85=B3=E9=97=AD=E5=90=8E=E5=86=8D=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E4=B8=8D=E4=BC=9A=E8=A2=AB=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Tasks/TaskSchedulerServer.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ZR.Tasks/TaskSchedulerServer.cs b/ZR.Tasks/TaskSchedulerServer.cs index 681c405..0130aad 100644 --- a/ZR.Tasks/TaskSchedulerServer.cs +++ b/ZR.Tasks/TaskSchedulerServer.cs @@ -123,6 +123,10 @@ namespace ZR.Tasks { return ApiResult.Error(500, $"该计划任务已经在执行:【{tasksQz.Name}】,请勿重复添加!"); } + if (tasksQz?.EndTime <= DateTime.Now) + { + return ApiResult.Error(500, $"结束时间小于当前时间计划将不会被执行"); + } #region 设置开始时间和结束时间 tasksQz.BeginTime = tasksQz.BeginTime == null ? DateTime.Now : tasksQz.BeginTime; @@ -166,10 +170,12 @@ namespace ZR.Tasks // 5、将触发器和任务器绑定到调度器中 await _scheduler.Result.ScheduleJob(job, trigger); //任务没有启动、暂停任务 - if (!tasksQz.IsStart) - { - _scheduler.Result.PauseJob(jobKey).Wait(); - } + //if (!tasksQz.IsStart) + //{ + // _scheduler.Result.PauseJob(jobKey).Wait(); + //} + //按新的trigger重新设置job执行 + await _scheduler.Result.ResumeTrigger(trigger.Key); return ApiResult.Success($"启动计划任务:【{tasksQz.Name}】成功!"); } catch (Exception ex) From 845c75ceb573cbb403a52ca5de7570c74591a116 Mon Sep 17 00:00:00 2001 From: King Date: Fri, 25 Mar 2022 21:50:30 +0800 Subject: [PATCH 06/11] =?UTF-8?q?mster=E5=8F=AA=E6=94=B9=E4=BA=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ZR.Admin.WebApi/appsettings.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ZR.Admin.WebApi/appsettings.json b/ZR.Admin.WebApi/appsettings.json index f4ddf7b..b709f7c 100644 --- a/ZR.Admin.WebApi/appsettings.json +++ b/ZR.Admin.WebApi/appsettings.json @@ -7,8 +7,8 @@ } }, "ConnectionStrings": { - "conn_zrAdmin": "server=LAPTOP-STKF2M8H\\SQLEXPRESS;uid=sa;pwd=zradmin123;database=ZrAdmin;Trusted_Connection=SSPI", - "conn_bus": "server=LAPTOP-STKF2M8H\\SQLEXPRESS;uid=zr;pwd=zradmin123;database=ZrAdmin;Trusted_Connection=SSPI" + "conn_zrAdmin": "server=it-sql08test;uid=wftest;pwd=wftest;database=ZrAdmin;", + "conn_bus": "server=it-sql08test;uid=wftest;pwd=wftest;database=ZrAdmin;" }, "conn_zrAdmin_type": 1, //MySql = 0, SqlServer = 1 "conn_bus_type": 1, @@ -34,7 +34,7 @@ "domainUrl": "http://xxx.xxx.com" //Դ }, "gen": { - "conn": "server=LAPTOP-STKF2M8H\\SQLEXPRESS;user=zr;pwd=abc;database=ZrAdmin;Trusted_Connection=SSPI", + "conn": "server=it-sql08test;uid=wftest;pwd=wftest;database=ZrAdmin;", "dbType": 1, //MySql = 0, SqlServer = 1 "autoPre": true, //Զȥǰ׺ "author": "zr", From 79f57c7ea50e73072cfd6ee67f1274c15e20cef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Sat, 26 Mar 2022 20:23:47 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Infrastructure/Enums/StoreType.cs | 12 +- .../Controllers/CommonController.cs | 45 +++++- ZR.CodeGenerator/CodeGenerateTemplate.cs | 2 +- ZR.Common/AliyunOssHelper.cs | 20 +++ ZR.Model/System/SysFile.cs | 3 +- ZR.Service/System/SysFileService.cs | 7 +- ZR.Vue/src/components/FileUpload/index.vue | 2 +- ZR.Vue/src/components/UploadImage/index.vue | 134 +++++++++--------- ZR.Vue/src/views/tool/file/index.vue | 19 +-- 9 files changed, 146 insertions(+), 98 deletions(-) diff --git a/Infrastructure/Enums/StoreType.cs b/Infrastructure/Enums/StoreType.cs index 4dea7eb..79d8e6d 100644 --- a/Infrastructure/Enums/StoreType.cs +++ b/Infrastructure/Enums/StoreType.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel; namespace Infrastructure.Enums { @@ -30,5 +25,10 @@ namespace Infrastructure.Enums [Description("腾讯云")] TENCENT = 3, + /// + /// 七牛 + /// + [Description("七牛云")] + QINIU = 4 } } diff --git a/ZR.Admin.WebApi/Controllers/CommonController.cs b/ZR.Admin.WebApi/Controllers/CommonController.cs index d36dff1..1b504b5 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.Enums; using Infrastructure.Extensions; using Infrastructure.Model; using Microsoft.AspNetCore.Hosting; @@ -91,19 +92,53 @@ namespace ZR.Admin.WebApi.Controllers /// /// 存储目录 /// 自定义文件名 - /// 上传类型 1、发送邮件 + /// 上传类型1、保存到本地 2、保存到阿里云 /// [HttpPost()] [Verify] [ActionPermissionFilter(Permission = "common")] - public async Task UploadFile([FromForm(Name = "file")] IFormFile formFile, string fileName = "", string fileDir = "uploads", int uploadType = 0) + public async Task UploadFile([FromForm(Name = "file")] IFormFile formFile, string fileName = "", string fileDir = "uploads", StoreType storeType = StoreType.LOCAL) { if (formFile == null) throw new CustomException(ResultCode.PARAM_ERROR, "上传文件不能为空"); + SysFile file = new(); + string fileExt = Path.GetExtension(formFile.FileName);//文件后缀 + double fileSize = Math.Round(formFile.Length / 1024.0, 2);//文件大小KB + string[] NotAllowedFileExtensions = new string[] { ".bat", ".exe", ".jar", ".js" }; + int MaxContentLength = 15; + if (NotAllowedFileExtensions.Contains(fileExt)) + { + return ToResponse(ResultCode.CUSTOM_ERROR, "上传失败,未经允许上传类型"); + } + switch (storeType) + { + case StoreType.LOCAL: + file = await SysFileService.SaveFileToLocal(WebHostEnvironment.WebRootPath, fileName, fileDir, HttpContext.GetName(), formFile); - SysFile file = await SysFileService.SaveFileToLocal(WebHostEnvironment.WebRootPath, fileName, fileDir, HttpContext.GetName(), formFile); + break; + case StoreType.ALIYUN: + if ((fileSize / 1024) > MaxContentLength) + { + return ToResponse(ResultCode.CUSTOM_ERROR, "上传文件过大,不能超过 " + MaxContentLength + " MB"); + } + file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", fileDir, HttpContext.GetName()) + { + StoreType = (int)StoreType.ALIYUN, + FileType = formFile.ContentType + }; + file = await SysFileService.SaveFileToAliyun(file, formFile); + + if (file.Id <= 0) { return ToResponse(ApiResult.Error("阿里云连接失败")); } + break; + case StoreType.TENCENT: + break; + case StoreType.QINIU: + break; + default: + break; + } return SUCCESS(new { - url = uploadType == 1 ? file.FileUrl : file.AccessUrl, + url = file.AccessUrl, fileName, fileId = file.Id.ToString() }); @@ -134,7 +169,7 @@ namespace ZR.Admin.WebApi.Controllers { return ToResponse(ResultCode.CUSTOM_ERROR, "上传文件过大,不能超过 " + MaxContentLength + " MB"); } - SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", fileDir, "", HttpContext.GetName()) + SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", fileDir, HttpContext.GetName()) { StoreType = (int)Infrastructure.Enums.StoreType.ALIYUN, FileType = formFile.ContentType diff --git a/ZR.CodeGenerator/CodeGenerateTemplate.cs b/ZR.CodeGenerator/CodeGenerateTemplate.cs index 03fcdbc..4e526c2 100644 --- a/ZR.CodeGenerator/CodeGenerateTemplate.cs +++ b/ZR.CodeGenerator/CodeGenerateTemplate.cs @@ -89,7 +89,7 @@ namespace ZR.CodeGenerator //图片 sb.AppendLine(" "); sb.AppendLine($" "); - sb.AppendLine($@" "); + sb.AppendLine($@" "); sb.AppendLine(" "); sb.AppendLine(" "); } diff --git a/ZR.Common/AliyunOssHelper.cs b/ZR.Common/AliyunOssHelper.cs index 4c9bf97..b45c87a 100644 --- a/ZR.Common/AliyunOssHelper.cs +++ b/ZR.Common/AliyunOssHelper.cs @@ -43,5 +43,25 @@ namespace ZR.Common return System.Net.HttpStatusCode.BadRequest; } + /// + /// 删除资源 + /// + /// + /// + /// + public static System.Net.HttpStatusCode DeleteFile(string dirPath, string bucketName = "") + { + if (string.IsNullOrEmpty(bucketName)) { bucketName = bucketName1; } + try + { + OssClient client = new(endpoint, accessKeyId, accessKeySecret); + DeleteObjectResult putObjectResult = client.DeleteObject(bucketName, dirPath); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + return System.Net.HttpStatusCode.BadRequest; + } } } diff --git a/ZR.Model/System/SysFile.cs b/ZR.Model/System/SysFile.cs index 501b9c0..81c75be 100644 --- a/ZR.Model/System/SysFile.cs +++ b/ZR.Model/System/SysFile.cs @@ -72,14 +72,13 @@ namespace ZR.Model.System public string AccessUrl { get; set; } public SysFile() { } - public SysFile(string originFileName, string fileName, string ext, string fileSize, string storePath, string accessUrl,string create_by) + public SysFile(string originFileName, string fileName, string ext, string fileSize, string storePath, string create_by) { StorePath = storePath; RealName = originFileName; FileName = fileName; FileExt = ext; FileSize = fileSize; - AccessUrl = accessUrl; Create_by = create_by; Create_time = DateTime.Now; } diff --git a/ZR.Service/System/SysFileService.cs b/ZR.Service/System/SysFileService.cs index 415a21e..a774d7d 100644 --- a/ZR.Service/System/SysFileService.cs +++ b/ZR.Service/System/SysFileService.cs @@ -51,14 +51,15 @@ namespace ZR.Service.System using (var stream = new FileStream(finalFilePath, FileMode.Create)) { - await formFile.CopyToAsync(stream); + await formFile.CopyToAsync(stream);//await 不能少 } string accessPath = string.Concat(OptionsSetting.Upload.UploadUrl, "/", filePath.Replace("\\", "/"), "/", fileName); - SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", filePath, accessPath, userName) + SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", filePath, userName) { StoreType = (int)Infrastructure.Enums.StoreType.LOCAL, FileType = formFile.ContentType, - FileUrl = finalFilePath + FileUrl = finalFilePath, + AccessUrl = accessPath }; file.Id = await InsertFile(file); return file; diff --git a/ZR.Vue/src/components/FileUpload/index.vue b/ZR.Vue/src/components/FileUpload/index.vue index 14d85de..a8a9eaf 100644 --- a/ZR.Vue/src/components/FileUpload/index.vue +++ b/ZR.Vue/src/components/FileUpload/index.vue @@ -52,7 +52,7 @@ export default { // 文件类型, 例如['png', 'jpg', 'jpeg'] fileType: { type: Array, - default: () => ['doc', 'xls', 'ppt', 'txt', 'pdf', 'svga', 'json'] + default: () => ['doc', 'xls', 'ppt', 'txt', 'pdf', 'json'] }, // 是否显示提示 isShowTip: { diff --git a/ZR.Vue/src/components/UploadImage/index.vue b/ZR.Vue/src/components/UploadImage/index.vue index 8bf4f22..3317d27 100644 --- a/ZR.Vue/src/components/UploadImage/index.vue +++ b/ZR.Vue/src/components/UploadImage/index.vue @@ -1,7 +1,7 @@