From 2cb8f6dfeeef75853d4e3a45b007b9911980c0d4 Mon Sep 17 00:00:00 2001 From: "DESKTOP-M4V1LH5\\Jin" Date: Fri, 30 Nov 2018 18:40:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E7=AB=A0=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminCP/Controllers/ArticleController.cs | 33 ++++++++++++-- .../Views/Article/AddArticleCategory.cshtml | 44 +++++++++++-------- .../Views/Article/EditArticleCategory.cshtml | 40 ++++++++++------- COMCMS.Web/Controllers/ArticleController.cs | 19 +++++--- 4 files changed, 91 insertions(+), 45 deletions(-) diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs index 0905789..af11af0 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs @@ -37,7 +37,20 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //获取上级栏目 IList list = ArticleCategory.GetListTree(0, -1, true, false); ViewBag.ListTree = list; - //获取模板 + //获取模板 模板规则,以Index_开头的,为栏目列表,以Detial_开头的为文章详情 + List listTpls = new List(); + var asms = AppDomain.CurrentDomain.GetAssemblies(); + foreach (var asmItem in asms) + { + var types = asmItem.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList(); + if (types.Count == 0) continue; + foreach (var type in types) + { + string viewName = type.Name.Replace("Views_Article_", "") + ".cshtml"; + listTpls.Add(viewName); + } + } + ViewBag.ListTpl = listTpls; Core.Admin.WriteLogActions("查看添加文章栏目页面;"); return View(); } @@ -73,9 +86,21 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //获取上级栏目 IList list = ArticleCategory.GetListTree(0, -1, true, false); ViewBag.ListTree = list; - //获取模板 - //List listtpl = COMCMS.Common.IOHelper.GetDirFiles(new DirectoryInfo(Server.MapPath("~/Views/article"))); - //ViewBag.ListTpl = listtpl; + + //获取模板 模板规则,以Index_开头的,为栏目列表,以Detial_开头的为文章详情 + List listTpls = new List(); + var asms = AppDomain.CurrentDomain.GetAssemblies(); + foreach (var asmItem in asms) + { + var types = asmItem.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList(); + if (types.Count == 0) continue; + foreach (var type in types) + { + string viewName = type.Name.Replace("Views_Article_", "") + ".cshtml"; + listTpls.Add(viewName); + } + } + ViewBag.ListTpl = listTpls; Core.Admin.WriteLogActions("查看/编辑文章栏目(id:" + id + ")页面;"); return View(entity); } diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticleCategory.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticleCategory.cshtml index 9abb2d7..98356d8 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticleCategory.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticleCategory.cshtml @@ -76,28 +76,34 @@ - @*
- -
- -
-
-
- -
- + @foreach (var s in ViewBag.ListTpl) + { + if (s.ToLower().StartsWith("index")) { } - -
-
*@ + } + + + +
+ +
+ +
+
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml index 8cfea3b..bc8c428 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml @@ -76,28 +76,34 @@
- @*
- -
- + @foreach (string s in ViewBag.ListTpl) + { + if (s.ToLower().StartsWith("index")) { - + } - -
+ } +
-
- -
- + @foreach (string s in ViewBag.ListTpl) + { + if (s.ToLower().StartsWith("detail")) { - + } - -
-
*@ + } + + +
diff --git a/COMCMS.Web/Controllers/ArticleController.cs b/COMCMS.Web/Controllers/ArticleController.cs index f94716f..b1684ea 100644 --- a/COMCMS.Web/Controllers/ArticleController.cs +++ b/COMCMS.Web/Controllers/ArticleController.cs @@ -90,10 +90,14 @@ namespace COMCMS.Web.Controllers ViewBag.cfg = cfg; string templatesname = "";//模板名称 if (!string.IsNullOrEmpty(model.TemplateFile)) + { templatesname = model.TemplateFile.Replace(".cshtml", "").Replace(".aspx", ""); - - return View(model); - + return View(templatesname, model); + } + else + { + return View(model); + } } #endregion @@ -137,9 +141,14 @@ namespace COMCMS.Web.Controllers } string templatesname = "";//模板名称 if (!string.IsNullOrEmpty(kind.TemplateFile)) + { templatesname = kind.DetailTemplateFile.Replace(".cshtml", "").Replace(".aspx", ""); - - return View(entity); + return View(templatesname, entity); + } + else + { + return View(entity); + } } #endregion }