diff --git a/.gitignore b/.gitignore index 12a0b90e..70e6483c 100644 --- a/.gitignore +++ b/.gitignore @@ -348,9 +348,9 @@ healthchecksdb # Backup folder for Package Reference Convert tool in Visual Studio 2017 MigrationBackup/ Publish -YiSha.Web/YiSha.Admin.Web/DataProtection -YiSha.Web/YiSha.Admin.WebApi/DataProtection YiSha.Web/YiSha.Admin.Web/Resource +YiSha.Web/YiSha.Admin.Web/DataProtection YiSha.Web/YiSha.Admin.WebApi/Resource +YiSha.Web/YiSha.Admin.WebApi/DataProtection .idea/ \ No newline at end of file diff --git a/Document/DatabaseScript/mysql_data.sql b/Document/DatabaseScript/mysql_data.sql index 56c472ba..2e3f78d5 100644 --- a/Document/DatabaseScript/mysql_data.sql +++ b/Document/DatabaseScript/mysql_data.sql @@ -3889,7 +3889,7 @@ INSERT INTO `SysMenu` (`Id`, `BaseIsDelete`, `BaseCreateTime`, `BaseModifyTime`, (16508640061130131, 0, '2019-01-05 07:42:31', '2019-02-08 10:30:52', 0, 0, 0, 16508640061130129, '文章新增', '', '', '', 2, 3, 1, 'organization:news:add', ''), (16508640061130132, 0, '2019-01-05 07:42:49', '2019-02-08 10:31:01', 0, 0, 0, 16508640061130129, '文章修改', '', '', '', 3, 3, 1, 'organization:news:edit', ''), (16508640061130133, 0, '2019-01-05 07:43:19', '2019-02-08 10:31:08', 0, 0, 0, 16508640061130129, '文章删除', '', '', '', 4, 3, 1, 'organization:news:delete', ''), - (16508640061130134, 0, '2019-01-07 13:05:40', '2019-07-28 19:20:06', 0, 16508640061130151, 0, 16508640061130070, '系统api', '', 'https://www.yishasoft.com/api/api-doc', '', 13, 2, 1, 'system:api:view', ''), + (16508640061130134, 0, '2019-01-07 13:05:40', '2019-07-28 19:20:06', 0, 16508640061130151, 0, 16508640061130070, '开发文档', '', 'http://www.toolhelper.cn/doc/', '', 13, 2, 1, 'system:api:view', ''), (16508640061130135, 0, '2019-01-09 17:05:00', '2019-01-09 17:05:00', 0, 0, 0, 16508640061130076, 'Api日志', '', 'SystemManage/LogApi/LogApiIndex', '', 3, 2, 1, 'system:logapi:view', ''), (16508640061130136, 0, '2019-01-09 17:06:11', '2019-01-09 17:06:31', 0, 0, 0, 16508640061130135, 'Api日志查询', '', '', '', 1, 3, 1, 'system:logapi:search', ''), (16508640061130137, 0, '2019-01-09 17:07:24', '2019-01-09 17:07:24', 0, 0, 0, 16508640061130135, 'Api日志删除', '', '', '', 2, 3, 1, 'system:logapi:delete', ''), diff --git a/Document/DatabaseScript/sqlserver_data.sql b/Document/DatabaseScript/sqlserver_data.sql index a3370b95..7782b4fc 100644 --- a/Document/DatabaseScript/sqlserver_data.sql +++ b/Document/DatabaseScript/sqlserver_data.sql @@ -3879,7 +3879,7 @@ INSERT [dbo].[SysMenu] ([Id], [BaseIsDelete], [BaseCreateTime], [BaseModifyTime] INSERT [dbo].[SysMenu] ([Id], [BaseIsDelete], [BaseCreateTime], [BaseModifyTime], [BaseCreatorId], [BaseModifierId], [BaseVersion], [ParentId], [MenuName], [MenuIcon], [MenuUrl], [MenuTarget], [MenuSort], [MenuType], [MenuStatus], [Authorize], [Remark]) VALUES (16508640061130131, 0, CAST(0x0000A9CC007F08B4 AS DateTime), CAST(0x0000A9EE00AD45D0 AS DateTime), 0, 0, 0, 16508640061130129, N'文章新增', N'', N'', N'', 2, 3, 1, N'organization:news:add', N'') INSERT [dbo].[SysMenu] ([Id], [BaseIsDelete], [BaseCreateTime], [BaseModifyTime], [BaseCreatorId], [BaseModifierId], [BaseVersion], [ParentId], [MenuName], [MenuIcon], [MenuUrl], [MenuTarget], [MenuSort], [MenuType], [MenuStatus], [Authorize], [Remark]) VALUES (16508640061130132, 0, CAST(0x0000A9CC007F1DCC AS DateTime), CAST(0x0000A9EE00AD505C AS DateTime), 0, 0, 0, 16508640061130129, N'文章修改', N'', N'', N'', 3, 3, 1, N'organization:news:edit', N'') INSERT [dbo].[SysMenu] ([Id], [BaseIsDelete], [BaseCreateTime], [BaseModifyTime], [BaseCreatorId], [BaseModifierId], [BaseVersion], [ParentId], [MenuName], [MenuIcon], [MenuUrl], [MenuTarget], [MenuSort], [MenuType], [MenuStatus], [Authorize], [Remark]) VALUES (16508640061130133, 0, CAST(0x0000A9CC007F40F4 AS DateTime), CAST(0x0000A9EE00AD5890 AS DateTime), 0, 0, 0, 16508640061130129, N'文章删除', N'', N'', N'', 4, 3, 1, N'organization:news:delete', N'') -INSERT [dbo].[SysMenu] ([Id], [BaseIsDelete], [BaseCreateTime], [BaseModifyTime], [BaseCreatorId], [BaseModifierId], [BaseVersion], [ParentId], [MenuName], [MenuIcon], [MenuUrl], [MenuTarget], [MenuSort], [MenuType], [MenuStatus], [Authorize], [Remark]) VALUES (16508640061130134, 0, CAST(0x0000A9CE00D7CA30 AS DateTime), CAST(0x0000AA98013EA188 AS DateTime), 0, 16508640061130151, 0, 16508640061130070, N'系统api', N'', N'https://www.yishasoft.com/api/api-doc', N'', 13, 2, 1, N'system:api:view', N'') +INSERT [dbo].[SysMenu] ([Id], [BaseIsDelete], [BaseCreateTime], [BaseModifyTime], [BaseCreatorId], [BaseModifierId], [BaseVersion], [ParentId], [MenuName], [MenuIcon], [MenuUrl], [MenuTarget], [MenuSort], [MenuType], [MenuStatus], [Authorize], [Remark]) VALUES (16508640061130134, 0, CAST(0x0000A9CE00D7CA30 AS DateTime), CAST(0x0000AA98013EA188 AS DateTime), 0, 16508640061130151, 0, 16508640061130070, N'开发文档', N'', N'http://www.toolhelper.cn/doc/', N'', 13, 2, 1, N'system:api:view', N'') INSERT [dbo].[SysMenu] ([Id], [BaseIsDelete], [BaseCreateTime], [BaseModifyTime], [BaseCreatorId], [BaseModifierId], [BaseVersion], [ParentId], [MenuName], [MenuIcon], [MenuUrl], [MenuTarget], [MenuSort], [MenuType], [MenuStatus], [Authorize], [Remark]) VALUES (16508640061130135, 0, CAST(0x0000A9D001198650 AS DateTime), CAST(0x0000A9D001198650 AS DateTime), 0, 0, 0, 16508640061130076, N'Api日志', N'', N'SystemManage/LogApi/LogApiIndex', N'', 3, 2, 1, N'system:logapi:view', N'') INSERT [dbo].[SysMenu] ([Id], [BaseIsDelete], [BaseCreateTime], [BaseModifyTime], [BaseCreatorId], [BaseModifierId], [BaseVersion], [ParentId], [MenuName], [MenuIcon], [MenuUrl], [MenuTarget], [MenuSort], [MenuType], [MenuStatus], [Authorize], [Remark]) VALUES (16508640061130136, 0, CAST(0x0000A9D00119D984 AS DateTime), CAST(0x0000A9D00119F0F4 AS DateTime), 0, 0, 0, 16508640061130135, N'Api日志查询', N'', N'', N'', 1, 3, 1, N'system:logapi:search', N'') INSERT [dbo].[SysMenu] ([Id], [BaseIsDelete], [BaseCreateTime], [BaseModifyTime], [BaseCreatorId], [BaseModifierId], [BaseVersion], [ParentId], [MenuName], [MenuIcon], [MenuUrl], [MenuTarget], [MenuSort], [MenuType], [MenuStatus], [Authorize], [Remark]) VALUES (16508640061130137, 0, CAST(0x0000A9D0011A2F10 AS DateTime), CAST(0x0000A9D0011A2F10 AS DateTime), 0, 0, 0, 16508640061130135, N'Api日志删除', N'', N'', N'', 2, 3, 1, N'system:logapi:delete', N'') diff --git a/YiSha.Web/YiSha.Admin.Web/wwwroot/image/demo_1.jpg b/Document/demo_1.jpg similarity index 100% rename from YiSha.Web/YiSha.Admin.Web/wwwroot/image/demo_1.jpg rename to Document/demo_1.jpg diff --git a/YiSha.Web/YiSha.Admin.Web/wwwroot/image/demo_2.png b/Document/demo_2.png similarity index 100% rename from YiSha.Web/YiSha.Admin.Web/wwwroot/image/demo_2.png rename to Document/demo_2.png diff --git a/YiSha.Web/YiSha.Admin.Web/wwwroot/image/demo_3.png b/Document/demo_3.png similarity index 100% rename from YiSha.Web/YiSha.Admin.Web/wwwroot/image/demo_3.png rename to Document/demo_3.png diff --git a/YiSha.Web/YiSha.Admin.Web/wwwroot/image/demo_4.png b/Document/demo_4.png similarity index 100% rename from YiSha.Web/YiSha.Admin.Web/wwwroot/image/demo_4.png rename to Document/demo_4.png diff --git a/README.md b/README.md index 32e59619..d3074bf5 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,7 @@ ## YiShaAdmin + YiShaAdmin 基于.NET Core Web开发,借鉴了很多开源项目的优点,让你开发Web管理系统和移动端Api更简单,所以我也把她开源了。 她可以用于所有的Web应用程序,例如网站管理后台、CMS、CRM、ERP、OA这类的系统和移动端Api。
- -| YiShaAdmin 版本 | .NET Core 版本 | 是否支持 | 链接 | Developer | -|:-----|:-----|:-----|:-----|:-----| -| 6.0 | 6.0 | 支持(开发中,不建议商用) | [YiShaAdmin-Net6.0](https://github.com/liukuo362573/YiShaAdmin/tree/YiShaAdmin-Net6) | [zgcwkj](https://github.com/zgcwkj) | -| 3.1 | 3.1 | 支持 | [YiShaAdmin-Net3.1](https://github.com/liukuo362573/YiShaAdmin/tree/master) | | -| 2.2 | 2.2 | 支持 | [YiShaAdmin-Net2.2](https://github.com/liukuo362573/YiShaAdmin/releases/tag/v2.2)| | - ## 内置功能 @@ -26,7 +20,6 @@ - 代码生成:快速生成对单表的增删改查 - 服务器信息:查看服务器的基本信息 - ## 开发文档 文档地址:[https://www.toolhelper.cn/doc](http://www.toolhelper.cn/doc) @@ -37,10 +30,10 @@ ## 演示图 -![登录页面](https://raw.githubusercontent.com/liukuo362573/YiShaAdmin/master/YiSha.Web/YiSha.Admin.Web/wwwroot/image/demo_1.jpg) -![登录进去首页](https://raw.githubusercontent.com/liukuo362573/YiShaAdmin/master/YiSha.Web/YiSha.Admin.Web/wwwroot/image/demo_2.png) -![用户列表](https://raw.githubusercontent.com/liukuo362573/YiShaAdmin/master/YiSha.Web/YiSha.Admin.Web/wwwroot/image/demo_3.png) -![用户列表修改](https://raw.githubusercontent.com/liukuo362573/YiShaAdmin/master/YiSha.Web/YiSha.Admin.Web/wwwroot/image/demo_4.png) +![登录页面](Document/demo_1.jpg) +![登录进去首页](Document/demo_2.png) +![用户列表](Document/demo_3.png) +![用户列表修改](Document/demo_4.png) ## 如何参与开源项目 @@ -54,4 +47,4 @@ ## License -[MIT](https://github.com/liukuo362573/yishaadmin/blob/master/LICENSE) +[MIT](LICENSE) diff --git a/YiSha.Business/YiSha.Business.AutoJob/YiSha.Business.AutoJob.csproj b/YiSha.Business/YiSha.Business.AutoJob/YiSha.Business.AutoJob.csproj index 265e9499..3161fc25 100644 --- a/YiSha.Business/YiSha.Business.AutoJob/YiSha.Business.AutoJob.csproj +++ b/YiSha.Business/YiSha.Business.AutoJob/YiSha.Business.AutoJob.csproj @@ -1,11 +1,13 @@ - net6.0 + net6.0 + enable + enable - + diff --git a/YiSha.Business/YiSha.Business.Cache/YiSha.Business.Cache.csproj b/YiSha.Business/YiSha.Business.Cache/YiSha.Business.Cache.csproj index 3633b71f..34aec7d2 100644 --- a/YiSha.Business/YiSha.Business.Cache/YiSha.Business.Cache.csproj +++ b/YiSha.Business/YiSha.Business.Cache/YiSha.Business.Cache.csproj @@ -1,7 +1,9 @@ - net6.0 + net6.0 + enable + enable diff --git a/YiSha.Business/YiSha.Business/SystemManage/MenuBLL.cs b/YiSha.Business/YiSha.Business/SystemManage/MenuBLL.cs index 3a4dd9a0..7291a444 100644 --- a/YiSha.Business/YiSha.Business/SystemManage/MenuBLL.cs +++ b/YiSha.Business/YiSha.Business/SystemManage/MenuBLL.cs @@ -1,18 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using YiSha.Entity; -using YiSha.Service; -using YiSha.Service.SystemManage; +using YiSha.Business.Cache; using YiSha.Entity.SystemManage; -using YiSha.Model.Result; -using YiSha.Model; -using YiSha.Util.Model; -using YiSha.Business.Cache; using YiSha.Model.Param.SystemManage; +using YiSha.Model.Result; +using YiSha.Service.SystemManage; using YiSha.Util.Extension; +using YiSha.Util.Model; namespace YiSha.Business.SystemManage { @@ -23,11 +15,12 @@ public class MenuBLL private MenuCache menuCache = new MenuCache(); #region 获取数据 - public async Task>> GetList(MenuListParam param) + + public async Task>> GetList(MenuListParam? param = default) { var obj = new TData>(); - List list = await menuCache.GetList(); + var list = await menuCache.GetList(); list = ListFilter(param, list); obj.Data = list; @@ -40,10 +33,10 @@ public async Task>> GetZtreeList(MenuListParam param) var obj = new TData>(); obj.Data = new List(); - List list = await menuCache.GetList(); + var list = await menuCache.GetList(); list = ListFilter(param, list); - foreach (MenuEntity menu in list) + foreach (var menu in list) { obj.Data.Add(new ZtreeInfo { @@ -59,14 +52,14 @@ public async Task>> GetZtreeList(MenuListParam param) public async Task> GetEntity(long id) { - TData obj = new TData(); + var obj = new TData(); obj.Data = await menuService.GetEntity(id); if (obj.Data != null) { - long parentId = obj.Data.ParentId.Value; + var parentId = obj.Data.ParentId.Value; if (parentId > 0) { - MenuEntity parentMenu = await menuService.GetEntity(parentId); + var parentMenu = await menuService.GetEntity(parentId); if (parentMenu != null) { obj.Data.ParentName = parentMenu.MenuName; @@ -83,17 +76,19 @@ public async Task> GetEntity(long id) public async Task> GetMaxSort(long parentId) { - TData obj = new TData(); + var obj = new TData(); obj.Data = await menuService.GetMaxSort(parentId); obj.Tag = 1; return obj; } - #endregion + + #endregion 获取数据 #region 提交数据 + public async Task> SaveForm(MenuEntity entity) { - TData obj = new TData(); + var obj = new TData(); if (!entity.Id.IsNullOrZero() && entity.Id == entity.ParentId) { obj.Message = "不能选择自己作为上级菜单!"; @@ -115,17 +110,19 @@ public async Task> SaveForm(MenuEntity entity) public async Task DeleteForm(string ids) { - TData obj = new TData(); + var obj = new TData(); await menuService.DeleteForm(ids); menuCache.Remove(); obj.Tag = 1; return obj; } - #endregion + + #endregion 提交数据 #region 私有方法 - private List ListFilter(MenuListParam param, List list) + + private List ListFilter(MenuListParam? param, List list) { if (param != null) { @@ -140,6 +137,7 @@ private List ListFilter(MenuListParam param, List list) } return list; } - #endregion + + #endregion 私有方法 } } diff --git a/YiSha.Business/YiSha.Business/YiSha.Business.csproj b/YiSha.Business/YiSha.Business/YiSha.Business.csproj index a8d689a7..4a5d1bb5 100644 --- a/YiSha.Business/YiSha.Business/YiSha.Business.csproj +++ b/YiSha.Business/YiSha.Business/YiSha.Business.csproj @@ -1,7 +1,9 @@ - net6.0 + net6.0 + enable + enable diff --git a/YiSha.Business/YiSha.Service/YiSha.Service.csproj b/YiSha.Business/YiSha.Service/YiSha.Service.csproj index 62371380..f2ae065a 100644 --- a/YiSha.Business/YiSha.Service/YiSha.Service.csproj +++ b/YiSha.Business/YiSha.Service/YiSha.Service.csproj @@ -1,7 +1,9 @@ - net6.0 + net6.0 + enable + enable diff --git a/YiSha.Cache/YiSha.Cache.Factory/YiSha.Cache.Factory.csproj b/YiSha.Cache/YiSha.Cache.Factory/YiSha.Cache.Factory.csproj index 53bd5062..01f13f15 100644 --- a/YiSha.Cache/YiSha.Cache.Factory/YiSha.Cache.Factory.csproj +++ b/YiSha.Cache/YiSha.Cache.Factory/YiSha.Cache.Factory.csproj @@ -2,6 +2,8 @@ net6.0 + enable + enable diff --git a/YiSha.Cache/YiSha.Cache.Interface/YiSha.Cache.Interface.csproj b/YiSha.Cache/YiSha.Cache.Interface/YiSha.Cache.Interface.csproj index efc79faf..74cb13c8 100644 --- a/YiSha.Cache/YiSha.Cache.Interface/YiSha.Cache.Interface.csproj +++ b/YiSha.Cache/YiSha.Cache.Interface/YiSha.Cache.Interface.csproj @@ -1,7 +1,9 @@ - net6.0 + net6.0 + enable + enable diff --git a/YiSha.Cache/YiSha.MemoryCache/YiSha.MemoryCache.csproj b/YiSha.Cache/YiSha.MemoryCache/YiSha.MemoryCache.csproj index 7d8e148a..b4bb17f9 100644 --- a/YiSha.Cache/YiSha.MemoryCache/YiSha.MemoryCache.csproj +++ b/YiSha.Cache/YiSha.MemoryCache/YiSha.MemoryCache.csproj @@ -1,11 +1,13 @@  - net6.0 + net6.0 + enable + enable - + diff --git a/YiSha.Cache/YiSha.RedisCache/YiSha.RedisCache.csproj b/YiSha.Cache/YiSha.RedisCache/YiSha.RedisCache.csproj index 3093d380..0ca6f082 100644 --- a/YiSha.Cache/YiSha.RedisCache/YiSha.RedisCache.csproj +++ b/YiSha.Cache/YiSha.RedisCache/YiSha.RedisCache.csproj @@ -1,11 +1,13 @@ - + - net6.0 + net6.0 + enable + enable - + diff --git a/YiSha.Data/YiSha.Data.EF/YiSha.Data.EF.csproj b/YiSha.Data/YiSha.Data.EF/YiSha.Data.EF.csproj index 6aebde8c..2bb66e1c 100644 --- a/YiSha.Data/YiSha.Data.EF/YiSha.Data.EF.csproj +++ b/YiSha.Data/YiSha.Data.EF/YiSha.Data.EF.csproj @@ -1,20 +1,11 @@  - net6.0 + net6.0 + enable + enable - - - - - - - - - - - diff --git a/YiSha.Data/YiSha.Data.Repository/YiSha.Data.Repository.csproj b/YiSha.Data/YiSha.Data.Repository/YiSha.Data.Repository.csproj index 10e786ae..62360049 100644 --- a/YiSha.Data/YiSha.Data.Repository/YiSha.Data.Repository.csproj +++ b/YiSha.Data/YiSha.Data.Repository/YiSha.Data.Repository.csproj @@ -1,7 +1,9 @@  - net6.0 + net6.0 + enable + enable diff --git a/YiSha.Data/YiSha.Data/DbHelper.cs b/YiSha.Data/YiSha.Data/DbHelper.cs index 15243b5d..cc7cc519 100644 --- a/YiSha.Data/YiSha.Data/DbHelper.cs +++ b/YiSha.Data/YiSha.Data/DbHelper.cs @@ -101,7 +101,8 @@ public async Task ExecuteReadeAsync(CommandType cmdType, string str dbContext, Guid.NewGuid(), connection.ConnectionId, - startTime); + startTime, + CommandSource.Unknown); var reader = interceptionResult.HasResult ? interceptionResult.Result @@ -117,7 +118,8 @@ public async Task ExecuteReadeAsync(CommandType cmdType, string str connection.ConnectionId, reader, startTime, - stopwatch.Elapsed); + stopwatch.Elapsed, + CommandSource.Unknown); } return reader; } @@ -169,7 +171,8 @@ public async Task ExecuteScalarAsync(CommandType cmdType, string strSql, dbContext, Guid.NewGuid(), connection.ConnectionId, - startTime); + startTime, + CommandSource.Unknown); var obj = interceptionResult.HasResult ? interceptionResult.Result @@ -185,7 +188,8 @@ public async Task ExecuteScalarAsync(CommandType cmdType, string strSql, connection.ConnectionId, obj, startTime, - stopwatch.Elapsed); + stopwatch.Elapsed, + CommandSource.Unknown); } return obj; } diff --git a/YiSha.Data/YiSha.Data/YiSha.Data.csproj b/YiSha.Data/YiSha.Data/YiSha.Data.csproj index 87da2263..ff013d03 100644 --- a/YiSha.Data/YiSha.Data/YiSha.Data.csproj +++ b/YiSha.Data/YiSha.Data/YiSha.Data.csproj @@ -1,14 +1,16 @@ - + - net6.0 + net6.0 + enable + enable - - - - + + + + diff --git a/YiSha.Entity/YiSha.Entity/BaseEntity.cs b/YiSha.Entity/YiSha.Entity/BaseEntity.cs index 35c8caa8..a590b731 100644 --- a/YiSha.Entity/YiSha.Entity/BaseEntity.cs +++ b/YiSha.Entity/YiSha.Entity/BaseEntity.cs @@ -1,11 +1,8 @@ -using System; -using Newtonsoft.Json; -using System.ComponentModel.DataAnnotations.Schema; +using Newtonsoft.Json; using System.ComponentModel; -using System.Threading.Tasks; -using YiSha.Util; -using YiSha.Web.Code; +using System.ComponentModel.DataAnnotations.Schema; using YiSha.IdGenerator; +using YiSha.Web.Code; namespace YiSha.Entity { @@ -19,7 +16,6 @@ public class BaseEntity /// 所有表的主键 /// long返回到前端js的时候,会丢失精度,所以转成字符串 /// - [JsonConverter(typeof(StringJsonConverter))] public long? Id { get; set; } /// @@ -39,7 +35,6 @@ public class BaseCreateEntity : BaseEntity /// /// 创建时间 /// - [JsonConverter(typeof(DateTimeJsonConverter))] [Description("创建时间")] public DateTime? BaseCreateTime { get; set; } @@ -85,7 +80,6 @@ public class BaseModifyEntity : BaseCreateEntity /// /// 修改时间 /// - [JsonConverter(typeof(DateTimeJsonConverter))] [Description("修改时间")] public DateTime? BaseModifyTime { get; set; } @@ -128,7 +122,7 @@ public class BaseExtensionEntity : BaseModifyEntity public new async Task Create() { this.BaseIsDelete = 0; - + await base.Create(); await base.Modify(); diff --git a/YiSha.Entity/YiSha.Entity/OrganizationManage/DepartmentEntity.cs b/YiSha.Entity/YiSha.Entity/OrganizationManage/DepartmentEntity.cs index b00f4604..2fd4916a 100644 --- a/YiSha.Entity/YiSha.Entity/OrganizationManage/DepartmentEntity.cs +++ b/YiSha.Entity/YiSha.Entity/OrganizationManage/DepartmentEntity.cs @@ -1,24 +1,15 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using YiSha.Util; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.OrganizationManage { [Table("SysDepartment")] public class DepartmentEntity : BaseExtensionEntity { - [JsonConverter(typeof(StringJsonConverter))] public long? ParentId { get; set; } public string DepartmentName { get; set; } public string Telephone { get; set; } public string Fax { get; set; } public string Email { get; set; } - [JsonConverter(typeof(StringJsonConverter))] public long? PrincipalId { get; set; } public int? DepartmentSort { get; set; } public string Remark { get; set; } @@ -28,6 +19,7 @@ public class DepartmentEntity : BaseExtensionEntity /// [NotMapped] public string Ids { get; set; } + /// /// 负责人名称 /// diff --git a/YiSha.Entity/YiSha.Entity/OrganizationManage/NewsEntity.cs b/YiSha.Entity/YiSha.Entity/OrganizationManage/NewsEntity.cs index 9353ccaf..aa5fe9d6 100644 --- a/YiSha.Entity/YiSha.Entity/OrganizationManage/NewsEntity.cs +++ b/YiSha.Entity/YiSha.Entity/OrganizationManage/NewsEntity.cs @@ -1,7 +1,4 @@ -using System; -using Newtonsoft.Json; -using System.ComponentModel.DataAnnotations.Schema; -using YiSha.Util; +using System.ComponentModel.DataAnnotations.Schema; using YiSha.Entity.SystemManage; namespace YiSha.Entity.OrganizationManage @@ -12,48 +9,47 @@ public class NewsEntity : BaseAreaEntity /// /// 文章标题 /// - /// public string NewsTitle { get; set; } + /// /// 文章内容 /// /// public string NewsContent { get; set; } + /// /// 文章标签 /// public string NewsTag { get; set; } + /// /// 缩略图 /// - /// public string ThumbImage { get; set; } + /// /// 作者 /// - /// public string NewsAuthor { get; set; } + /// /// 排序 /// - /// public int? NewsSort { get; set; } + /// /// 发布时间 /// - /// - [JsonConverter(typeof(DateTimeJsonConverter))] public DateTime? NewsDate { get; set; } + /// /// 文章类别 /// - /// public int? NewsType { get; set; } + /// /// 阅读量 /// - /// public int? ViewTimes { get; set; } - } } diff --git a/YiSha.Entity/YiSha.Entity/OrganizationManage/PositionEntity.cs b/YiSha.Entity/YiSha.Entity/OrganizationManage/PositionEntity.cs index 5094652e..a4c27c5a 100644 --- a/YiSha.Entity/YiSha.Entity/OrganizationManage/PositionEntity.cs +++ b/YiSha.Entity/YiSha.Entity/OrganizationManage/PositionEntity.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.OrganizationManage { diff --git a/YiSha.Entity/YiSha.Entity/OrganizationManage/UserBelongEntity.cs b/YiSha.Entity/YiSha.Entity/OrganizationManage/UserBelongEntity.cs index eb7bc2b9..b43e933a 100644 --- a/YiSha.Entity/YiSha.Entity/OrganizationManage/UserBelongEntity.cs +++ b/YiSha.Entity/YiSha.Entity/OrganizationManage/UserBelongEntity.cs @@ -1,20 +1,11 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using YiSha.Util; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.OrganizationManage { [Table("SysUserBelong")] public class UserBelongEntity : BaseCreateEntity { - [JsonConverter(typeof(StringJsonConverter))] public long? UserId { get; set; } - [JsonConverter(typeof(StringJsonConverter))] public long? BelongId { get; set; } public int? BelongType { get; set; } diff --git a/YiSha.Entity/YiSha.Entity/OrganizationManage/UserEntity.cs b/YiSha.Entity/YiSha.Entity/OrganizationManage/UserEntity.cs index 79cc9ac7..7b630cf5 100644 --- a/YiSha.Entity/YiSha.Entity/OrganizationManage/UserEntity.cs +++ b/YiSha.Entity/YiSha.Entity/OrganizationManage/UserEntity.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; +using Newtonsoft.Json; using System.ComponentModel; using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using YiSha.Util; namespace YiSha.Entity.OrganizationManage { @@ -15,18 +9,25 @@ public class UserEntity : BaseExtensionEntity { [Description("用户名")] public string UserName { get; set; } + public string Password { get; set; } + [JsonIgnore] public string Salt { get; set; } + [Description("真实姓名")] public string RealName { get; set; } + [Description("性别")] public int? Gender { get; set; } + public string Birthday { get; set; } public string Portrait { get; set; } public string Email { get; set; } + [Description("手机号")] public string Mobile { get; set; } + public string QQ { get; set; } public string Wechat { get; set; } public int? LoginCount { get; set; } @@ -40,7 +41,6 @@ public class UserEntity : BaseExtensionEntity public string WebToken { get; set; } public string ApiToken { get; set; } - [JsonConverter(typeof(StringJsonConverter))] public long? DepartmentId { get; set; } [NotMapped] diff --git a/YiSha.Entity/YiSha.Entity/SystemManage/AreaEntity.cs b/YiSha.Entity/YiSha.Entity/SystemManage/AreaEntity.cs index f5166249..ce6a6faf 100644 --- a/YiSha.Entity/YiSha.Entity/SystemManage/AreaEntity.cs +++ b/YiSha.Entity/YiSha.Entity/SystemManage/AreaEntity.cs @@ -1,7 +1,4 @@ -using Newtonsoft.Json; -using System; -using System.ComponentModel.DataAnnotations.Schema; -using YiSha.Util; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.SystemManage { @@ -9,27 +6,31 @@ namespace YiSha.Entity.SystemManage public class AreaEntity : BaseExtensionEntity { /// - /// + /// /// /// public string AreaCode { get; set; } + /// - /// + /// /// /// public string ParentAreaCode { get; set; } + /// - /// + /// /// /// public string AreaName { get; set; } + /// - /// + /// /// /// public string ZipCode { get; set; } + /// - /// + /// /// /// public int? AreaLevel { get; set; } @@ -44,26 +45,29 @@ public class BaseAreaEntity : BaseExtensionEntity /// 省份ID /// /// - [JsonConverter(typeof(StringJsonConverter))] public long? ProvinceId { get; set; } + /// /// 城市ID /// /// - [JsonConverter(typeof(StringJsonConverter))] public long? CityId { get; set; } + /// /// 区域ID /// /// - [JsonConverter(typeof(StringJsonConverter))] public long? CountyId { get; set; } + [NotMapped] public string ProvinceName { get; set; } + [NotMapped] public string CityName { get; set; } + [NotMapped] public string CountryName { get; set; } + [NotMapped] public string AreaId { get; set; } } diff --git a/YiSha.Entity/YiSha.Entity/SystemManage/AutoJobEntity.cs b/YiSha.Entity/YiSha.Entity/SystemManage/AutoJobEntity.cs index e6a78540..e41c66f5 100644 --- a/YiSha.Entity/YiSha.Entity/SystemManage/AutoJobEntity.cs +++ b/YiSha.Entity/YiSha.Entity/SystemManage/AutoJobEntity.cs @@ -1,7 +1,4 @@ -using Newtonsoft.Json; -using System; -using System.ComponentModel.DataAnnotations.Schema; -using YiSha.Util; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.SystemManage { @@ -9,43 +6,47 @@ namespace YiSha.Entity.SystemManage public class AutoJobEntity : BaseExtensionEntity { /// - /// + /// /// /// public string JobGroupName { get; set; } + /// - /// + /// /// /// public string JobName { get; set; } + /// - /// + /// /// /// public int? JobStatus { get; set; } + /// - /// + /// /// /// public string CronExpression { get; set; } + /// - /// + /// /// /// - [JsonConverter(typeof(DateTimeJsonConverter))] public DateTime? StartTime { get; set; } + /// - /// + /// /// /// - [JsonConverter(typeof(DateTimeJsonConverter))] public DateTime? EndTime { get; set; } + /// - /// + /// /// /// - [JsonConverter(typeof(DateTimeJsonConverter))] public DateTime? NextStartTime { get; set; } + /// /// 备注 /// diff --git a/YiSha.Entity/YiSha.Entity/SystemManage/AutoJobLogEntity.cs b/YiSha.Entity/YiSha.Entity/SystemManage/AutoJobLogEntity.cs index 3af4b849..7d3f744a 100644 --- a/YiSha.Entity/YiSha.Entity/SystemManage/AutoJobLogEntity.cs +++ b/YiSha.Entity/YiSha.Entity/SystemManage/AutoJobLogEntity.cs @@ -1,5 +1,4 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.SystemManage { @@ -7,22 +6,25 @@ namespace YiSha.Entity.SystemManage public class AutoJobLogEntity : BaseCreateEntity { /// - /// + /// /// /// public string JobGroupName { get; set; } + /// - /// + /// /// /// public string JobName { get; set; } + /// - /// + /// /// /// public int? LogStatus { get; set; } + /// - /// + /// /// /// public string Remark { get; set; } diff --git a/YiSha.Entity/YiSha.Entity/SystemManage/DataDictDetailEntity.cs b/YiSha.Entity/YiSha.Entity/SystemManage/DataDictDetailEntity.cs index 839173d6..926d8296 100644 --- a/YiSha.Entity/YiSha.Entity/SystemManage/DataDictDetailEntity.cs +++ b/YiSha.Entity/YiSha.Entity/SystemManage/DataDictDetailEntity.cs @@ -1,5 +1,4 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.SystemManage { @@ -7,30 +6,35 @@ namespace YiSha.Entity.SystemManage public class DataDictDetailEntity : BaseExtensionEntity { /// - /// + /// /// /// public string DictType { get; set; } + /// - /// + /// /// /// public int? DictSort { get; set; } + /// /// 字典键 /// /// public int? DictKey { get; set; } + /// /// 字典值 /// /// public string DictValue { get; set; } + public string ListClass { get; set; } public int? DictStatus { get; set; } public int? IsDefault { get; set; } + /// - /// + /// /// /// public string Remark { get; set; } diff --git a/YiSha.Entity/YiSha.Entity/SystemManage/DataDictEntity.cs b/YiSha.Entity/YiSha.Entity/SystemManage/DataDictEntity.cs index 8d4261ec..2f118f24 100644 --- a/YiSha.Entity/YiSha.Entity/SystemManage/DataDictEntity.cs +++ b/YiSha.Entity/YiSha.Entity/SystemManage/DataDictEntity.cs @@ -1,5 +1,4 @@ -using System; -using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.SystemManage { @@ -7,17 +6,19 @@ namespace YiSha.Entity.SystemManage public class DataDictEntity : BaseExtensionEntity { /// - /// + /// /// /// public string DictType { get; set; } + /// - /// + /// /// /// public int? DictSort { get; set; } + /// - /// + /// /// /// public string Remark { get; set; } diff --git a/YiSha.Entity/YiSha.Entity/SystemManage/LogApiEntity.cs b/YiSha.Entity/YiSha.Entity/SystemManage/LogApiEntity.cs index 02b3f4a5..cd78480f 100644 --- a/YiSha.Entity/YiSha.Entity/SystemManage/LogApiEntity.cs +++ b/YiSha.Entity/YiSha.Entity/SystemManage/LogApiEntity.cs @@ -1,7 +1,4 @@ -using System; -using Newtonsoft.Json; -using System.ComponentModel.DataAnnotations.Schema; -using YiSha.Util; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.SystemManage { @@ -9,38 +6,44 @@ namespace YiSha.Entity.SystemManage public class LogApiEntity : BaseCreateEntity { /// - /// + /// /// /// public int? LogStatus { get; set; } + /// - /// + /// /// /// public string Remark { get; set; } + /// - /// + /// /// /// public string ExecuteUrl { get; set; } + /// - /// + /// /// /// public string ExecuteParam { get; set; } + /// - /// + /// /// /// public string ExecuteResult { get; set; } + /// - /// + /// /// /// public int? ExecuteTime { get; set; } [NotMapped] public string UserName { get; set; } + [NotMapped] public string DepartmentName { get; set; } } diff --git a/YiSha.Entity/YiSha.Entity/SystemManage/LogLoginEntity.cs b/YiSha.Entity/YiSha.Entity/SystemManage/LogLoginEntity.cs index ece6234c..2777dfcb 100644 --- a/YiSha.Entity/YiSha.Entity/SystemManage/LogLoginEntity.cs +++ b/YiSha.Entity/YiSha.Entity/SystemManage/LogLoginEntity.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.SystemManage { diff --git a/YiSha.Entity/YiSha.Entity/SystemManage/LogOperateEntity.cs b/YiSha.Entity/YiSha.Entity/SystemManage/LogOperateEntity.cs index 6e3861c9..99cb5cfc 100644 --- a/YiSha.Entity/YiSha.Entity/SystemManage/LogOperateEntity.cs +++ b/YiSha.Entity/YiSha.Entity/SystemManage/LogOperateEntity.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.SystemManage { @@ -23,8 +18,8 @@ public class LogOperateEntity : BaseCreateEntity [NotMapped] public string UserName { get; set; } + [NotMapped] public string DepartmentName { get; set; } - } } diff --git a/YiSha.Entity/YiSha.Entity/SystemManage/MenuAuthorizeEntity.cs b/YiSha.Entity/YiSha.Entity/SystemManage/MenuAuthorizeEntity.cs index ac86aff2..a27ce444 100644 --- a/YiSha.Entity/YiSha.Entity/SystemManage/MenuAuthorizeEntity.cs +++ b/YiSha.Entity/YiSha.Entity/SystemManage/MenuAuthorizeEntity.cs @@ -1,21 +1,12 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using YiSha.Util; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.SystemManage { [Table("SysMenuAuthorize")] public class MenuAuthorizeEntity : BaseCreateEntity { - [JsonConverter(typeof(StringJsonConverter))] public long? MenuId { get; set; } - [JsonConverter(typeof(StringJsonConverter))] public long? AuthorizeId { get; set; } public int? AuthorizeType { get; set; } diff --git a/YiSha.Entity/YiSha.Entity/SystemManage/MenuEntity.cs b/YiSha.Entity/YiSha.Entity/SystemManage/MenuEntity.cs index fce8a7a9..705818fb 100644 --- a/YiSha.Entity/YiSha.Entity/SystemManage/MenuEntity.cs +++ b/YiSha.Entity/YiSha.Entity/SystemManage/MenuEntity.cs @@ -1,18 +1,10 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using YiSha.Util; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Entity.SystemManage { [Table("SysMenu")] public class MenuEntity : BaseExtensionEntity { - [JsonConverter(typeof(StringJsonConverter))] public long? ParentId { get; set; } public string MenuName { get; set; } diff --git a/YiSha.Entity/YiSha.Entity/SystemManage/RoleEntity.cs b/YiSha.Entity/YiSha.Entity/SystemManage/RoleEntity.cs index 61fef06b..95c92ec1 100644 --- a/YiSha.Entity/YiSha.Entity/SystemManage/RoleEntity.cs +++ b/YiSha.Entity/YiSha.Entity/SystemManage/RoleEntity.cs @@ -14,6 +14,5 @@ public class RoleEntity : BaseExtensionEntity /// [NotMapped] public string MenuIds { get; set; } - } } diff --git a/YiSha.Entity/YiSha.Entity/YiSha.Entity.csproj b/YiSha.Entity/YiSha.Entity/YiSha.Entity.csproj index 7bcd5f15..87297612 100644 --- a/YiSha.Entity/YiSha.Entity/YiSha.Entity.csproj +++ b/YiSha.Entity/YiSha.Entity/YiSha.Entity.csproj @@ -1,7 +1,9 @@ - net6.0 + net6.0 + enable + enable diff --git a/YiSha.Entity/YiSha.Enum/YiSha.Enum.csproj b/YiSha.Entity/YiSha.Enum/YiSha.Enum.csproj index efc79faf..74cb13c8 100644 --- a/YiSha.Entity/YiSha.Enum/YiSha.Enum.csproj +++ b/YiSha.Entity/YiSha.Enum/YiSha.Enum.csproj @@ -1,7 +1,9 @@ - net6.0 + net6.0 + enable + enable diff --git a/YiSha.Entity/YiSha.Model/Param/IdParam.cs b/YiSha.Entity/YiSha.Model/Param/IdParam.cs index c7f090a8..02317d4e 100644 --- a/YiSha.Entity/YiSha.Model/Param/IdParam.cs +++ b/YiSha.Entity/YiSha.Model/Param/IdParam.cs @@ -13,7 +13,6 @@ public class IdParam /// 所有表的主键 /// long返回到前端js的时候,会丢失精度,所以转成字符串 /// - [JsonConverter(typeof(StringJsonConverter))] public long? Id { get; set; } } } diff --git a/YiSha.Entity/YiSha.Model/Result/MenuAuthorizeInfo.cs b/YiSha.Entity/YiSha.Model/Result/MenuAuthorizeInfo.cs index f8ae7780..8d14cc6a 100644 --- a/YiSha.Entity/YiSha.Model/Result/MenuAuthorizeInfo.cs +++ b/YiSha.Entity/YiSha.Model/Result/MenuAuthorizeInfo.cs @@ -10,12 +10,10 @@ namespace YiSha.Model.Result { public class MenuAuthorizeInfo { - [JsonConverter(typeof(StringJsonConverter))] public long? MenuId { get; set; } /// /// 用户Id或者角色Id /// - [JsonConverter(typeof(StringJsonConverter))] public long? AuthorizeId { get; set; } /// /// 用户或者角色 diff --git a/YiSha.Entity/YiSha.Model/Result/ZtreeInfo.cs b/YiSha.Entity/YiSha.Model/Result/ZtreeInfo.cs index e7136888..f9081218 100644 --- a/YiSha.Entity/YiSha.Model/Result/ZtreeInfo.cs +++ b/YiSha.Entity/YiSha.Model/Result/ZtreeInfo.cs @@ -10,10 +10,8 @@ namespace YiSha.Model.Result { public class ZtreeInfo { - [JsonConverter(typeof(StringJsonConverter))] public long? id { get; set; } - [JsonConverter(typeof(StringJsonConverter))] public long? pId { get; set; } public string name { get; set; } diff --git a/YiSha.Entity/YiSha.Model/YiSha.Model.csproj b/YiSha.Entity/YiSha.Model/YiSha.Model.csproj index b0d30029..15c956df 100644 --- a/YiSha.Entity/YiSha.Model/YiSha.Model.csproj +++ b/YiSha.Entity/YiSha.Model/YiSha.Model.csproj @@ -1,7 +1,9 @@ - net6.0 + net6.0 + enable + enable diff --git a/YiSha.Test/YiSha.CacheTest/YiSha.CacheTest.csproj b/YiSha.Test/YiSha.CacheTest/YiSha.CacheTest.csproj index 15c5e147..937e911e 100644 --- a/YiSha.Test/YiSha.CacheTest/YiSha.CacheTest.csproj +++ b/YiSha.Test/YiSha.CacheTest/YiSha.CacheTest.csproj @@ -2,17 +2,18 @@ net6.0 - + enable + enable false - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/YiSha.Test/YiSha.DataTest/YiSha.DataTest.csproj b/YiSha.Test/YiSha.DataTest/YiSha.DataTest.csproj index c972335e..48028862 100644 --- a/YiSha.Test/YiSha.DataTest/YiSha.DataTest.csproj +++ b/YiSha.Test/YiSha.DataTest/YiSha.DataTest.csproj @@ -2,17 +2,18 @@ net6.0 - + enable + enable false - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/YiSha.Test/YiSha.UtilTest/YiSha.UtilTest.csproj b/YiSha.Test/YiSha.UtilTest/YiSha.UtilTest.csproj index 23bdc397..60685256 100644 --- a/YiSha.Test/YiSha.UtilTest/YiSha.UtilTest.csproj +++ b/YiSha.Test/YiSha.UtilTest/YiSha.UtilTest.csproj @@ -2,17 +2,18 @@ net6.0 - + enable + enable false - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/YiSha.Util/YiSha.CodeGenerator/YiSha.CodeGenerator.csproj b/YiSha.Util/YiSha.CodeGenerator/YiSha.CodeGenerator.csproj index 46a5fc1e..227b6a50 100644 --- a/YiSha.Util/YiSha.CodeGenerator/YiSha.CodeGenerator.csproj +++ b/YiSha.Util/YiSha.CodeGenerator/YiSha.CodeGenerator.csproj @@ -1,13 +1,11 @@ - + - net6.0 + net6.0 + enable + enable - - - - diff --git a/YiSha.Util/YiSha.IdGenerator/YiSha.IdGenerator.csproj b/YiSha.Util/YiSha.IdGenerator/YiSha.IdGenerator.csproj index 065798b6..334dc84d 100644 --- a/YiSha.Util/YiSha.IdGenerator/YiSha.IdGenerator.csproj +++ b/YiSha.Util/YiSha.IdGenerator/YiSha.IdGenerator.csproj @@ -1,7 +1,9 @@  - net6.0 + net6.0 + enable + enable diff --git a/YiSha.Util/YiSha.Util/CaptchaHelper.cs b/YiSha.Util/YiSha.Util/CaptchaHelper.cs index 1e3b7b14..bc42cd11 100644 --- a/YiSha.Util/YiSha.Util/CaptchaHelper.cs +++ b/YiSha.Util/YiSha.Util/CaptchaHelper.cs @@ -12,7 +12,7 @@ public class CaptchaHelper /// Tuple第一个值是表达式,第二个值是表达式结果 /// /// - public static Tuple GetCaptchaCode() + public static Tuple GetCaptchaCode() { int value = 0; char[] operators = { '+', '-', '*' }; @@ -44,7 +44,7 @@ public class CaptchaHelper code = (char)('0' + (char)second); randomCode += code; randomCode += "=?"; - return new Tuple(randomCode, value); + return new Tuple(randomCode, value.ToString()); } #endregion diff --git a/YiSha.Util/YiSha.Util/JsonConverter/JsonDateTime.cs b/YiSha.Util/YiSha.Util/JsonConverter/JsonDateTime.cs new file mode 100644 index 00000000..f4ce6249 --- /dev/null +++ b/YiSha.Util/YiSha.Util/JsonConverter/JsonDateTime.cs @@ -0,0 +1,41 @@ +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace YiSha.Util +{ + /// + /// 时间序列化 + /// + public class JsonDateTime : JsonConverter + { + /// + /// 读取 + /// + /// 读 + /// 类型 + /// 选项 + /// + public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.String) + { + if (DateTime.TryParse(reader.GetString(), out DateTime data)) return data; + } + return reader.GetDateTime(); + } + + /// + /// 写入 + /// + /// 写 + /// 值 + /// 选项 + public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) + { + var zhCN = new CultureInfo("zh-CN");//时区 + var setValue = value.ToString("yyyy-MM-dd HH:mm:ss", zhCN); + writer?.WriteStringValue(setValue); + } + } +} diff --git a/YiSha.Util/YiSha.Util/JsonConverter/JsonHelper.cs b/YiSha.Util/YiSha.Util/JsonConverter/JsonHelper.cs new file mode 100644 index 00000000..3ae8bbbc --- /dev/null +++ b/YiSha.Util/YiSha.Util/JsonConverter/JsonHelper.cs @@ -0,0 +1,29 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using YiSha.Util.Extension; + +namespace YiSha.Util +{ + /// + /// JsonHelper + /// + public static class JsonHelper + { + /// + /// ToObject + /// + public static T ToObject(this string Json) + { + Json = Json.Replace(" ", ""); + return Json == null ? default(T) : JsonConvert.DeserializeObject(Json); + } + + /// + /// ToJObject + /// + public static JObject ToJObject(this string Json) + { + return Json == null ? JObject.Parse("{}") : JObject.Parse(Json.Replace(" ", "")); + } + } +} diff --git a/YiSha.Util/YiSha.Util/JsonConverter/JsonLong.cs b/YiSha.Util/YiSha.Util/JsonConverter/JsonLong.cs new file mode 100644 index 00000000..a5e77047 --- /dev/null +++ b/YiSha.Util/YiSha.Util/JsonConverter/JsonLong.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace YiSha.Util +{ + /// + /// Int64 序列化 + /// + public class JsonLong : JsonConverter + { + public override long Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType == JsonTokenType.String) + { + if (long.TryParse(reader.GetString(), out long data)) return data; + } + return reader.GetInt64(); + } + + public override void Write(Utf8JsonWriter writer, long value, JsonSerializerOptions options) + { + var zhCN = new CultureInfo("zh-CN");//时区 + var setValue = value.ToString(zhCN); + writer?.WriteStringValue(setValue); + } + } +} diff --git a/YiSha.Util/YiSha.Util/JsonHelper.cs b/YiSha.Util/YiSha.Util/JsonHelper.cs deleted file mode 100644 index 355aff1f..00000000 --- a/YiSha.Util/YiSha.Util/JsonHelper.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using YiSha.Util.Extension; - -namespace YiSha.Util -{ - #region JsonHelper - public static class JsonHelper - { - public static T ToObject(this string Json) - { - Json = Json.Replace(" ", ""); - return Json == null ? default(T) : JsonConvert.DeserializeObject(Json); - } - - public static JObject ToJObject(this string Json) - { - return Json == null ? JObject.Parse("{}") : JObject.Parse(Json.Replace(" ", "")); - } - } - #endregion - - #region JsonConverter - /// - /// Json数据返回到前端js的时候,把数值很大的long类型转成字符串 - /// - public class StringJsonConverter : JsonConverter - { - public StringJsonConverter() { } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - return reader.Value.ParseToLong(); - } - - public override bool CanConvert(Type objectType) - { - return true; - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - if (value == null) - { - writer.WriteNull(); - return; - } - string sValue = value.ToString(); - writer.WriteValue(sValue); - } - } - - /// - /// DateTime类型序列化的时候,转成指定的格式 - /// - public class DateTimeJsonConverter : JsonConverter - { - public DateTimeJsonConverter() { } - - public override bool CanConvert(Type objectType) - { - return true; - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - return reader.Value.ParseToString().ParseToDateTime(); - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - if (value == null) - { - writer.WriteNull(); - return; - } - DateTime? dt = value as DateTime?; - if (dt == null) - { - writer.WriteNull(); - return; - } - writer.WriteValue(dt.Value.ToString("yyyy-MM-dd HH:mm:ss")); - } - } - #endregion -} diff --git a/YiSha.Util/YiSha.Util/YiSha.Util.csproj b/YiSha.Util/YiSha.Util/YiSha.Util.csproj index 8d183668..f405d8ff 100644 --- a/YiSha.Util/YiSha.Util/YiSha.Util.csproj +++ b/YiSha.Util/YiSha.Util/YiSha.Util.csproj @@ -1,19 +1,17 @@  - net6.0 + net6.0 + enable + enable - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + diff --git a/YiSha.Web/YiSha.Admin.Web/Controllers/HomeController.cs b/YiSha.Web/YiSha.Admin.Web/Controllers/HomeController.cs index 46d34bc8..e8a95c35 100644 --- a/YiSha.Web/YiSha.Admin.Web/Controllers/HomeController.cs +++ b/YiSha.Web/YiSha.Admin.Web/Controllers/HomeController.cs @@ -1,47 +1,52 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using YiSha.Business.OrganizationManage; using YiSha.Business.SystemManage; +using YiSha.Entity.OrganizationManage; using YiSha.Entity.SystemManage; using YiSha.Enum; -using YiSha.IdGenerator; -using YiSha.Model.Result; +using YiSha.Util; using YiSha.Util.Extension; -using YiSha.Web.Code; using YiSha.Util.Model; -using YiSha.Util; -using YiSha.Entity.OrganizationManage; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; +using YiSha.Web.Code; namespace YiSha.Admin.Web.Controllers { public class HomeController : BaseController { - private MenuBLL menuBLL = new MenuBLL(); - private UserBLL userBLL = new UserBLL(); - private LogLoginBLL logLoginBLL = new LogLoginBLL(); - private MenuAuthorizeBLL menuAuthorizeBLL = new MenuAuthorizeBLL(); + private MenuBLL menuBLL { get; set; } + + private UserBLL userBLL { get; set; } + + private LogLoginBLL logLoginBLL { get; set; } - #region 视图功能 + private MenuAuthorizeBLL menuAuthorizeBLL { get; set; } + + public HomeController() + { + menuBLL = new MenuBLL(); + userBLL = new UserBLL(); + logLoginBLL = new LogLoginBLL(); + menuAuthorizeBLL = new MenuAuthorizeBLL(); + } + + /// + /// Index + /// + /// [HttpGet] [AuthorizeFilter] public async Task Index() { - OperatorInfo operatorInfo = await Operator.Instance.Current(); + var operatorInfo = await Operator.Instance.Current(); - TData> objMenu = await menuBLL.GetList(null); - List menuList = objMenu.Data; + var objMenu = await menuBLL.GetList(); + var menuList = objMenu.Data; menuList = menuList.Where(p => p.MenuStatus == StatusEnum.Yes.ParseToInt()).ToList(); if (operatorInfo.IsSystem != 1) { - TData> objMenuAuthorize = await menuAuthorizeBLL.GetAuthorizeList(operatorInfo); - List authorizeMenuIdList = objMenuAuthorize.Data.Select(p => p.MenuId).ToList(); + var objMenuAuthorize = await menuAuthorizeBLL.GetAuthorizeList(operatorInfo); + var authorizeMenuIdList = objMenuAuthorize.Data.Select(p => p.MenuId).ToList(); menuList = menuList.Where(p => authorizeMenuIdList.Contains(p.Id)).ToList(); } @@ -50,12 +55,20 @@ public async Task Index() return View(); } + /// + /// Welcome + /// + /// [HttpGet] public IActionResult Welcome() { return View(); } + /// + /// Login + /// + /// [HttpGet] public IActionResult Login() { @@ -67,13 +80,18 @@ public IActionResult Login() return View(); } + /// + /// 退出登录 + /// + /// [HttpPost] public async Task LoginOffJson() { - OperatorInfo user = await Operator.Instance.Current(); + var user = await Operator.Instance.Current(); if (user != null) { #region 退出系统 + // 如果不允许同一个用户多次登录,当用户登出的时候,就不在线了 if (!GlobalContext.SystemConfig.LoginMultiple) { @@ -94,10 +112,11 @@ public async Task LoginOffJson() }); Operator.Instance.RemoveCurrent(); - new CookieHelper().RemoveCookie("RememberMe"); + CookieHelper.Remove("RememberMe"); return Json(new TData { Tag = 1 }); - #endregion + + #endregion 退出系统 } else { @@ -105,12 +124,20 @@ public async Task LoginOffJson() } } + /// + /// NoPermission + /// + /// [HttpGet] public IActionResult NoPermission() { return View(); } + /// + /// Error + /// + /// [HttpGet] public IActionResult Error(string message) { @@ -118,51 +145,60 @@ public IActionResult Error(string message) return View(); } + /// + /// Skin + /// + /// [HttpGet] public IActionResult Skin() { return View(); } - #endregion - #region 获取数据 + /// + /// 获取验证码 + /// + /// public IActionResult GetCaptchaImage() { - string sessionId = GlobalContext.ServiceProvider?.GetService().HttpContext.Session.Id; - - Tuple captchaCode = CaptchaHelper.GetCaptchaCode(); - byte[] bytes = CaptchaHelper.CreateCaptchaImage(captchaCode.Item1); - new SessionHelper().WriteSession("CaptchaCode", captchaCode.Item2); + var captchaCode = CaptchaHelper.GetCaptchaCode(); + var bytes = CaptchaHelper.CreateCaptchaImage(captchaCode.Item1); + SessionHelper.Set("CaptchaCode", captchaCode.Item2); return File(bytes, @"image/jpeg"); } - #endregion - #region 提交数据 + /// + /// 登录帐号 + /// + /// 帐号 + /// 密码 + /// 验证码 + /// [HttpPost] public async Task LoginJson(string userName, string password, string captchaCode) { - TData obj = new TData(); + var obj = new TData(); if (string.IsNullOrEmpty(captchaCode)) { obj.Message = "验证码不能为空"; return Json(obj); } - if (captchaCode != new SessionHelper().GetSession("CaptchaCode").ParseToString()) + if (captchaCode != SessionHelper.Get("CaptchaCode").ParseToString()) { obj.Message = "验证码错误,请重新输入"; return Json(obj); } - TData userObj = await userBLL.CheckLogin(userName, password, (int)PlatformEnum.Web); + var userObj = await userBLL.CheckLogin(userName, password, (int)PlatformEnum.Web); if (userObj.Tag == 1) { await new UserBLL().UpdateUser(userObj.Data); await Operator.Instance.AddCurrent(userObj.Data.WebToken); } - string ip = NetHelper.Ip; - string browser = NetHelper.Browser; - string os = NetHelper.GetOSVersion(); - string userAgent = NetHelper.UserAgent; + var ip = NetHelper.Ip; + var browser = NetHelper.Browser; + var os = NetHelper.GetOSVersion(); + var userAgent = NetHelper.UserAgent; Action taskAction = async () => { @@ -189,6 +225,5 @@ public async Task LoginJson(string userName, string password, str obj.Message = userObj.Message; return Json(obj); } - #endregion } } diff --git a/YiSha.Web/YiSha.Admin.Web/DataProtection/key-272b180f-b1fb-42fa-85ce-4778a6075e72.xml b/YiSha.Web/YiSha.Admin.Web/DataProtection/key-272b180f-b1fb-42fa-85ce-4778a6075e72.xml deleted file mode 100644 index c3d689a5..00000000 --- a/YiSha.Web/YiSha.Admin.Web/DataProtection/key-272b180f-b1fb-42fa-85ce-4778a6075e72.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - 2019-10-18T14:33:58.7444058Z - 2019-10-18T14:33:58.7134058Z - 2020-01-16T14:33:58.7134058Z - - - - - - - UCisTh3vXKJDyDrj1MrpH7nEdAII8/LL/LSWbeWV1eNoObF7zigaTvS1Ulh2UZ0hN80YSYOhdr/1kNkKqU7PXg== - - - - \ No newline at end of file diff --git a/YiSha.Web/YiSha.Admin.Web/Filter/AuthorizeFilterAttribute.cs b/YiSha.Web/YiSha.Admin.Web/Filter/AuthorizeFilterAttribute.cs index 886b49cc..c292fefc 100644 --- a/YiSha.Web/YiSha.Admin.Web/Filter/AuthorizeFilterAttribute.cs +++ b/YiSha.Web/YiSha.Admin.Web/Filter/AuthorizeFilterAttribute.cs @@ -38,7 +38,7 @@ public override async Task OnActionExecutionAsync(ActionExecutingContext context if (user == null || user.UserId == 0) { // 防止用户选择记住我,页面一直在首页刷新 - if (new CookieHelper().GetCookie("RememberMe").ParseToInt() == 1) + if (CookieHelper.Get("RememberMe").ParseToInt() == 1) { Operator.Instance.RemoveCurrent(); } diff --git a/YiSha.Web/YiSha.Admin.Web/Program.cs b/YiSha.Web/YiSha.Admin.Web/Program.cs index 5d99b293..1c39f3ac 100644 --- a/YiSha.Web/YiSha.Admin.Web/Program.cs +++ b/YiSha.Web/YiSha.Admin.Web/Program.cs @@ -1,25 +1,175 @@ -using Microsoft.AspNetCore; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.DataProtection; +using Microsoft.Extensions.FileProviders; using NLog.Web; +using System.Text; +using YiSha.Admin.Web.Controllers; +using YiSha.Util; +using YiSha.Util.Model; namespace YiSha.Admin.Web { - public class Program + /// + /// Program + /// + public static class Program { + /// + /// 程序入口 + /// + /// public static void Main(string[] args) { - CreateWebHostBuilder(args).Build().Run(); + var builder = WebApplication.CreateBuilder(args); + builder.Services.ConfigureServices(builder); + builder.Services.AddInjection(builder); + var app = builder.Build(); + app.Configure(builder); + app.Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseUrls("http://*:5000") - .UseStartup() - .ConfigureLogging(logging => - { - logging.ClearProviders(); - logging.SetMinimumLevel(LogLevel.Trace); - }).UseNLog(); + /// + /// 该方法通过运行时调用 + /// 使用此方法将服务添加到容器中 + /// + /// 服务 + /// 网站程序 + public static void ConfigureServices(this IServiceCollection services, WebApplicationBuilder builder) + { + //全局环境变量 + GlobalContext.Services = services; + GlobalContext.Configuration = builder.Configuration; + GlobalContext.HostingEnvironment = builder.Environment; + GlobalContext.SystemConfig = builder.Configuration.GetSection("SystemConfig").Get(); + GlobalContext.LogWhenStart(builder.Environment); + //注册Encoding + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + //日志组件 + builder.WebHost.ConfigureLogging(logging => + { + logging.ClearProviders(); + logging.SetMinimumLevel(LogLevel.Trace); + }).UseNLog(); + //运行模式 + if (builder.Environment.IsDevelopment()) + { + //Razor + services.AddRazorPages().AddRazorRuntimeCompilation(); + } + //Configure + services.Configure(options => + { + // This lambda determines whether user consent for non-essential cookies is needed for a given request. + options.CheckConsentNeeded = context => true; + options.MinimumSameSitePolicy = SameSiteMode.None; + }); + //启用缓存功能 + services.AddMemoryCache(); + //启动数据保护服务 + services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(GlobalContext.HostingEnvironment.ContentRootPath + Path.DirectorySeparatorChar + "DataProtection")); + //启动 Session + services.AddSession(options => + { + options.Cookie.Name = ".AspNetCore.Session";//设置Session在Cookie的Key + options.IdleTimeout = TimeSpan.FromMinutes(20);//设置Session的过期时间 + options.Cookie.HttpOnly = true;//设置在浏览器不能通过js获得该Cookie的值 + options.Cookie.IsEssential = true; + }); + //添加 Options 模式 + services.AddOptions(); + //添加 MVC + services.AddMvc(); + //返回数据首字母不小写 + services.AddMvc().AddJsonOptions(options => + { + //返回数据首字不变 + //PropertyNamingPolicy = null 默认不改变 + //PropertyNamingPolicy = JsonNamingPolicy.CamelCase 默认小写 + //https://docs.microsoft.com/zh-cn/dotnet/api/system.text.json.jsonserializeroptions.propertynamingpolicy?view=net-6.0 + options.JsonSerializerOptions.PropertyNamingPolicy = null; + //数据序列化 + options.JsonSerializerOptions.Converters.Add(new JsonDateTime()); + options.JsonSerializerOptions.Converters.Add(new JsonLong()); + //取消 Unicode 编码 + //options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); + //空值不反回前端 + //options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + //允许额外符号 + //options.JsonSerializerOptions.AllowTrailingCommas = true; + //反序列化过程中属性名称是否使用不区分大小写的比较 + //options.JsonSerializerOptions.PropertyNameCaseInsensitive = false; + }); + //添加 HttpContext 存取器 + services.AddHttpContextAccessor(); + //添加 Options + services.AddOptions(); + //全局异常捕获 + services.AddControllers(options => + { + options.Filters.Add(); + options.ModelMetadataDetailsProviders.Add(new ModelBindingMetadataProvider()); + }); + } + + /// + /// 该方法通过运行时调用 + /// 使用此方法配置HTTP请求流水线 + /// + /// 应用 + /// 网站程序 + public static void Configure(this WebApplication app, WebApplicationBuilder builder) + { + //全局环境变量 + GlobalContext.ServiceProvider = app.Services; + GlobalContext.Configuration = app.Configuration; + GlobalContext.HostingEnvironment = app.Environment; + //让 Pathbase 中间件成为第一个处理请求的中间件, 才能正确的模拟虚拟路径 + if (!string.IsNullOrEmpty(GlobalContext.SystemConfig.VirtualDirectory)) + { + app.UsePathBase(new PathString(GlobalContext.SystemConfig.VirtualDirectory)); + } + //运行模式 + if (app.Environment.IsDevelopment()) + { + GlobalContext.SystemConfig.Debug = true; + //开发环境展示错误堆栈页 + app.UseDeveloperExceptionPage(); + } + else + { + //正式环境自定义错误页 + app.UseExceptionHandler("/Help/Error"); + } + //默认的静态目录路径 + app.UseStaticFiles(); + //用户自定义静态目录 + string resource = Path.Combine(app.Environment.ContentRootPath, "Resource"); + if (!Directory.Exists(resource)) Directory.CreateDirectory(resource); + app.UseStaticFiles(new StaticFileOptions + { + RequestPath = "/Resource", + FileProvider = new PhysicalFileProvider(resource), + OnPrepareResponse = GlobalContext.SetCacheControl, + }); + //用户路由 + app.UseRouting(); + //用户 Session + app.UseSession(); + //用户默认路由 + app.MapControllerRoute( + name: "areaRoute", + pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); + app.MapControllerRoute( + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}"); + } + + /// + /// 依赖注入 + /// + /// 服务 + /// 网站程序 + public static void AddInjection(this IServiceCollection services, WebApplicationBuilder builder) + { + } } } diff --git a/YiSha.Web/YiSha.Admin.Web/Startup.cs b/YiSha.Web/YiSha.Admin.Web/Startup.cs deleted file mode 100644 index eb28b0c1..00000000 --- a/YiSha.Web/YiSha.Admin.Web/Startup.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using System.Text; -using System.Text.Encodings.Web; -using System.Text.Unicode; -using Newtonsoft.Json.Serialization; -using Microsoft.Extensions.FileProviders; -using Microsoft.AspNetCore.DataProtection; -using Microsoft.Extensions.Hosting; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using YiSha.Util; -using YiSha.Util.Model; -using YiSha.Admin.Web.Controllers; -using Microsoft.Extensions.Logging; - -namespace YiSha.Admin.Web -{ - public class Startup - { - public IConfiguration Configuration { get; } - public IWebHostEnvironment WebHostEnvironment { get; set; } - - public Startup(IConfiguration configuration, IWebHostEnvironment env) - { - Configuration = configuration; - WebHostEnvironment = env; - GlobalContext.LogWhenStart(env); - GlobalContext.HostingEnvironment = env; - } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - if (WebHostEnvironment.IsDevelopment()) - { - services.AddRazorPages().AddRazorRuntimeCompilation(); - } - services.Configure(options => - { - // This lambda determines whether user consent for non-essential cookies is needed for a given request. - options.CheckConsentNeeded = context => true; - options.MinimumSameSitePolicy = SameSiteMode.None; - }); - - services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All)); - services.AddControllersWithViews(options => - { - options.Filters.Add(); - options.ModelMetadataDetailsProviders.Add(new ModelBindingMetadataProvider()); - }).AddNewtonsoftJson(options => - { - // 返回数据首字母不小写,CamelCasePropertyNamesContractResolver是小写 - options.SerializerSettings.ContractResolver = new DefaultContractResolver(); - }); - - services.AddMemoryCache(); - services.AddSession(); - services.AddHttpContextAccessor(); - - services.AddOptions(); - - services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(GlobalContext.HostingEnvironment.ContentRootPath + Path.DirectorySeparatorChar + "DataProtection")); - - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // 注册Encoding - - GlobalContext.SystemConfig = Configuration.GetSection("SystemConfig").Get(); - GlobalContext.Services = services; - GlobalContext.Configuration = Configuration; - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (!string.IsNullOrEmpty(GlobalContext.SystemConfig.VirtualDirectory)) - { - app.UsePathBase(new PathString(GlobalContext.SystemConfig.VirtualDirectory)); // 让 Pathbase 中间件成为第一个处理请求的中间件, 才能正确的模拟虚拟路径 - } - if (WebHostEnvironment.IsDevelopment()) - { - GlobalContext.SystemConfig.Debug = true; - app.UseDeveloperExceptionPage(); - } - else - { - app.UseExceptionHandler("/Home/Error"); - } - - string resource = Path.Combine(env.ContentRootPath, "Resource"); - FileHelper.CreateDirectory(resource); - - app.UseStaticFiles(new StaticFileOptions - { - OnPrepareResponse = GlobalContext.SetCacheControl - }); - app.UseStaticFiles(new StaticFileOptions - { - RequestPath = "/Resource", - FileProvider = new PhysicalFileProvider(resource), - OnPrepareResponse = GlobalContext.SetCacheControl - }); - app.UseSession(); - app.UseRouting(); - app.UseEndpoints(endpoints => - { - endpoints.MapControllerRoute("areas", "{area:exists}/{controller=Home}/{action=Index}/{id?}"); - endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); - }); - GlobalContext.ServiceProvider = app.ApplicationServices; - } - } -} diff --git a/YiSha.Web/YiSha.Admin.Web/Views/Home/Welcome.cshtml b/YiSha.Web/YiSha.Admin.Web/Views/Home/Welcome.cshtml index fb0722a8..5451f639 100644 --- a/YiSha.Web/YiSha.Admin.Web/Views/Home/Welcome.cshtml +++ b/YiSha.Web/YiSha.Admin.Web/Views/Home/Welcome.cshtml @@ -1,7 +1,6 @@ @{ Layout = "~/Views/Shared/_FormGray.cshtml"; } -
@@ -24,7 +23,7 @@
-
+
框架介绍
@@ -42,25 +41,22 @@

YiShaAdmin 借鉴了很多开源项目的优点,让你开发Web管理系统和移动端Api更简单,所以我也把她开源了(前端CSS样式主要参考若依,在此表示感谢 :)。
- 她适用于开发 网站管理后台CMSCRMERPOA 这类的系统和开发移动端Api
+ 她适用于开发 网站管理后台CMSCRMERPOA 这类的系统和开发移动端Api
代码完全免费开源,易读易懂、界面简洁美观,给你的项目多一种选择与参考。

当前版本:@YiSha.Util.GlobalContext.GetVersion()   ¥免费开源

-

- - 访问 github - - @* - 访问主页 - *@ + QQ群:满 428703155 851661600 +

+

+ GitHub:https://github.com/liukuo362573/YiShaAdmin

-
+
技术选型
@@ -83,92 +79,7 @@
-
- -
-
-
-
-
联系信息
-
- - - - -
-
-
- @*

- 官网: -

*@ -

- QQ群:满 428703155 851661600 -

-
-
-
-
-
-
-
更新日志
-
- - -
-
-
-
-
-
-
-
- v3.1.02020.02.20 -
-
-
-
-
    -
  1. 1. 框架由.NET Core 2.2升级到.NET Core 3.1
  2. -
  3. 2. 导入文件支持xlsx格式
  4. -
  5. 3. 菜单支持打开外部链接
  6. -
  7. 4. 修复读取cookie样式bug
  8. -
  9. 5. 部门和用户的数据权限修改,只能看到自己及以下
  10. -
  11. 6. 菜单新增或编辑之后,显示对应的数据
  12. -
  13. 7. 定时任务支持暂停和更新任务周期
  14. -
  15. 8. 数据库和实体之间映射约定修改
  16. -
  17. 9. 支持移动端
  18. -
-
-
-
-
-
-
- v2.2.02019.09.27 -
-
-
-
-
    -
  1. 1. 正式开源YiShaAdmin 2.2
  2. -
  3. 2. 代码自动生成的时候,根据配置,生成对应菜单
  4. -
  5. 3. 修复bootstrap tree table的expandFirst为true,tree展开的问题
  6. -
  7. 4. 修复头像上传报错
  8. -
  9. 5. 增加多个基类实体,根据业务按需继承
  10. -
  11. 6. 调整项目文件结构,使代码结构更加清晰
  12. -
  13. 7. 增加NUnit测试项目
  14. -
  15. 8. 增加常用的前端组件示例
  16. -
  17. 9. 增加用户导入示例
  18. -
-
-
-
-
-
-
-
-
-
+
捐赠
diff --git a/YiSha.Web/YiSha.Admin.Web/YiSha.Admin.Web.csproj b/YiSha.Web/YiSha.Admin.Web/YiSha.Admin.Web.csproj index da6f49a0..93fd6e53 100644 --- a/YiSha.Web/YiSha.Admin.Web/YiSha.Admin.Web.csproj +++ b/YiSha.Web/YiSha.Admin.Web/YiSha.Admin.Web.csproj @@ -2,13 +2,12 @@ net6.0 - 6.0.0.0 - 6.0.0.0 - YiSha.Admin.Web - YiSha.Admin.Web - YiShaAdmin - YiShaAdmin + enable + enable + False en + 6.1.0.0 + 6.1.0.0 @@ -18,9 +17,8 @@ - - - + + diff --git a/YiSha.Web/YiSha.Admin.Web/appsettings.json b/YiSha.Web/YiSha.Admin.Web/appsettings.json index b2984a98..1b2c7766 100644 --- a/YiSha.Web/YiSha.Admin.Web/appsettings.json +++ b/YiSha.Web/YiSha.Admin.Web/appsettings.json @@ -5,20 +5,20 @@ } }, "AllowedHosts": "*", - "SystemConfig": { - "Demo": false, // 是否是演示模式 - "LoginMultiple": true, // 是否允许一个账户在多处登录 - "LoginProvider": "Cookie", // 登录信息保存方式 Cookie Session WebApi - "SnowFlakeWorkerId": 1, // SnowFlake 节点序号 - "ApiSite": "http://localhost:5001", // Api地址,例如可以上传文件到Api - "VirtualDirectory": "/admin", // 虚拟目录 - - "DBProvider": "MySql", - "DBConnectionString": "server=localhost;database=YiShaAdmin;user=root;password=123456;port=3306;pooling=true;max pool size=20;persist security info=True;charset=utf8mb4;", - "DBCommandTimeout": 180, // 数据库超时时间,单位秒 - "DBBackup": "", // 数据库备份路径 - - "CacheProvider": "Memory", // 缓存使用方式 Memory Redis - "RedisConnectionString": "127.0.0.1:6379" - } + "SystemConfig": { + "Demo": false, // 是否是演示模式 + "LoginMultiple": true, // 是否允许一个账户在多处登录 + "LoginProvider": "Cookie", // 登录信息保存方式 Cookie Session WebApi + "SnowFlakeWorkerId": 1, // SnowFlake 节点序号 + "ApiSite": "http://localhost:5001", // Api地址,例如可以上传文件到Api + "VirtualDirectory": "/admin", // 虚拟目录 + + "DBProvider": "MySql", + "DBConnectionString": "server=localhost;database=YiShaAdmin;user=root;password=root;port=3306;pooling=true;max pool size=20;persist security info=True;charset=utf8mb4;", + "DBCommandTimeout": 180, // 数据库超时时间,单位秒 + "DBBackup": "", // 数据库备份路径 + + "CacheProvider": "Memory", // 缓存使用方式 Memory Redis + "RedisConnectionString": "127.0.0.1:6379" + } } diff --git a/YiSha.Web/YiSha.Admin.WebApi/Controllers/DataDictController.cs b/YiSha.Web/YiSha.Admin.WebApi/Controllers/DataDictController.cs index 90f1581f..128d9a1f 100644 --- a/YiSha.Web/YiSha.Admin.WebApi/Controllers/DataDictController.cs +++ b/YiSha.Web/YiSha.Admin.WebApi/Controllers/DataDictController.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; +using YiSha.Admin.WebApi.Filter; using YiSha.Business.SystemManage; using YiSha.Model.Param.SystemManage; using YiSha.Model.Result.SystemManage; @@ -19,18 +15,20 @@ public class DataDictController : ControllerBase private DataDictBLL dataDictBLL = new DataDictBLL(); #region 获取数据 + /// /// 获取数据字典列表 /// /// /// [HttpGet] - public async Task>> GetList([FromQuery]DataDictListParam param) + public async Task>> GetList([FromQuery] DataDictListParam param) { TData> obj = await dataDictBLL.GetDataDictList(); obj.Tag = 1; return obj; } - #endregion + + #endregion 获取数据 } -} \ No newline at end of file +} diff --git a/YiSha.Web/YiSha.Admin.WebApi/Controllers/FileController.cs b/YiSha.Web/YiSha.Admin.WebApi/Controllers/FileController.cs index ab0a17c0..7966dce9 100644 --- a/YiSha.Web/YiSha.Admin.WebApi/Controllers/FileController.cs +++ b/YiSha.Web/YiSha.Admin.WebApi/Controllers/FileController.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; +using YiSha.Admin.WebApi.Filter; using YiSha.Util; -using YiSha.Util.Extension; using YiSha.Util.Model; namespace YiSha.Admin.WebApi.Controllers @@ -17,24 +11,29 @@ namespace YiSha.Admin.WebApi.Controllers public class FileController : ControllerBase { #region 上传单个文件 + [HttpPost] public async Task> UploadFile(int fileModule, IFormCollection fileList) { TData obj = await FileHelper.UploadFile(fileModule, fileList.Files); return obj; } - #endregion + + #endregion 上传单个文件 #region 删除单个文件 + [HttpPost] public TData DeleteFile(int fileModule, string filePath) { TData obj = FileHelper.DeleteFile(fileModule, filePath); return obj; } - #endregion + + #endregion 删除单个文件 #region 下载文件 + [HttpGet] public FileContentResult DownloadFile(string filePath, int delete = 1) { @@ -48,6 +47,7 @@ public FileContentResult DownloadFile(string filePath, int delete = 1) throw new Exception("下载失败:" + obj.Message); } } - #endregion + + #endregion 下载文件 } -} \ No newline at end of file +} diff --git a/YiSha.Web/YiSha.Admin.WebApi/Controllers/NewsController.cs b/YiSha.Web/YiSha.Admin.WebApi/Controllers/NewsController.cs index 2b797c8a..3c8286f5 100644 --- a/YiSha.Web/YiSha.Admin.WebApi/Controllers/NewsController.cs +++ b/YiSha.Web/YiSha.Admin.WebApi/Controllers/NewsController.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; +using YiSha.Admin.WebApi.Filter; using YiSha.Business.OrganizationManage; using YiSha.Entity.OrganizationManage; using YiSha.Model.Param; @@ -20,6 +16,7 @@ public class NewsController : ControllerBase private NewsBLL newsBLL = new NewsBLL(); #region 获取数据 + /// /// 获取文章列表 /// @@ -40,7 +37,7 @@ public async Task>> GetPageList([FromQuery] NewsListParam /// /// [HttpGet] - public async Task>> GetPageContentList([FromQuery]NewsListParam param, [FromQuery]Pagination pagination) + public async Task>> GetPageContentList([FromQuery] NewsListParam param, [FromQuery] Pagination pagination) { TData> obj = await newsBLL.GetPageContentList(param, pagination); return obj; @@ -52,28 +49,30 @@ public async Task>> GetPageContentList([FromQuery]NewsLis /// /// [HttpGet] - public async Task> GetForm([FromQuery]long id) + public async Task> GetForm([FromQuery] long id) { TData obj = await newsBLL.GetEntity(id); return obj; } - #endregion + + #endregion 获取数据 #region 提交数据 + /// /// 保存文章 /// /// /// [HttpPost] - public async Task> SaveForm([FromBody]NewsEntity entity) + public async Task> SaveForm([FromBody] NewsEntity entity) { TData obj = await newsBLL.SaveForm(entity); return obj; } [HttpPost] - public async Task> SaveViewTimes([FromBody]IdParam param) + public async Task> SaveViewTimes([FromBody] IdParam param) { TData obj = null; TData objNews = await newsBLL.GetEntity(param.Id.Value); @@ -92,6 +91,7 @@ public async Task> SaveViewTimes([FromBody]IdParam param) } return obj; } - #endregion + + #endregion 提交数据 } -} \ No newline at end of file +} diff --git a/YiSha.Web/YiSha.Admin.WebApi/Controllers/UserController.cs b/YiSha.Web/YiSha.Admin.WebApi/Controllers/UserController.cs index 804df009..5eba7ecc 100644 --- a/YiSha.Web/YiSha.Admin.WebApi/Controllers/UserController.cs +++ b/YiSha.Web/YiSha.Admin.WebApi/Controllers/UserController.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; +using YiSha.Admin.WebApi.Filter; using YiSha.Business.OrganizationManage; using YiSha.Entity.OrganizationManage; using YiSha.Enum; -using YiSha.Model.Result.SystemManage; -using YiSha.Util; using YiSha.Util.Model; using YiSha.Web.Code; @@ -21,10 +15,10 @@ public class UserController : ControllerBase { private UserBLL userBLL = new UserBLL(); - #region 获取数据 - #endregion + #region 提交数据 + /// /// 用户登录 /// @@ -60,6 +54,7 @@ public TData LoginOff([FromQuery] string token) obj.Message = "登出成功"; return obj; } - #endregion + + #endregion 提交数据 } -} \ No newline at end of file +} diff --git a/YiSha.Web/YiSha.Admin.WebApi/Filter/AuthorizeFilterAttribute.cs b/YiSha.Web/YiSha.Admin.WebApi/Filter/AuthorizeFilterAttribute.cs index 22ca1c6f..8b4629c7 100644 --- a/YiSha.Web/YiSha.Admin.WebApi/Filter/AuthorizeFilterAttribute.cs +++ b/YiSha.Web/YiSha.Admin.WebApi/Filter/AuthorizeFilterAttribute.cs @@ -1,23 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using System.Reflection; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Newtonsoft.Json; +using System.Diagnostics; +using System.Reflection; +using System.Text; using YiSha.Business.SystemManage; using YiSha.Entity.SystemManage; using YiSha.Enum; using YiSha.Util; using YiSha.Util.Extension; -using YiSha.Util.Model; using YiSha.Web.Code; -namespace YiSha.Admin.WebApi.Controllers +namespace YiSha.Admin.WebApi.Filter { /// /// 验证token和记录日志 @@ -72,11 +66,13 @@ public override async Task OnActionExecutionAsync(ActionExecutingContext context sw.Stop(); #region 保存日志 + LogApiEntity logApiEntity = new LogApiEntity(); logApiEntity.ExecuteUrl = context.HttpContext.Request.Path; logApiEntity.LogStatus = OperateStatusEnum.Success.ParseToInt(); #region 获取Post参数 + switch (context.HttpContext.Request.Method.ToUpper()) { case "GET": @@ -95,11 +91,13 @@ public override async Task OnActionExecutionAsync(ActionExecutingContext context } break; } - #endregion + + #endregion 获取Post参数 if (resultContext.Exception != null) { #region 异常获取 + StringBuilder sbException = new StringBuilder(); Exception exception = resultContext.Exception; sbException.AppendLine(exception.Message); @@ -109,7 +107,8 @@ public override async Task OnActionExecutionAsync(ActionExecutingContext context exception = exception.InnerException; } sbException.AppendLine(TextHelper.GetSubString(resultContext.Exception.StackTrace, 8000)); - #endregion + + #endregion 异常获取 logApiEntity.ExecuteResult = sbException.ToString(); logApiEntity.LogStatus = OperateStatusEnum.Fail.ParseToInt(); @@ -139,7 +138,8 @@ public override async Task OnActionExecutionAsync(ActionExecutingContext context await new LogApiBLL().SaveForm(logApiEntity); }; AsyncTaskHelper.StartTask(taskAction); - #endregion + + #endregion 保存日志 } } } diff --git a/YiSha.Web/YiSha.Admin.WebApi/Filter/GlobalExceptionFilter.cs b/YiSha.Web/YiSha.Admin.WebApi/Filter/GlobalExceptionFilter.cs new file mode 100644 index 00000000..bc722cd5 --- /dev/null +++ b/YiSha.Web/YiSha.Admin.WebApi/Filter/GlobalExceptionFilter.cs @@ -0,0 +1,46 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; +using System.Web; +using YiSha.Util; +using YiSha.Util.Extension; +using YiSha.Util.Model; + +namespace YiSha.Admin.WebApi.Filter +{ + /// + /// 全局异常过滤器 + /// + public class GlobalExceptionFilter : IExceptionFilter, IAsyncExceptionFilter + { + public void OnException(ExceptionContext context) + { + LogHelper.Error(context.Exception); + if (context.HttpContext.Request.IsAjaxRequest()) + { + TData obj = new TData(); + obj.Message = context.Exception.GetOriginalException().Message; + if (string.IsNullOrEmpty(obj.Message)) + { + obj.Message = "抱歉,系统错误,请联系管理员!"; + } + context.Result = new JsonResult(obj); + context.ExceptionHandled = true; + } + else + { + string errorMessage = context.Exception.GetOriginalException().Message; + context.Result = new RedirectResult("~/Home/Error?message=" + HttpUtility.UrlEncode(errorMessage)); + context.ExceptionHandled = true; + } + } + + public Task OnExceptionAsync(ExceptionContext context) + { + if (GlobalContext.HostingEnvironment.IsProduction()) + { + OnException(context); + } + return Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/YiSha.Web/YiSha.Admin.WebApi/Filter/GlobalExceptionMiddleware.cs b/YiSha.Web/YiSha.Admin.WebApi/Filter/GlobalExceptionMiddleware.cs index e769954d..1f35ce99 100644 --- a/YiSha.Web/YiSha.Admin.WebApi/Filter/GlobalExceptionMiddleware.cs +++ b/YiSha.Web/YiSha.Admin.WebApi/Filter/GlobalExceptionMiddleware.cs @@ -1,13 +1,8 @@ -using Microsoft.AspNetCore.Http; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; +using Newtonsoft.Json; using System.Net; -using System.Threading.Tasks; using YiSha.Util.Model; -namespace YiSha.Admin.WebApi.Controllers +namespace YiSha.Admin.WebApi.Filter { public class GlobalExceptionMiddleware { diff --git a/YiSha.Web/YiSha.Admin.WebApi/Program.cs b/YiSha.Web/YiSha.Admin.WebApi/Program.cs index 235a1065..bca46d84 100644 --- a/YiSha.Web/YiSha.Admin.WebApi/Program.cs +++ b/YiSha.Web/YiSha.Admin.WebApi/Program.cs @@ -1,25 +1,204 @@ -using Microsoft.AspNetCore; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.DataProtection; +using Microsoft.Extensions.FileProviders; using NLog.Web; +using Swashbuckle.AspNetCore.SwaggerUI; +using System.Text; +using YiSha.Admin.WebApi.Filter; +using YiSha.Business.AutoJob; +using YiSha.Util; +using YiSha.Util.Model; namespace YiSha.Admin.WebApi { - public class Program + /// + /// Program + /// + public static class Program { + /// + /// 程序入口 + /// + /// public static void Main(string[] args) { - CreateWebHostBuilder(args).Build().Run(); + var builder = WebApplication.CreateBuilder(args); + builder.Services.ConfigureServices(builder); + builder.Services.AddInjection(builder); + var app = builder.Build(); + app.Configure(builder); + app.Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseUrls("http://*:5001") - .UseStartup() - .ConfigureLogging(logging => - { - logging.ClearProviders(); - logging.SetMinimumLevel(LogLevel.Trace); - }).UseNLog(); + /// + /// 该方法通过运行时调用 + /// 使用此方法将服务添加到容器中 + /// + /// 服务 + /// 网站程序 + public static void ConfigureServices(this IServiceCollection services, WebApplicationBuilder builder) + { + //全局环境变量 + GlobalContext.Services = services; + GlobalContext.Configuration = builder.Configuration; + GlobalContext.HostingEnvironment = builder.Environment; + GlobalContext.SystemConfig = builder.Configuration.GetSection("SystemConfig").Get(); + GlobalContext.LogWhenStart(builder.Environment); + //注册 Encoding + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + //跨域支持 + builder.Services.AddCors(option => + { + option.AddPolicy( + name: "policyCors", + builde => + { + builde + .WithOrigins("*", "*", "*") + .AllowAnyOrigin() + .AllowAnyHeader() + .AllowAnyMethod(); + }); + }); + //日志组件 + builder.WebHost.ConfigureLogging(logging => + { + logging.ClearProviders(); + logging.SetMinimumLevel(LogLevel.Trace); + }).UseNLog(); + //Swagger + services.AddSwaggerGen(options => + { + ////文档 + //options.SwaggerDoc("v1", new OpenApiInfo + //{ + // Title = "YiSha Api", + // Version = "v1", + // //Description = "YiSha Api", + //}); + //排序接口 + //options.OrderActionsBy(o => o.RelativePath); + //显示注释 + var path = typeof(Program).Assembly.Location; + var basePath = Path.GetDirectoryName(path); + var xmlFilesPath = Directory.GetFiles(basePath ?? "", "*.xml"); + foreach (var xmlPath in xmlFilesPath) + { + options.IncludeXmlComments(xmlPath, true); + } + }); + //启用缓存功能 + services.AddMemoryCache(); + //启动数据保护服务 + services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(GlobalContext.HostingEnvironment.ContentRootPath + Path.DirectorySeparatorChar + "DataProtection")); + //添加 Options 模式 + services.AddOptions(); + //返回数据首字母不小写 + services.AddControllers().AddJsonOptions(options => + { + //返回数据首字不变 + //PropertyNamingPolicy = null 默认不改变 + //PropertyNamingPolicy = JsonNamingPolicy.CamelCase 默认小写 + //https://docs.microsoft.com/zh-cn/dotnet/api/system.text.json.jsonserializeroptions.propertynamingpolicy?view=net-6.0 + options.JsonSerializerOptions.PropertyNamingPolicy = null; + //取消 Unicode 编码 + //options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); + //空值不反回前端 + //options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + //允许额外符号 + //options.JsonSerializerOptions.AllowTrailingCommas = true; + //反序列化过程中属性名称是否使用不区分大小写的比较 + //options.JsonSerializerOptions.PropertyNameCaseInsensitive = false; + }); + //添加 Options + services.AddOptions(); + //全局异常捕获 + services.AddControllers(options => + { + options.Filters.Add(); + options.ModelMetadataDetailsProviders.Add(new ModelBindingMetadataProvider()); + }); + } + + /// + /// 该方法通过运行时调用 + /// 使用此方法配置HTTP请求流水线 + /// + /// 应用 + /// 网站程序 + public static void Configure(this WebApplication app, WebApplicationBuilder builder) + { + //全局环境变量 + GlobalContext.ServiceProvider = app.Services; + GlobalContext.Configuration = app.Configuration; + GlobalContext.HostingEnvironment = app.Environment; + // + if (!string.IsNullOrEmpty(GlobalContext.SystemConfig.VirtualDirectory)) + { + //让 Pathbase 中间件成为第一个处理请求的中间件, 才能正确的模拟虚拟路径 + app.UsePathBase(new PathString(GlobalContext.SystemConfig.VirtualDirectory)); + } + //跨域支持 + app.UseCors("policyCors"); + //运行模式 + if (app.Environment.IsDevelopment()) + { + GlobalContext.SystemConfig.Debug = true; + //开发环境展示错误堆栈页 + app.UseDeveloperExceptionPage(); + //定时任务 + new JobCenter().Start(); + //Swagger + app.UseSwagger(); + app.UseSwaggerUI(options => + { + //默认地址 + options.RoutePrefix = "swagger"; + //修改界面打开时自动展开 + options.DocExpansion(DocExpansion.List); + //隐藏底部的 Schemas + options.DefaultModelsExpandDepth(-1); + //展开请求详情的 Schema + options.DefaultModelExpandDepth(int.MaxValue); + }); + } + else + { + //正式环境自定义错误页 + app.UseExceptionHandler("/Help/Error"); + } + //默认的静态目录路径 + app.UseStaticFiles(); + //用户自定义静态目录 + string resource = Path.Combine(app.Environment.ContentRootPath, "Resource"); + if (!Directory.Exists(resource)) Directory.CreateDirectory(resource); + app.UseStaticFiles(new StaticFileOptions + { + RequestPath = "/Resource", + FileProvider = new PhysicalFileProvider(resource), + OnPrepareResponse = GlobalContext.SetCacheControl, + }); + // + app.UseMiddleware(typeof(GlobalExceptionMiddleware)); + // + app.UseCors(builder => + { + builder.WithOrigins(GlobalContext.SystemConfig.AllowCorsSite.Split(',')).AllowAnyHeader().AllowAnyMethod().AllowCredentials(); + }); + //用户路由 + app.UseRouting(); + //用户默认路由 + app.MapControllerRoute( + name: "default", + pattern: "{controller=ApiHome}/{action=Index}/{id?}"); + } + + /// + /// 依赖注入 + /// + /// 服务 + /// 网站程序 + public static void AddInjection(this IServiceCollection services, WebApplicationBuilder builder) + { + } } } diff --git a/YiSha.Web/YiSha.Admin.WebApi/Properties/launchSettings.json b/YiSha.Web/YiSha.Admin.WebApi/Properties/launchSettings.json index f459d844..1f0ed503 100644 --- a/YiSha.Web/YiSha.Admin.WebApi/Properties/launchSettings.json +++ b/YiSha.Web/YiSha.Admin.WebApi/Properties/launchSettings.json @@ -12,11 +12,11 @@ "YiSha.Admin.WebApi": { "commandName": "Project", "launchBrowser": true, - "launchUrl": "api-doc", + "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "applicationUrl": "http://localhost:5001" } } -} \ No newline at end of file +} diff --git a/YiSha.Web/YiSha.Admin.WebApi/Startup.cs b/YiSha.Web/YiSha.Admin.WebApi/Startup.cs deleted file mode 100644 index 855da02f..00000000 --- a/YiSha.Web/YiSha.Admin.WebApi/Startup.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System.Text; -using System.IO; -using Newtonsoft.Json.Serialization; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.FileProviders; -using Microsoft.AspNetCore.DataProtection; -using Microsoft.Extensions.Hosting; -using Microsoft.OpenApi.Models; -using System; -using System.Reflection; -using YiSha.Util; -using YiSha.Util.Model; -using YiSha.Business.AutoJob; -using YiSha.Admin.WebApi.Controllers; - -namespace YiSha.Admin.WebApi -{ - public class Startup - { - public IConfiguration Configuration { get; } - - public Startup(IConfiguration configuration, IWebHostEnvironment env) - { - Configuration = configuration; - GlobalContext.LogWhenStart(env); - GlobalContext.HostingEnvironment = env; - } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddSwaggerGen(options => - { - var xmlPath = Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"); - options.SwaggerDoc("v1", new OpenApiInfo { Title = "YiSha Api", Version = "v1" }); - options.IncludeXmlComments(xmlPath, true); - }); - - services.AddOptions(); - services.AddCors(); - services.AddControllers(options => - { - options.ModelMetadataDetailsProviders.Add(new ModelBindingMetadataProvider()); - }).AddNewtonsoftJson(options => - { - // 返回数据首字母不小写,CamelCasePropertyNamesContractResolver是小写 - options.SerializerSettings.ContractResolver = new DefaultContractResolver(); - }); - - services.AddMemoryCache(); - - services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(GlobalContext.HostingEnvironment.ContentRootPath + Path.DirectorySeparatorChar + "DataProtection")); - - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // 注册Encoding - - GlobalContext.SystemConfig = Configuration.GetSection("SystemConfig").Get(); - GlobalContext.Services = services; - GlobalContext.Configuration = Configuration; - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - GlobalContext.SystemConfig.Debug = true; - app.UseDeveloperExceptionPage(); - } - else - { - app.UseDeveloperExceptionPage(); - } - - string resource = Path.Combine(env.ContentRootPath, "Resource"); - FileHelper.CreateDirectory(resource); - - app.UseStaticFiles(new StaticFileOptions - { - OnPrepareResponse = GlobalContext.SetCacheControl - }); - app.UseStaticFiles(new StaticFileOptions - { - RequestPath = "/Resource", - FileProvider = new PhysicalFileProvider(resource), - OnPrepareResponse = GlobalContext.SetCacheControl - }); - - app.UseMiddleware(typeof(GlobalExceptionMiddleware)); - - app.UseCors(builder => - { - builder.WithOrigins(GlobalContext.SystemConfig.AllowCorsSite.Split(',')).AllowAnyHeader().AllowAnyMethod().AllowCredentials(); - }); - app.UseSwagger(c => - { - c.RouteTemplate = "api-doc/{documentName}/swagger.json"; - }); - app.UseSwaggerUI(c => - { - c.RoutePrefix = "api-doc"; - c.SwaggerEndpoint("v1/swagger.json", "YiSha Api v1"); - }); - app.UseRouting(); - app.UseEndpoints(endpoints => - { - endpoints.MapControllerRoute("default", "{controller=ApiHome}/{action=Index}/{id?}"); - }); - GlobalContext.ServiceProvider = app.ApplicationServices; - if (!GlobalContext.SystemConfig.Debug) - { - new JobCenter().Start(); // 定时任务 - } - } - } -} \ No newline at end of file diff --git a/YiSha.Web/YiSha.Admin.WebApi/YiSha.Admin.WebApi.csproj b/YiSha.Web/YiSha.Admin.WebApi/YiSha.Admin.WebApi.csproj index 7830bfdd..3059be9f 100644 --- a/YiSha.Web/YiSha.Admin.WebApi/YiSha.Admin.WebApi.csproj +++ b/YiSha.Web/YiSha.Admin.WebApi/YiSha.Admin.WebApi.csproj @@ -2,13 +2,10 @@ net6.0 - 6.0.0.0 - 6.0.0.0 - YiShaAdmin - - - - YiSha.Admin.WebApi.xml + enable + enable + True + False @@ -18,7 +15,7 @@ - + diff --git a/YiSha.Web/YiSha.Admin.WebApi/YiSha.Admin.WebApi.xml b/YiSha.Web/YiSha.Admin.WebApi/YiSha.Admin.WebApi.xml deleted file mode 100644 index c6deff5f..00000000 --- a/YiSha.Web/YiSha.Admin.WebApi/YiSha.Admin.WebApi.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - YiSha.Admin.WebApi - - - - - 获取数据字典列表 - - - - - - - 获取文章列表 - - - - - - - - 获取文章列表 - - - - - - - - 获取文章内容 - - - - - - - 保存文章 - - - - - - - 用户登录 - - - - - - - - 用户退出登录 - - - - - - - 验证token和记录日志 - - - - - 忽略token的方法 - - - - - 异步接口日志 - - - - - - - diff --git a/YiSha.Web/YiSha.Admin.WebApi/appsettings.json b/YiSha.Web/YiSha.Admin.WebApi/appsettings.json index 9477ecb4..32fa20c2 100644 --- a/YiSha.Web/YiSha.Admin.WebApi/appsettings.json +++ b/YiSha.Web/YiSha.Admin.WebApi/appsettings.json @@ -1,23 +1,23 @@ { - "Logging": { - "LogLevel": { - "Default": "Debug", // Trace,Debug,Information,Warning,Error,Critical - "System": "Information", - "Microsoft": "Information" - } - }, - "AllowedHosts": "*", - "SystemConfig": { - "LoginProvider": "WebApi", // 登录信息保存方式 Cookie Session WebApi - "SnowFlakeWorkerId": 2, // SnowFlake 节点序号 - "AllowCorsSite": "http://localhost:5000", // 允许的其他站点访问Api - - "DBProvider": "MySql", - "DBConnectionString": "server=localhost;database=YiShaAdmin;user=root;password=123456;port=3306;pooling=true;max pool size=20;persist security info=True;charset=utf8mb4;", - "DBCommandTimeout": 180, // 数据库超时时间,单位秒 - "DBBackup": "", // 数据库备份路径 - - "CacheProvider": "Memory", // 缓存使用方式 Memory Redis - "RedisConnectionString": "127.0.0.1:6379" + "Logging": { + "LogLevel": { + "Default": "Debug", // Trace,Debug,Information,Warning,Error,Critical + "System": "Information", + "Microsoft": "Information" } + }, + "AllowedHosts": "*", + "SystemConfig": { + "LoginProvider": "WebApi", // 登录信息保存方式 Cookie Session WebApi + "SnowFlakeWorkerId": 2, // SnowFlake 节点序号 + "AllowCorsSite": "http://localhost:5000", // 允许的其他站点访问Api + + "DBProvider": "MySql", + "DBConnectionString": "server=localhost;database=YiShaAdmin;user=root;password=123456;port=3306;pooling=true;max pool size=20;persist security info=True;charset=utf8mb4;", + "DBCommandTimeout": 180, // 数据库超时时间,单位秒 + "DBBackup": "", // 数据库备份路径 + + "CacheProvider": "Memory", // 缓存使用方式 Memory Redis + "RedisConnectionString": "127.0.0.1:6379" + } } diff --git a/YiSha.Web/YiSha.Admin.WebApi/nlog.config b/YiSha.Web/YiSha.Admin.WebApi/nlog.config index 1e775127..60724405 100644 --- a/YiSha.Web/YiSha.Admin.WebApi/nlog.config +++ b/YiSha.Web/YiSha.Admin.WebApi/nlog.config @@ -7,7 +7,7 @@ - + @@ -32,4 +32,4 @@ - \ No newline at end of file + diff --git a/YiSha.Web/YiSha.Web.Code/DataRepository.cs b/YiSha.Web/YiSha.Web.Code/DataRepository.cs index 6c7d344f..073ec3e3 100644 --- a/YiSha.Web/YiSha.Web.Code/DataRepository.cs +++ b/YiSha.Web/YiSha.Web.Code/DataRepository.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Text; using YiSha.Data.Repository; using YiSha.Enum.OrganizationManage; using YiSha.Util; @@ -37,6 +33,7 @@ public async Task GetUserByToken(string token) if (operatorInfo != null) { #region 角色 + strSql.Clear(); strSql.Append(@"SELECT a.BelongId as RoleId FROM SysUserBelong a @@ -44,19 +41,21 @@ public async Task GetUserByToken(string token) strSql.Append(" a.BelongType = " + UserBelongTypeEnum.Role.ParseToInt()); IEnumerable roleList = await BaseRepository().FindList(strSql.ToString()); operatorInfo.RoleIds = string.Join(",", roleList.Select(p => p.RoleId).ToArray()); - #endregion + + #endregion 角色 #region 部门名称 + strSql.Clear(); strSql.Append(@"SELECT a.DepartmentName FROM SysDepartment a WHERE a.Id = " + operatorInfo.DepartmentId); object departmentName = await BaseRepository().FindObject(strSql.ToString()); operatorInfo.DepartmentName = departmentName.ParseToString(); - #endregion + + #endregion 部门名称 } return operatorInfo; } - } } diff --git a/YiSha.Web/YiSha.Web.Code/Operator.cs b/YiSha.Web/YiSha.Web.Code/Operator.cs index 39fab381..545a225d 100644 --- a/YiSha.Web/YiSha.Web.Code/Operator.cs +++ b/YiSha.Web/YiSha.Web.Code/Operator.cs @@ -1,14 +1,7 @@ using Microsoft.AspNetCore.Http; -using System; using Microsoft.Extensions.DependencyInjection; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web; -using YiSha.Util; -using YiSha.Util.Extension; using YiSha.Cache.Factory; +using YiSha.Util; namespace YiSha.Web.Code { @@ -27,11 +20,11 @@ public async Task AddCurrent(string token) switch (LoginProvider) { case "Cookie": - new CookieHelper().WriteCookie(TokenName, token); + CookieHelper.Set(TokenName, token); break; case "Session": - new SessionHelper().WriteSession(TokenName, token); + SessionHelper.Set(TokenName, token); break; case "WebApi": @@ -56,11 +49,11 @@ public void RemoveCurrent(string apiToken = "") switch (LoginProvider) { case "Cookie": - new CookieHelper().RemoveCookie(TokenName); + CookieHelper.Remove(TokenName); break; case "Session": - new SessionHelper().RemoveSession(TokenName); + SessionHelper.Remove(TokenName); break; case "WebApi": @@ -87,14 +80,14 @@ public async Task Current(string apiToken = "") case "Cookie": if (hca.HttpContext != null) { - token = new CookieHelper().GetCookie(TokenName); + token = CookieHelper.Get(TokenName); } break; case "Session": if (hca.HttpContext != null) { - token = new SessionHelper().GetSession(TokenName); + token = SessionHelper.Get(TokenName); } break; diff --git a/YiSha.Web/YiSha.Web.Code/OperatorInfo.cs b/YiSha.Web/YiSha.Web.Code/OperatorInfo.cs index ad7ba5e6..fe7df201 100644 --- a/YiSha.Web/YiSha.Web.Code/OperatorInfo.cs +++ b/YiSha.Web/YiSha.Web.Code/OperatorInfo.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations.Schema; namespace YiSha.Web.Code { @@ -36,9 +31,9 @@ public class OperatorInfo [NotMapped] public string RoleIds { get; set; } } + public class RoleInfo { public long RoleId { get; set; } } - } diff --git a/YiSha.Web/YiSha.Web.Code/State/ConfigHelp.cs b/YiSha.Web/YiSha.Web.Code/State/ConfigHelp.cs new file mode 100644 index 00000000..91c63767 --- /dev/null +++ b/YiSha.Web/YiSha.Web.Code/State/ConfigHelp.cs @@ -0,0 +1,58 @@ +using Microsoft.Extensions.Configuration; + +namespace YiSha.Util +{ + /// + /// Config 帮助 + /// + public class ConfigHelp + { + /// + /// 获取 Config 对象 + /// + /// + public static IConfiguration GetObj() + { + return GlobalContext.Configuration; + } + + /// + /// 读取 Config + /// + /// 名称 + /// + public static T? Get(string sName) + { + try + { + var config = GlobalContext.Configuration; + if (string.IsNullOrEmpty(sName)) return default; + var configValue = config.GetValue(sName); + if (configValue == null) + { + var sectionValue = config.GetSection(sName); + configValue = (T)sectionValue.Get(typeof(T)); + } + return configValue; + } + catch (Exception ex) + { + string message = ex.Message; + //Logger.Error($"获取配置异常:{message}"); + return default; + } + } + + /// + /// 读取 Config + /// + /// 名称 + /// + public static string Get(string sName) + { + var configValue = Get(sName); + if (string.IsNullOrEmpty(configValue)) return ""; + return configValue; + } + } +} diff --git a/YiSha.Web/YiSha.Web.Code/State/CookieHelper.cs b/YiSha.Web/YiSha.Web.Code/State/CookieHelper.cs index aa24147e..08394b81 100644 --- a/YiSha.Web/YiSha.Web.Code/State/CookieHelper.cs +++ b/YiSha.Web/YiSha.Web.Code/State/CookieHelper.cs @@ -1,69 +1,124 @@ -using System; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; -using Microsoft.AspNetCore.Http; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web; -using YiSha.Util.Extension; namespace YiSha.Util { + /// + /// Cookie 帮助 + /// public class CookieHelper { /// - /// 写cookie值 + /// 获取 Cookie 对象 + /// + /// + public static IResponseCookies? GetObj() + { + var hca = GlobalContext.ServiceProvider?.GetService(); + return hca?.HttpContext?.Response.Cookies; + } + + /// + /// 写入 Cookie /// /// 名称 /// 值 - /// true代表浏览器的js不能获取到的cookie - public void WriteCookie(string sName, string sValue, bool httpOnly = true) + /// 前端脚本能否获取到的Cookie + /// 状态 + public static bool Set(string sName, string sValue, bool httpOnly = true) { - IHttpContextAccessor hca = GlobalContext.ServiceProvider?.GetService(); - CookieOptions option = new CookieOptions(); - option.Expires = DateTime.Now.AddDays(30); - option.HttpOnly = httpOnly; - option.SameSite = SameSiteMode.Lax; + var hca = GlobalContext.ServiceProvider?.GetService(); + var option = new CookieOptions + { + Expires = DateTime.MaxValue, + HttpOnly = httpOnly, + }; hca?.HttpContext?.Response.Cookies.Append(sName, sValue, option); + return true; } /// - /// 写cookie值 + /// 写入 Cookie /// /// 名称 /// 值 /// 过期时间(分钟) - /// true代表浏览器的js不能获取到的cookie - public void WriteCookie(string sName, string sValue, int expires, bool httpOnly = true) + /// 前端脚本能否获取到的Cookie + /// 状态 + public static bool Set(string sName, string sValue, int expires, bool httpOnly = true) + { + var hca = GlobalContext.ServiceProvider?.GetService(); + var option = new CookieOptions + { + Expires = DateTime.Now.AddMinutes(expires), + HttpOnly = httpOnly, + }; + hca?.HttpContext?.Response.Cookies.Append(sName, sValue, option); + return true; + } + + /// + /// 写入临时 Cookie + /// + /// 名称 + /// 值 + /// 前端脚本能否获取到的Cookie + /// 状态 + public static bool SetTemp(string sName, string sValue, bool httpOnly = true) { - IHttpContextAccessor hca = GlobalContext.ServiceProvider?.GetService(); - CookieOptions option = new CookieOptions(); - option.Expires = DateTime.Now.AddMinutes(expires); - option.HttpOnly = httpOnly; - option.SameSite = SameSiteMode.Lax; + var hca = GlobalContext.ServiceProvider?.GetService(); + var option = new CookieOptions + { + HttpOnly = httpOnly, + }; hca?.HttpContext?.Response.Cookies.Append(sName, sValue, option); + return true; } /// - /// 读cookie值 + /// 读取 Cookie /// /// 名称 - /// cookie值 - public string GetCookie(string sName) + /// + public static string Get(string sName) { - IHttpContextAccessor hca = GlobalContext.ServiceProvider?.GetService(); - return hca?.HttpContext?.Request.Cookies[sName]; + var hca = GlobalContext.ServiceProvider?.GetService(); + return hca?.HttpContext?.Request.Cookies[sName] ?? ""; } /// - /// 删除Cookie对象 + /// 删除 Cookie /// /// Cookie对象名称 - public void RemoveCookie(string sName) + /// 状态 + public static bool Remove(string sName) { - IHttpContextAccessor hca = GlobalContext.ServiceProvider?.GetService(); + var hca = GlobalContext.ServiceProvider?.GetService(); hca?.HttpContext?.Response.Cookies.Delete(sName); + return true; + } + + /// + /// 清空 Cookie + /// + /// 状态 + public static bool Clear() + { + var hca = GlobalContext.ServiceProvider?.GetService(); + //请求 + var request = hca?.HttpContext?.Request; + if (request == null) return false; + //响应 + var response = hca?.HttpContext?.Response; + if (response == null) return false; + //循环所有 Cookie + foreach (var cookie in request.Cookies) + { + var key = cookie.Key; + //var value = cookie.Value; + response.Cookies.Delete(key); + } + return true; } } } diff --git a/YiSha.Web/YiSha.Web.Code/State/SessionHelper.cs b/YiSha.Web/YiSha.Web.Code/State/SessionHelper.cs index 6eb128c2..104b03ee 100644 --- a/YiSha.Web/YiSha.Web.Code/State/SessionHelper.cs +++ b/YiSha.Web/YiSha.Web.Code/State/SessionHelper.cs @@ -1,71 +1,97 @@ -using System; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; -using Microsoft.AspNetCore.Http; -using System.Collections.Generic; -using System.Linq; using System.Text; -using System.Threading.Tasks; -using System.Web; -using Microsoft.AspNetCore.Session; -using Microsoft.AspNetCore.Http.Extensions; -using Newtonsoft.Json; +using System.Text.Json; namespace YiSha.Util { + /// + /// Session 帮助 + /// public class SessionHelper { /// - /// 写Session + /// 获取 Session 对象 + /// + /// + public static ISession? GetObj() + { + var hca = GlobalContext.ServiceProvider?.GetService(); + return hca?.HttpContext?.Session; + } + + /// + /// 写入 Session /// /// Session键值的类型 /// Session的键名 /// Session的键值 - public void WriteSession(string key, T value) + /// 状态 + public static bool Set(string key, T value) { - if (string.IsNullOrEmpty(key)) - { - return; - } - IHttpContextAccessor hca = GlobalContext.ServiceProvider?.GetService(); - hca?.HttpContext?.Session.SetString(key, JsonConvert.SerializeObject(value)); + if (string.IsNullOrEmpty(key)) return false; + var hca = GlobalContext.ServiceProvider?.GetService(); + hca?.HttpContext?.Session.SetString(key, JsonSerializer.Serialize(value)); + return true; } /// - /// 写Session + /// 写入 Session /// /// Session的键名 /// Session的键值 - public void WriteSession(string key, string value) + /// 状态 + public static bool Set(string key, string value) { - WriteSession(key, value); + return Set(key, value); } /// - /// 读取Session的值 + /// 读取 Session /// - /// Session的键名 - public string GetSession(string key) + /// Session的键名 + /// + public static T? Get(string key) { - if (string.IsNullOrEmpty(key)) - { - return string.Empty; - } - IHttpContextAccessor hca = GlobalContext.ServiceProvider?.GetService(); - return hca?.HttpContext?.Session.GetString(key) as string; + if (string.IsNullOrEmpty(key)) return default; + var hca = GlobalContext.ServiceProvider?.GetService(); + var sessionStr = hca?.HttpContext?.Session.GetString(key); + if (string.IsNullOrEmpty(sessionStr)) return default; + return JsonSerializer.Deserialize(sessionStr); } /// - /// 删除指定Session + /// 读取 Session /// /// Session的键名 - public void RemoveSession(string key) + /// + public static string Get(string key) { - if (string.IsNullOrEmpty(key)) - { - return; - } - IHttpContextAccessor hca = GlobalContext.ServiceProvider?.GetService(); + return Get(key) ?? ""; + } + + /// + /// 删除 Session + /// + /// Session的键名 + /// 状态 + public static bool Remove(string key) + { + if (string.IsNullOrEmpty(key)) return false; + var hca = GlobalContext.ServiceProvider?.GetService(); hca?.HttpContext?.Session.Remove(key); + return true; + } + + /// + /// 清空 Session + /// + /// 状态 + public static bool Clear() + { + var hca = GlobalContext.ServiceProvider?.GetService(); + hca?.HttpContext?.Session.Clear(); + return true; } } } diff --git a/YiSha.Web/YiSha.Web.Code/YiSha.Web.Code.csproj b/YiSha.Web/YiSha.Web.Code/YiSha.Web.Code.csproj index 590cc933..5b4df73c 100644 --- a/YiSha.Web/YiSha.Web.Code/YiSha.Web.Code.csproj +++ b/YiSha.Web/YiSha.Web.Code/YiSha.Web.Code.csproj @@ -2,11 +2,10 @@ net6.0 + enable + enable - - -