From 6a5ef1226c23e0eedc07705e398845b5d987f8ea Mon Sep 17 00:00:00 2001 From: Hogen Date: Wed, 26 Jun 2024 17:48:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=95=86=E5=93=81=E6=A0=8F?= =?UTF-8?q?=E7=9B=AE=E7=AE=A1=E7=90=86=E9=80=89=E6=8B=A9=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=EF=BC=8C=E5=95=86=E5=93=81=E6=A0=8F=E7=9B=AE=E3=80=81=E5=95=86?= =?UTF-8?q?=E5=93=81=E4=BC=AA=E9=9D=99=E6=80=81=E5=9C=B0=E5=9D=80=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COMCMS.Core/Core/ViewsHelper.cs | 40 +++++++- .../AdminCP/Controllers/ArticleController.cs | 4 +- .../AdminCP/Controllers/ProductController.cs | 92 ++++++++++++++++++- .../AdminCP/Controllers/ServerController.cs | 8 ++ .../AdminCP/Views/Product/AddCategory.cshtml | 78 +++++++++++----- .../AdminCP/Views/Product/CategoryList.cshtml | 2 +- .../AdminCP/Views/Product/EditCategory.cshtml | 73 +++++++++++---- .../AdminCP/Views/Product/ProductList.cshtml | 5 +- COMCMS.Web/Common/AdminUtils.cs | 6 +- COMCMS.Web/Controllers/ProductController.cs | 26 +++++- COMCMS.Web/Views/Home/Index.cshtml | 16 ++-- COMCMS.Web/Views/Product/Detail.cshtml | 2 +- COMCMS.Web/Views/Product/Index.cshtml | 4 +- COMCMS.Web/Views/Shared/_Layout.cshtml | 2 +- 14 files changed, 294 insertions(+), 64 deletions(-) diff --git a/COMCMS.Core/Core/ViewsHelper.cs b/COMCMS.Core/Core/ViewsHelper.cs index 349965c..b39583a 100644 --- a/COMCMS.Core/Core/ViewsHelper.cs +++ b/COMCMS.Core/Core/ViewsHelper.cs @@ -75,7 +75,22 @@ namespace COMCMS.Core /// public static string EchoURL(Product model) { - return $"/product/detail/{model.Id}"; + if (model == null) + return "javascript:;"; + + Category categoty = Category.FindById(model.KId); + + if (categoty != null && !string.IsNullOrEmpty(categoty.FilePath)) + { + string url = $"{categoty.FilePath}/{model.Id}.html"; + if (!string.IsNullOrEmpty(model.FileName)) + { + url = $"{categoty.FilePath}/{model.FileName}"; + } + return url; + } + else + return $"/product/detail/{model.Id}"; } /// @@ -149,5 +164,28 @@ namespace COMCMS.Core } #endregion + #region 生成商品地址 + /// + /// 生成商品分类地址 + /// + /// + /// + public static string EchoCategoryURL(int id) + { + Category model = Category.FindById(id); + return EchoURL(model); + } + /// + /// 生成商品详情地址 + /// + /// + /// + public static string EchoProductURL(int id) + { + Product model = Product.FindById(id); + return EchoURL(model); + } + #endregion + } } diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs index 16f81cd..306e397 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs @@ -43,7 +43,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers foreach (var asmItem in asms) { string fullName = asmItem.GetName().ToString(); - if (fullName.IndexOf("COMCMS.Web.Views") > -1) + if (fullName.IndexOf("COMCMS.Web") > -1) { var types = asmItem.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList(); if (types.Count == 0) continue; @@ -174,7 +174,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers foreach (var asmItem in asms) { string fullName = asmItem.GetName().ToString(); - if (fullName.IndexOf("COMCMS.Web.Views") > -1) + if (fullName.IndexOf("COMCMS.Web") > -1) { var types = asmItem.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList(); if (types.Count == 0) continue; diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/ProductController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/ProductController.cs index 90dfb20..46adad6 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/ProductController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/ProductController.cs @@ -36,6 +36,24 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //获取上级栏目 IList list = Category.GetListTree(0, -1, true, false); ViewBag.ListTree = list; + //获取模板 模板规则,以Index_开头的,为栏目列表,以Detial_开头的为文章详情 + List listTpls = new List(); + var asms = AppDomain.CurrentDomain.GetAssemblies(); + foreach (var asmItem in asms) + { + string fullName = asmItem.GetName().ToString(); + if (fullName.IndexOf("COMCMS.Web") > -1) + { + var types = asmItem.GetTypes().Where(e => e.Name.StartsWith("Views_Product")).ToList(); + if (types.Count == 0) continue; + foreach (var type in types) + { + string viewName = type.Name.Replace("Views_Product_", "") + ".cshtml"; + listTpls.Add(viewName); + } + } + } + ViewBag.ListTpl = listTpls; //获取模板 //List listtpl = COMCMS.Common.IOHelper.GetDirFiles(new DirectoryInfo(Server.MapPath("~/Views/article"))); //ViewBag.ListTpl = listtpl; @@ -53,6 +71,33 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers tip.Message = "商品栏目标题不能为空!"; return Json(tip); } + + if (!string.IsNullOrEmpty(model.FilePath)) + { + if (!model.FilePath.StartsWith("/")) + { + tip.Message = "栏目路径请以/开头!"; + return Json(tip); + } + if (model.FilePath.EndsWith("/")) + { + tip.Message = "栏目路径结尾不用加上/"; + return Json(tip); + } + + if (model.FilePath.Count(x => x == '/') > 4) + { + tip.Message = "最多只能四级路径!"; + return Json(tip); + } + } + + if (!string.IsNullOrEmpty(model.FilePath) && !AdminUtils.CheckFilePathIsOK(model.FilePath, 0, 1)) + { + tip.Message = "栏目路径不可用,请重新填写!"; + return Json(tip); + } + model.Insert(); Core.Admin.WriteLogActions("添加商品栏目(id:" + model.Id + ");"); tip.Status = JsonTip.SUCCESS; @@ -74,9 +119,25 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //获取上级栏目 IList list = Category.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) + { + string fullName = asmItem.GetName().ToString(); + if (fullName.IndexOf("COMCMS.Web") > -1) + { + var types = asmItem.GetTypes().Where(e => e.Name.StartsWith("Views_Product")).ToList(); + if (types.Count == 0) continue; + foreach (var type in types) + { + string viewName = type.Name.Replace("Views_Product_", "") + ".cshtml"; + listTpls.Add(viewName); + } + } + } + ViewBag.ListTpl = listTpls; + Core.Admin.WriteLogActions("查看/编辑商品栏目(id:" + id + ")页面;"); return View(entity); } @@ -102,6 +163,30 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers tip.Message = "系统找不到本记录!"; Json(tip); } + if (!string.IsNullOrEmpty(model.FilePath)) + { + if (!model.FilePath.StartsWith("/")) + { + tip.Message = "栏目路径请以/开头!"; + return Json(tip); + } + if (model.FilePath.EndsWith("/")) + { + tip.Message = "栏目路径结尾不用加上/"; + return Json(tip); + } + + if (model.FilePath.Count(x => x == '/') > 4) + { + tip.Message = "最多只能四级路径!"; + return Json(tip); + } + } + if (!string.IsNullOrEmpty(model.FilePath) && !AdminUtils.CheckFilePathIsOK(model.FilePath, entity.Id, 1)) + { + tip.Message = "栏目路径不可用,请重新填写!"; + return Json(tip); + } if (entity.PId != model.PId) { @@ -147,6 +232,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers entity.KindDomain = model.KindDomain; entity.Rank = model.Rank; entity.Pic = model.Pic; + entity.FilePath = model.FilePath; entity.Save(); diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/ServerController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/ServerController.cs index c2bbcf3..b230613 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/ServerController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/ServerController.cs @@ -28,6 +28,14 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers pinyin = pcategory.FilePath+"/"; } } + else if(t == "category" && pid > 0) + { + Category pcategory = Category.FindById(pid); + if (pcategory != null && !string.IsNullOrEmpty(pcategory.FilePath)) + { + pinyin = pcategory.FilePath + "/"; + } + } if (!string.IsNullOrEmpty(name)) { diff --git a/COMCMS.Web/Areas/AdminCP/Views/Product/AddCategory.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Product/AddCategory.cshtml index 39fabde..7a26fb7 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Product/AddCategory.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Product/AddCategory.cshtml @@ -27,7 +27,13 @@
- + +
+
+
+ +
+
@@ -69,29 +75,34 @@
- - @*
- -
- -
-
-
- -
- + @foreach (var s in ViewBag.ListTpl) + { + if (s.ToLower().StartsWith("index")) { } - -
-
*@ + } + + + +
+ +
+ +
+
@@ -145,5 +156,30 @@ DoPost("addArticleKindForm"); CKEDITOR.replace('KindInfo'); }) + function aoutoTransform() { + var title = $("#KindName").val(); + var filePath = $("#FilePath").val(); + var pid = $("#PId").val(); + if (!filePath) { + $.ajax({ + type: "POST", + url: "/AdminCP/Server/Hanzi2Pinyin", + data: { name: title, pid: pid, t: "category" }, + 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 }); + } + }); + } + } diff --git a/COMCMS.Web/Areas/AdminCP/Views/Product/CategoryList.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Product/CategoryList.cshtml index a398004..d92215f 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Product/CategoryList.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Product/CategoryList.cshtml @@ -34,7 +34,7 @@ @foreach (var m in Model) { - @m.KindName + @m.KindName @m.Id diff --git a/COMCMS.Web/Areas/AdminCP/Views/Product/EditCategory.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Product/EditCategory.cshtml index 822dadb..f32ce90 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Product/EditCategory.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Product/EditCategory.cshtml @@ -28,7 +28,13 @@
- + +
+
+
+ +
+
@@ -86,28 +92,34 @@
- @*
- -
- + @foreach (var s in ViewBag.ListTpl) + { + if (s.ToLower().StartsWith("index")) { - + } - -
+ } +
-
- -
- + @foreach (var s in ViewBag.ListTpl) + { + if (s.ToLower().StartsWith("detail")) { - + } - -
-
*@ + } + +
+
@@ -162,4 +174,29 @@ DoPost("editCategoryForm"); CKEDITOR.replace('KindInfo'); }) + function aoutoTransform() { + var title = $("#KindName").val(); + var filePath = $("#FilePath").val(); + var pid = $("#PId").val(); + if (!filePath) { + $.ajax({ + type: "POST", + url: "/AdminCP/Server/Hanzi2Pinyin", + data: { name: title, pid: pid, t: "category" }, + 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/Areas/AdminCP/Views/Product/ProductList.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Product/ProductList.cshtml index 1c6af90..48a733a 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Product/ProductList.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Product/ProductList.cshtml @@ -135,7 +135,10 @@ title: '所属分类' }, { field: 'Title', - title: '商品标题', + title: '商品标题', + formatter: function (value, row, index) { + return '' + value + '' + } }, { field: 'Price', diff --git a/COMCMS.Web/Common/AdminUtils.cs b/COMCMS.Web/Common/AdminUtils.cs index 07704cc..bb14c2e 100644 --- a/COMCMS.Web/Common/AdminUtils.cs +++ b/COMCMS.Web/Common/AdminUtils.cs @@ -81,13 +81,13 @@ namespace COMCMS.Web.Common return false; } } - else if(typeid == 1) + else if(typeid == 1)//商品 { - if (ArticleCategory.FindCount(ArticleCategory._.FilePath == pathname , null, null, 0, 0) > 0) + if (Category.FindCount(Category._.FilePath == pathname & Category._.Id != kid, null, null, 0, 0) > 0) { return false; } - if (Category.FindCount(Category._.FilePath == pathname & Category._.Id != kid, null, null, 0, 0) > 0) + if (ArticleCategory.FindCount(ArticleCategory._.FilePath == pathname, null, null, 0, 0) > 0) { return false; } diff --git a/COMCMS.Web/Controllers/ProductController.cs b/COMCMS.Web/Controllers/ProductController.cs index e86991a..0f860c3 100644 --- a/COMCMS.Web/Controllers/ProductController.cs +++ b/COMCMS.Web/Controllers/ProductController.cs @@ -8,6 +8,7 @@ using COMCMS.Core; using COMCMS.Core.Models; using COMCMS.Web.Common; using XCode; +using static Google.Protobuf.WellKnownTypes.Field.Types; namespace COMCMS.Web.Controllers { @@ -60,7 +61,14 @@ namespace COMCMS.Web.Controllers ViewBag.cfg = cfg; ViewBag.list = list; - return View(entity); + string templatesname = "Index.cshtml";//模板名称 + if (!string.IsNullOrEmpty(entity.TemplateFile)) + { + templatesname = entity.TemplateFile; + //return Content(templatesname); + } + + return View("~/Views/Product/" + templatesname, entity); } #endregion @@ -73,6 +81,11 @@ namespace COMCMS.Web.Controllers { return EchoTip("系统找不到本记录!"); } + Category kind = Category.FindById(entity.KId); + if (kind == null) + { + return AlertAndGoBack("系统找不到本文章栏目!"); + } //文章更多图片列表 if (!string.IsNullOrEmpty(entity.ItemImg)) { @@ -92,7 +105,16 @@ namespace COMCMS.Web.Controllers ViewBag.cfg = cfg; ViewBag.category = entity.Category; - return View(entity); + string templatesname = "";//模板名称 + if (!string.IsNullOrEmpty(kind.TemplateFile)) + { + templatesname = kind.DetailTemplateFile;//.Replace(".cshtml", "").Replace(".aspx", ""); + return View("~/Views/Product/" + templatesname, entity); + } + else + { + return View("~/Views/Product/Detail.cshtml", entity); + } } #endregion } diff --git a/COMCMS.Web/Views/Home/Index.cshtml b/COMCMS.Web/Views/Home/Index.cshtml index 81f7567..235633b 100644 --- a/COMCMS.Web/Views/Home/Index.cshtml +++ b/COMCMS.Web/Views/Home/Index.cshtml @@ -177,7 +177,7 @@
@@ -186,7 +186,7 @@

@(Utils.CutString(Utils.NoHTML(about?.Content), 700))

- 查看详情 + 查看详情
@@ -210,7 +210,7 @@ @foreach(var p in listPorducts) {
  • - +