From 2ab7ecc9b0304d54c50f18cf75ba477b5547d9a5 Mon Sep 17 00:00:00 2001 From: xxred Date: Wed, 7 Nov 2018 17:15:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=EF=BC=8C=E7=9B=B8=E5=BA=94=E6=8E=A7=E5=88=B6=E5=85=B6?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=8A=A0=E4=B8=8ADisplayName=E3=80=81Descrip?= =?UTF-8?q?tion=E7=89=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../AdminCP/Controllers/ArticleController.cs | 5 + .../Controllers/GuestbookController.cs | 2 +- .../AdminCP/Controllers/MemberController.cs | 4 + .../Controllers/PermissionController.cs | 3 + COMCMS.Web/COMCMS.Web.csproj | 2 +- COMCMS.Web/Common/MenuRegister.cs | 137 ++++++++++++++++++ COMCMS.Web/Startup.cs | 3 + COMCMS_NETCORE.sln | 8 +- WebTest/Program.cs | 24 +++ WebTest/Startup.cs | 71 +++++++++ WebTest/Views/Home/About.cshtml | 7 + WebTest/Views/Home/Contact.cshtml | 17 +++ WebTest/Views/Home/Index.cshtml | 94 ++++++++++++ WebTest/Views/Home/Privacy.cshtml | 6 + .../Views/Shared/_CookieConsentPartial.cshtml | 41 ++++++ WebTest/Views/Shared/_Layout.cshtml | 74 ++++++++++ .../Shared/_ValidationScriptsPartial.cshtml | 18 +++ WebTest/Views/_ViewImports.cshtml | 2 + WebTest/Views/_ViewStart.cshtml | 3 + WebTest/WebTest.csproj | 21 +++ WebTest/appsettings.Development.json | 9 ++ WebTest/appsettings.json | 8 + 23 files changed, 557 insertions(+), 3 deletions(-) create mode 100644 COMCMS.Web/Common/MenuRegister.cs create mode 100644 WebTest/Program.cs create mode 100644 WebTest/Startup.cs create mode 100644 WebTest/Views/Home/About.cshtml create mode 100644 WebTest/Views/Home/Contact.cshtml create mode 100644 WebTest/Views/Home/Index.cshtml create mode 100644 WebTest/Views/Home/Privacy.cshtml create mode 100644 WebTest/Views/Shared/_CookieConsentPartial.cshtml create mode 100644 WebTest/Views/Shared/_Layout.cshtml create mode 100644 WebTest/Views/Shared/_ValidationScriptsPartial.cshtml create mode 100644 WebTest/Views/_ViewImports.cshtml create mode 100644 WebTest/Views/_ViewStart.cshtml create mode 100644 WebTest/WebTest.csproj create mode 100644 WebTest/appsettings.Development.json create mode 100644 WebTest/appsettings.json diff --git a/.gitignore b/.gitignore index fecad19..078ea47 100644 --- a/.gitignore +++ b/.gitignore @@ -307,3 +307,4 @@ COMCMS.Web/wwwroot/userfiles/ /COMCMS.Web/COMCMS.Web.csproj.DotSettings /COMCMS.Web/UploadFile /COMCMS.Web/UploadTemp +/WebTest/wwwroot diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs index 07c98c3..0905789 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -12,6 +13,8 @@ using Microsoft.AspNetCore.Http; namespace COMCMS.Web.Areas.AdminCP.Controllers { + [DisplayName("文章系统")] + [Description("文章系统管理,包括文章、文章栏目")] public class ArticleController : AdminBaseController { #region 文章栏目 @@ -20,6 +23,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers /// /// [MyAuthorize( "viewlist", "articlecategory")] + [DisplayName("文章栏目")] public IActionResult ArticleCategoryList() { IList list = ArticleCategory.GetListTree(0, -1, false, true); @@ -189,6 +193,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers /// /// [MyAuthorize("viewlist", "article")] + [DisplayName("文章")] public IActionResult ArticleList() { //获取上级栏目 diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/GuestbookController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/GuestbookController.cs index 0b9f10c..dfcef92 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/GuestbookController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/GuestbookController.cs @@ -99,7 +99,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers ViewBag.ListKinds = list; return View(); } - [MyAuthorize("viewlist", "guestbook")] + [MyAuthorize("viewlist", "guestbook","JSON")] public IActionResult GetGuesbookList(string keyword, int page = 1, int limit = 20) { int numPerPage, currentPage, startRowIndex; diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs index 261b689..68e8c12 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/MemberController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -19,6 +20,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers /// /// 后台用户管理控制器 /// + [DisplayName("管理员")] public class MemberController : AdminBaseController { #region 修改密码 @@ -115,6 +117,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers #region 管理组管理 [MyAuthorize("viewlist", "adminrole")] + [DisplayName("管理组")] public IActionResult AdminRole() { IList list = AdminRoles.FindAll(AdminRoles._.Id > 0, AdminRoles._.Rank.Asc(), null, 0, 0); @@ -366,6 +369,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers #region 管理员管理 //管理员管理 [MyAuthorize("viewlist", "admins")] + [DisplayName("管理员")] public IActionResult Admins() { //加载管理组 diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/PermissionController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/PermissionController.cs index d619dfd..dc40bcb 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/PermissionController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/PermissionController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -13,6 +14,7 @@ using Microsoft.AspNetCore.Http; namespace COMCMS.Web.Areas.AdminCP.Controllers { [Area("AdminCP")] + [DisplayName("后台权限")] public class PermissionController : AdminBaseController { #region 事件管理 @@ -107,6 +109,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers #region 后台栏目管理 //后台菜单列表 [MyAuthorize( "viewlist", "adminmenu")] + [DisplayName("后台栏目")] public IActionResult AdminMenuList() { IList list = AdminMenu.GetListTree(0, -1, false, true); diff --git a/COMCMS.Web/COMCMS.Web.csproj b/COMCMS.Web/COMCMS.Web.csproj index 18d8dc0..f6abe4a 100644 --- a/COMCMS.Web/COMCMS.Web.csproj +++ b/COMCMS.Web/COMCMS.Web.csproj @@ -6,7 +6,7 @@ - + diff --git a/COMCMS.Web/Common/MenuRegister.cs b/COMCMS.Web/Common/MenuRegister.cs new file mode 100644 index 0000000..399e103 --- /dev/null +++ b/COMCMS.Web/Common/MenuRegister.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using COMCMS.Core; +using Microsoft.AspNetCore.Mvc; +using NewLife.Reflection; +using XCode; + +namespace COMCMS.Web.Common +{ + public class MenuRegister + { + private static void StartRegister() + { + // 操作项定义 + var menuEventDic = new Dictionary> + { + { "add",new KeyValuePair(1,"添加")}, + { "edit",new KeyValuePair(2,"修改")}, + { "del",new KeyValuePair(3,"删除")}, + { "view",new KeyValuePair(4,"查看")}, + { "viewlist",new KeyValuePair(5,"查看列表")}, + { "import",new KeyValuePair(6,"导入")}, + { "export",new KeyValuePair(7,"导出")}, + { "filter",new KeyValuePair(8,"搜索")}, + { "batch",new KeyValuePair(9,"批量操作")}, + { "recycle",new KeyValuePair(10,"回收站")}, + { "confirm",new KeyValuePair(11,"确认")}, + + }; + + var asms = AppDomain.CurrentDomain.GetAssemblies(); + foreach (var asmItem in asms) + { + var types = asmItem.GetTypes().Where(e => e.Name.EndsWith("Controller")).ToList(); + if (types.Count == 0) continue; + + foreach (var type in types) + { + // 控制器名称 + var ctrName = type.Name.TrimEnd("Controller"); + + // 控制器展示名 + var ctrDpName = type.GetDisplayName(); + + var ctrDes = type.GetDescription(); + + var url = ctrName; + + var fAdminMenu = AdminMenu.Find(AdminMenu._.MenuKey == ctrName + "Sys" & AdminMenu._.Link == "#"); + var nAdminMenu = new AdminMenu + { + Description = ctrDes, + IsHide = 0, + Level = 0, + Link = "#", + Location = "0,", + MenuKey = ctrName + "Sys", + MenuName = ctrDpName, + PId = 0 + }; + var pAdminMenu = fAdminMenu ?? nAdminMenu; + if (pAdminMenu.Id > 0) + { + pAdminMenu.Description = nAdminMenu.Description; + pAdminMenu.MenuName = nAdminMenu.MenuName; + } + pAdminMenu.Save(); + + // 控制器所有包含MyAuthorizeAttribute的方法 + var acts = type.GetMethods() + .Where(w => w.IsDefined(typeof(MyAuthorizeAttribute))) + .ToList(); + + if (!acts.Any()) continue; + + var eventKeyDic = new Dictionary(); + var adminMenuEventList = new List(); + + foreach (var method in acts) + { + var dn = method.GetDisplayName(); + var methodDes = method.GetDescription(); + var actName = method.Name; + var myAuthorize = method.GetCustomAttribute(); + + var menuKey = myAuthorize.GetValue("_menuKey").ToString(); + var eventKey = myAuthorize.GetValue("_eventKey").ToString(); + var returnType = myAuthorize.GetValue("_returnType").ToString(); + + //保存菜单 + if (eventKey == "viewlist" && returnType == "HTML") + { + var adminMenu = AdminMenu.Find(AdminMenu._.MenuKey == menuKey & AdminMenu._.Link == url + "/" + actName) ?? new AdminMenu + { + Description = methodDes, + IsHide = 0, + Level = pAdminMenu.Level + 1, + Link = url + "/" + actName, + Location = pAdminMenu.Location + ",", + MenuKey = menuKey, + MenuName = dn, + PId = pAdminMenu.Id + }; + adminMenu.Save(); + + eventKeyDic[menuKey] = adminMenu.Id; + } + + // 保存操作 + var adminmenuevent = AdminMenuEvent.Find(AdminMenuEvent._.MenuId == menuEventDic[eventKey].Key + & AdminMenuEvent._.MenuKey == menuKey & AdminMenuEvent._.EventKey == eventKey) + ?? new AdminMenuEvent + { + MenuKey = menuKey, + MenuId = menuEventDic[eventKey].Key, + EventKey = eventKey, + EventName = menuEventDic[eventKey].Value + }; + adminMenuEventList.Add(adminmenuevent); + } + + adminMenuEventList.ForEach(f => f.MenuId = eventKeyDic.ContainsKey(f.MenuKey) ? eventKeyDic[f.MenuKey] : 0); + adminMenuEventList.Save(); + } + + } + } + + public static void Register() + { + Task.Run(() => { StartRegister(); }).LogException(); + } + } +} diff --git a/COMCMS.Web/Startup.cs b/COMCMS.Web/Startup.cs index fb57925..7b7bbba 100644 --- a/COMCMS.Web/Startup.cs +++ b/COMCMS.Web/Startup.cs @@ -43,6 +43,9 @@ namespace COMCMS.Web // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + // 注册菜单 + MenuRegister.Register(); + //注入自己的HttpContext services.AddSingleton(); //services.AddMvc().AddSessionStateTempDataProvider(); diff --git a/COMCMS_NETCORE.sln b/COMCMS_NETCORE.sln index 765d897..f260e9a 100644 --- a/COMCMS_NETCORE.sln +++ b/COMCMS_NETCORE.sln @@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COMCMS.API", "COMCMS.API\CO EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib.Core", "Lib.Core\Lib.Core.csproj", "{D95FC3C1-B035-4A19-A706-71C31DD1E52D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewLife.UserGroup.WebUploader", "NewLife.UserGroup.WebUploader\NewLife.UserGroup.WebUploader.csproj", "{F8D6AE11-1436-44CA-BDD9-4AFD7B489DD0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewLife.UserGroup.WebUploader", "NewLife.UserGroup.WebUploader\NewLife.UserGroup.WebUploader.csproj", "{F8D6AE11-1436-44CA-BDD9-4AFD7B489DD0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebTest", "WebTest\WebTest.csproj", "{9226DDB8-57D8-484A-9B3E-CB73CDB2F20B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +53,10 @@ Global {F8D6AE11-1436-44CA-BDD9-4AFD7B489DD0}.Debug|Any CPU.Build.0 = Debug|Any CPU {F8D6AE11-1436-44CA-BDD9-4AFD7B489DD0}.Release|Any CPU.ActiveCfg = Release|Any CPU {F8D6AE11-1436-44CA-BDD9-4AFD7B489DD0}.Release|Any CPU.Build.0 = Release|Any CPU + {9226DDB8-57D8-484A-9B3E-CB73CDB2F20B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9226DDB8-57D8-484A-9B3E-CB73CDB2F20B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9226DDB8-57D8-484A-9B3E-CB73CDB2F20B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9226DDB8-57D8-484A-9B3E-CB73CDB2F20B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WebTest/Program.cs b/WebTest/Program.cs new file mode 100644 index 0000000..d0016a3 --- /dev/null +++ b/WebTest/Program.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace WebTest +{ + public class Program + { + public static void Main(string[] args) + { + CreateWebHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/WebTest/Startup.cs b/WebTest/Startup.cs new file mode 100644 index 0000000..772fa36 --- /dev/null +++ b/WebTest/Startup.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using COMCMS.Web; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace WebTest +{ + public class MyStartup : Startup + { + public MyStartup(IConfiguration configuration) : base(configuration) + { + } + } + + //public class Startup + //{ + // public Startup(IConfiguration configuration) + // { + // Configuration = configuration; + // } + + // public IConfiguration Configuration { get; } + + // // This method gets called by the runtime. Use this method to add services to the container. + // public void ConfigureServices(IServiceCollection services) + // { + // 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.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + // } + + // // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + // public void Configure(IApplicationBuilder app, IHostingEnvironment env) + // { + // if (env.IsDevelopment()) + // { + // app.UseDeveloperExceptionPage(); + // } + // else + // { + // app.UseExceptionHandler("/Home/Error"); + // app.UseHsts(); + // } + + // app.UseHttpsRedirection(); + // app.UseStaticFiles(); + // app.UseCookiePolicy(); + + // app.UseMvc(routes => + // { + // routes.MapRoute( + // name: "default", + // template: "{controller=Home}/{action=Index}/{id?}"); + // }); + // } + //} +} diff --git a/WebTest/Views/Home/About.cshtml b/WebTest/Views/Home/About.cshtml new file mode 100644 index 0000000..3674e37 --- /dev/null +++ b/WebTest/Views/Home/About.cshtml @@ -0,0 +1,7 @@ +@{ + ViewData["Title"] = "About"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +

Use this area to provide additional information.

diff --git a/WebTest/Views/Home/Contact.cshtml b/WebTest/Views/Home/Contact.cshtml new file mode 100644 index 0000000..a11a186 --- /dev/null +++ b/WebTest/Views/Home/Contact.cshtml @@ -0,0 +1,17 @@ +@{ + ViewData["Title"] = "Contact"; +} +

@ViewData["Title"]

+

@ViewData["Message"]

+ +
+ One Microsoft Way
+ Redmond, WA 98052-6399
+ P: + 425.555.0100 +
+ +
+ Support: Support@example.com
+ Marketing: Marketing@example.com +
diff --git a/WebTest/Views/Home/Index.cshtml b/WebTest/Views/Home/Index.cshtml new file mode 100644 index 0000000..f42d2a0 --- /dev/null +++ b/WebTest/Views/Home/Index.cshtml @@ -0,0 +1,94 @@ +@{ + ViewData["Title"] = "Home Page"; +} + + + + diff --git a/WebTest/Views/Home/Privacy.cshtml b/WebTest/Views/Home/Privacy.cshtml new file mode 100644 index 0000000..7bd3861 --- /dev/null +++ b/WebTest/Views/Home/Privacy.cshtml @@ -0,0 +1,6 @@ +@{ + ViewData["Title"] = "Privacy Policy"; +} +

@ViewData["Title"]

+ +

Use this page to detail your site's privacy policy.

diff --git a/WebTest/Views/Shared/_CookieConsentPartial.cshtml b/WebTest/Views/Shared/_CookieConsentPartial.cshtml new file mode 100644 index 0000000..bbfbb09 --- /dev/null +++ b/WebTest/Views/Shared/_CookieConsentPartial.cshtml @@ -0,0 +1,41 @@ +@using Microsoft.AspNetCore.Http.Features + +@{ + var consentFeature = Context.Features.Get(); + var showBanner = !consentFeature?.CanTrack ?? false; + var cookieString = consentFeature?.CreateConsentCookie(); +} + +@if (showBanner) +{ + + +} \ No newline at end of file diff --git a/WebTest/Views/Shared/_Layout.cshtml b/WebTest/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000..415e3f6 --- /dev/null +++ b/WebTest/Views/Shared/_Layout.cshtml @@ -0,0 +1,74 @@ + + + + + + @ViewData["Title"] - WebTest + + + + + + + + + + + + + + + +
+ @RenderBody() +
+
+

© 2018 - WebTest

+
+
+ + + + + + + + + + + + + @RenderSection("Scripts", required: false) + + diff --git a/WebTest/Views/Shared/_ValidationScriptsPartial.cshtml b/WebTest/Views/Shared/_ValidationScriptsPartial.cshtml new file mode 100644 index 0000000..2a9241f --- /dev/null +++ b/WebTest/Views/Shared/_ValidationScriptsPartial.cshtml @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/WebTest/Views/_ViewImports.cshtml b/WebTest/Views/_ViewImports.cshtml new file mode 100644 index 0000000..d05d2fb --- /dev/null +++ b/WebTest/Views/_ViewImports.cshtml @@ -0,0 +1,2 @@ +@using WebTest +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/WebTest/Views/_ViewStart.cshtml b/WebTest/Views/_ViewStart.cshtml new file mode 100644 index 0000000..a5f1004 --- /dev/null +++ b/WebTest/Views/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +} diff --git a/WebTest/WebTest.csproj b/WebTest/WebTest.csproj new file mode 100644 index 0000000..bd35275 --- /dev/null +++ b/WebTest/WebTest.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + + + + + + diff --git a/WebTest/appsettings.Development.json b/WebTest/appsettings.Development.json new file mode 100644 index 0000000..e203e94 --- /dev/null +++ b/WebTest/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/WebTest/appsettings.json b/WebTest/appsettings.json new file mode 100644 index 0000000..def9159 --- /dev/null +++ b/WebTest/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +}