diff --git a/COMCMS.Core/Article/文章栏目.Biz.cs b/COMCMS.Core/Article/文章栏目.Biz.cs index ac2d0f5..071515e 100644 --- a/COMCMS.Core/Article/文章栏目.Biz.cs +++ b/COMCMS.Core/Article/文章栏目.Biz.cs @@ -142,6 +142,23 @@ namespace COMCMS.Core return Find(_.Id == id); } + + /// 根据目录查找 + /// 目录 + /// 实体对象 + public static ArticleCategory FindByFilePath(string path) + { + if (string.IsNullOrEmpty(path)) return null; + + // 实体缓存 + if (Meta.Count < 1000) return Meta.Cache.Find(e => e.FilePath == path); + + // 单对象缓存 + //return Meta.SingleCache[id]; + + return Find(_.FilePath == path); + } + /// /// 根据父ID查询所有子项 /// diff --git a/COMCMS.Core/Mall/商品栏目.Biz.cs b/COMCMS.Core/Mall/商品栏目.Biz.cs index e107cb0..55a8e06 100644 --- a/COMCMS.Core/Mall/商品栏目.Biz.cs +++ b/COMCMS.Core/Mall/商品栏目.Biz.cs @@ -132,6 +132,22 @@ namespace COMCMS.Core return Find(_.Id == id); } + + /// 根据目录查找 + /// 目录 + /// 实体对象 + public static Category FindByFilePath(string path) + { + if (string.IsNullOrEmpty(path)) return null; + + // 实体缓存 + if (Meta.Count < 1000) return Meta.Cache.Find(e => e.FilePath == path); + + // 单对象缓存 + //return Meta.SingleCache[id]; + + return Find(_.FilePath == path); + } /// /// 根据父ID查询所有子项 /// diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs index c40ea7b..50ed2ff 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs @@ -71,7 +71,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers return Json(tip); } - if (!model.FilePath.StartsWith("/")) + if (model.FilePath.StartsWith("/")) { tip.Message = "栏目路径请以/开头!"; return Json(tip); @@ -165,7 +165,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers tip.Message = "栏目路径请以/开头!"; return Json(tip); } - if (!model.FilePath.EndsWith("/")) + if (model.FilePath.EndsWith("/")) { tip.Message = "栏目路径结尾不用加上/"; return Json(tip); @@ -203,6 +203,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers alist.Save(); } } + bool idNeedUpdateAllArticleFilePath = entity.FilePath == model.FilePath; //赋值 entity.PId = model.PId; entity.KindName = model.KindName; @@ -225,10 +226,23 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers entity.KindDomain = model.KindDomain; entity.Rank = model.Rank; entity.Pic = model.Pic; - model.FilePath = model.FilePath; + entity.FilePath = model.FilePath; entity.Save(); + //修改所有文章的路径 + if (idNeedUpdateAllArticleFilePath) + { + IList
listArticles = Article.FindAll(Article._.KId == entity.Id, null, null, 0, 0); + if(listArticles !=null && listArticles.Count > 0) + { + foreach (var item in listArticles) + { + item.FilePath = entity.FilePath; + } + listArticles.BatchUpdate(); + } + } Core.Admin.WriteLogActions("修改文章栏目(id:" + entity.Id + ");"); tip.Status = JsonTip.SUCCESS; tip.Message = "修改文章栏目成功"; diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml index 0c25aff..fff93ca 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml @@ -28,7 +28,13 @@
- + +
+
+
+ +
+
@@ -37,12 +43,7 @@
- +
@@ -163,5 +164,29 @@ $(".upload-img").InitUploader({ filesize: "10240", sendurl: "/AdminCP/Upload/DoWebuploaderImage", swf: "/js/webuploader/uploader.swf", filetypes: "gif,jpg,png,bmp", notwater: true }); DoPost("editArticleKindForm"); CKEDITOR.replace('KindInfo'); - }) + }); + function aoutoTransform() { + var title = $("#KindName").val(); + var filePath = $("#FilePath").val(); + if (!filePath) { + $.ajax({ + type: "POST", + url: "/AdminCP/Server/Hanzi2Pinyin", + data: { name: title}, + dataType: "JSON", + success: function (data) { + if (data.status == "success") { + if (data.message) { + $("#FilePath").val(data.message); + } + } else { + layer.alert(data.message, { icon: 2 }); + } + }, + error: function () { + layer.alert('执行错误,请联系管理员!', { icon: 2 }); + } + }); + } + } \ No newline at end of file diff --git a/COMCMS.Web/Common/ViewsHelper.cs b/COMCMS.Web/Common/ViewsHelper.cs new file mode 100644 index 0000000..c0b83d3 --- /dev/null +++ b/COMCMS.Web/Common/ViewsHelper.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using COMCMS.Core; +using COMCMS.Common; +using XCode; + +namespace COMCMS.Web.Common +{ + /// + /// 识图方法 + /// + public class ViewsHelper + { + #region 获取分类链接 + public static string EchoURL(ArticleCategory model) + { + if (model == null) + return ""; + if (!string.IsNullOrEmpty(model.FilePath)) + return model.FilePath + "/index.html"; + else + return $"/article/index/{model.Id}"; + } + #endregion + + } +} diff --git a/COMCMS.Web/Controllers/ArticleController.cs b/COMCMS.Web/Controllers/ArticleController.cs index ee6b1d0..fab86f7 100644 --- a/COMCMS.Web/Controllers/ArticleController.cs +++ b/COMCMS.Web/Controllers/ArticleController.cs @@ -19,6 +19,7 @@ namespace COMCMS.Web.Controllers public IActionResult Index(int id = 0, int page = 1) { ArticleCategory model = ArticleCategory.FindById(id); + if (model == null) { return AlertAndGoBack("系统找不到本记录"); @@ -88,16 +89,13 @@ namespace COMCMS.Web.Controllers } ViewBag.cfg = cfg; - string templatesname = "";//模板名称 + string templatesname = "Index.cshtml";//模板名称 if (!string.IsNullOrEmpty(model.TemplateFile)) { - templatesname = model.TemplateFile.Replace(".cshtml", "").Replace(".aspx", ""); - return View(templatesname, model); - } - else - { - return View(model); + templatesname = model.TemplateFile; + //return Content(templatesname); } + return View("~/Views/Article/" + templatesname, model); //固定死就是这个 } #endregion diff --git a/COMCMS.Web/Controllers/HomeController.cs b/COMCMS.Web/Controllers/HomeController.cs index 5379490..4cade6e 100644 --- a/COMCMS.Web/Controllers/HomeController.cs +++ b/COMCMS.Web/Controllers/HomeController.cs @@ -26,7 +26,7 @@ namespace COMCMS.Web.Controllers { ViewBag.cfg = cfg; ViewBag.about = Article.FindById(1);//关于我们 - return View(); + return View("~/Views/Home/Index.cshtml"); } #endregion @@ -47,19 +47,19 @@ namespace COMCMS.Web.Controllers } #region 测试 - [Route("{path:regex([[a-zA-Z0-9-]])}/index.html")] - public IActionResult Test(string path = "") - { - string tel = "13332835377"; - return Content(tel.Substring(tel.Length - 5) + ";path:" + path); - } - [Route("{path1:regex([[a-zA-Z0-9-]])}/{path2:regex([[a-zA-Z0-9-]])}/index.html")] - public IActionResult Test2(string path1 = "", string path2 = "") - { - ArticleController ac = new ArticleController(); - return ac.Index(1); - //return Content(";ath1:" + path1+";path2:"+path2); - } + //[Route("{path:regex([[a-zA-Z0-9-]])}/index.html")] + //public IActionResult Test(string path = "") + //{ + // string tel = "13332835377"; + // return Content(tel.Substring(tel.Length - 5) + ";path:" + path); + //} + //[Route("{path1:regex([[a-zA-Z0-9-]])}/{path2:regex([[a-zA-Z0-9-]])}/index.html")] + //public IActionResult Test2(string path1 = "", string path2 = "") + //{ + // ArticleController ac = new ArticleController(); + // return ac.Index(1); + // //return Content(";ath1:" + path1+";path2:"+path2); + //} #endregion #region 测试拼音 @@ -69,8 +69,34 @@ namespace COMCMS.Web.Controllers } #endregion - #region 系统文章、商品路由 - + #region 系统文章栏目、商品栏目路由 + /// + /// 一级路径栏目 + /// + /// + /// + [Route("{path:regex([[a-zA-Z0-9-]])}/index.html")] + [Route("{path:regex([[a-zA-Z0-9-]])}/index-{page:int}.html")] + [Route("{path:regex([[a-zA-Z0-9-]])}/")] + public IActionResult ShowCategory(string path,int page=1) + { + //先判断文章栏目 + ArticleCategory articleCategory = ArticleCategory.FindByFilePath("/" + path); + if(articleCategory != null) + { + //return Content(articleCategory.Id.ToString()); + ArticleController ac = new ArticleController(); + return ac.Index(articleCategory.Id); + } + //再判断商品 + Category category = Category.FindByFilePath("/" + path); + if(category != null) + { + ProductController pc = new ProductController(); + return pc.Index(category.Id,page); + } + return EchoTip("系统找不到本栏目!"+"/"+path); + } #endregion } diff --git a/COMCMS.Web/Views/Shared/EchoTip.cshtml b/COMCMS.Web/Views/Shared/EchoTip.cshtml new file mode 100644 index 0000000..55d85fd --- /dev/null +++ b/COMCMS.Web/Views/Shared/EchoTip.cshtml @@ -0,0 +1,46 @@ +@{ + Layout = null; + ViewBag.Title = "信息提示"; +} + + + + + + @ViewBag.Title + + + + + + + + + +
+
+
+
@ViewBag.Title
+
+
+
+
+

+ 信息提示
+

+

+ @ViewBag.Message +

+

+ 返回首页 +

+
+
+ + +
+ + + + + \ No newline at end of file diff --git a/COMCMS.Web/Views/_ViewImports.cshtml b/COMCMS.Web/Views/_ViewImports.cshtml index 3d96f25..fc984f4 100644 --- a/COMCMS.Web/Views/_ViewImports.cshtml +++ b/COMCMS.Web/Views/_ViewImports.cshtml @@ -3,4 +3,5 @@ @using COMCMS.Core @using COMCMS.Common @using XCode +@using COMCMS.Web.Common @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers