完善商品栏目管理选择模板,商品栏目、商品伪静态地址生成

This commit is contained in:
2024-06-26 17:48:08 +08:00
parent e97763bfab
commit 6a5ef1226c
14 changed files with 294 additions and 64 deletions
@@ -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;
@@ -36,6 +36,24 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
//获取上级栏目
IList<Category> list = Category.GetListTree(0, -1, true, false);
ViewBag.ListTree = list;
//获取模板 模板规则,以Index_开头的,为栏目列表,以Detial_开头的为文章详情
List<string> listTpls = new List<string>();
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<string> 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<Category> list = Category.GetListTree(0, -1, true, false);
ViewBag.ListTree = list;
//获取模板
//List<string> listtpl = COMCMS.Common.IOHelper.GetDirFiles(new DirectoryInfo(Server.MapPath("~/Views/article")));
//ViewBag.ListTpl = listtpl;
//获取模板 模板规则,以Index_开头的,为栏目列表,以Detial_开头的为文章详情
List<string> listTpls = new List<string>();
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();
@@ -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))
{
@@ -27,7 +27,13 @@
<div class="form-group">
<label class="col-sm-3 control-label">栏目名称:</label>
<div class="col-sm-8">
<input id="KindName" name="KindName" maxlength="200" type="text" class="form-control" required aria-required="true" placeholder="填写栏目名称">
<input id="KindName" name="KindName" maxlength="200" type="text" class="form-control" required aria-required="true" placeholder="填写栏目名称" onblur="aoutoTransform()">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">栏目路径:</label>
<div class="col-sm-8">
<input id="FilePath" name="FilePath" maxlength="100" type="text" class="form-control" aria-required="true" placeholder="填写栏目路径,SEO优化使用,最多支持4级目录,可以输入字母、数字和-">
</div>
</div>
<div class="form-group">
@@ -69,29 +75,34 @@
</label>
</div>
</div>
@*<div class="form-group">
<label class="col-sm-3 control-label">栏目模板:</label>
<div class="col-sm-8">
<select class="form-control" name="TemplateFile" id="TemplateFile">
@foreach (var s in ViewBag.ListTpl)
{
<option value="@s" >@s</option>
}
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">商品模板:</label>
<div class="col-sm-8">
<select class="form-control" name="DetailTemplateFile" id="DetailTemplateFile">
@foreach (var s in ViewBag.ListTpl)
<div class="form-group">
<label class="col-sm-3 control-label">栏目模板:</label>
<div class="col-sm-8">
<select class="form-control" name="TemplateFile" id="TemplateFile">
@foreach (var s in ViewBag.ListTpl)
{
if (s.ToLower().StartsWith("index"))
{
<option value="@s">@s</option>
}
</select>
</div>
</div>*@
}
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">商品详情模板:</label>
<div class="col-sm-8">
<select class="form-control" name="DetailTemplateFile" id="DetailTemplateFile">
@foreach (var s in ViewBag.ListTpl)
{
if (s.ToLower().StartsWith("detail"))
{
<option value="@s">@s</option>
}
}
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">隐藏栏目:</label>
<div class="col-sm-8">
@@ -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 });
}
});
}
}
</script>
@@ -34,7 +34,7 @@
@foreach (var m in Model)
{
<tr class="treegrid-@m.Id @(m.PId !=0?"treegrid-parent-"+m.PId:"") ">
<td>@m.KindName</td>
<td><a href="@ViewsHelper.EchoURL(m)" target="_blank" title="新窗口打开栏目">@m.KindName</a></td>
<td>
@m.Id
</td>
@@ -28,7 +28,13 @@
<div class="form-group">
<label class="col-sm-3 control-label">栏目名称:</label>
<div class="col-sm-8">
<input id="KindName" name="KindName" maxlength="200" type="text" class="form-control" value="@Model.KindName" required aria-required="true" placeholder="填写栏目名称">
<input id="KindName" name="KindName" maxlength="200" type="text" class="form-control" value="@Model.KindName" required aria-required="true" placeholder="填写栏目名称" onblur="aoutoTransform()">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">栏目路径:</label>
<div class="col-sm-8">
<input id="FilePath" name="FilePath" maxlength="100" type="text" class="form-control" aria-required="true" placeholder="填写栏目路径,SEO优化使用,最多支持4级目录,可以输入字母、数字和-" value="@Model.FilePath">
</div>
</div>
<div class="form-group">
@@ -86,28 +92,34 @@
</div>
</div>
@*<div class="form-group">
<label class="col-sm-3 control-label">栏目模板:</label>
<div class="col-sm-8">
<select class="form-control" name="TemplateFile" id="TemplateFile">
@foreach (var s in ViewBag.ListTpl)
<div class="form-group">
<label class="col-sm-3 control-label">栏目模板:</label>
<div class="col-sm-8">
<select class="form-control" asp-for="TemplateFile">
@foreach (var s in ViewBag.ListTpl)
{
if (s.ToLower().StartsWith("index"))
{
<option value="@s" @(Model.TemplateFile == s?"selected":"")>@s</option>
<option value="@s">@s</option>
}
</select>
</div>
}
</select>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">商品模板:</label>
<div class="col-sm-8">
<select class="form-control" name="DetailTemplateFile" id="DetailTemplateFile">
@foreach (var s in ViewBag.ListTpl)
</div>
<div class="form-group">
<label class="col-sm-3 control-label">商品详情模板:</label>
<div class="col-sm-8">
<select class="form-control" asp-for="DetailTemplateFile">
@foreach (var s in ViewBag.ListTpl)
{
if (s.ToLower().StartsWith("detail"))
{
<option value="@s" @(Model.DetailTemplateFile == s?"selected":"")>@s</option>
<option value="@s">@s</option>
}
</select>
</div>
</div>*@
}
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">隐藏栏目:</label>
<div class="col-sm-8">
@@ -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 });
}
});
}
}
</script>
@@ -135,7 +135,10 @@
title: '所属分类'
}, {
field: 'Title',
title: '商品标题',
title: '商品标题',
formatter: function (value, row, index) {
return '<a href="/Product/Detail/' + row["id"] + '" target="_blank" title="新窗口打开预览商品">' + value + '</a>'
}
}, {
field: 'Price',
+3 -3
View File
@@ -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;
}
+24 -2
View File
@@ -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
}
+8 -8
View File
@@ -177,7 +177,7 @@
<div class="i-au-cont">
<div class="i-au-left">
<div class="pic-box">
<a href="/Article/detail/1" title="关于我们">
<a href="@(ViewsHelper.EchoArticleURL(1))" title="关于我们">
<img src="@(about?.Pic)" alt="关于我们">
</a>
</div>
@@ -186,7 +186,7 @@
<p>
@(Utils.CutString(Utils.NoHTML(about?.Content), 700))
</p>
<a href="/Article/detail/1" title="查看详情" class="read-d">查看详情</a>
<a href="@(ViewsHelper.EchoArticleURL(1))" title="查看详情" class="read-d">查看详情</a>
</div>
</div>
</div>
@@ -210,7 +210,7 @@
@foreach(var p in listPorducts)
{
<li>
<a asp-controller="Product" asp-action="Detail" asp-route-id="@(p.Id)" title="@(p.Title)">
<a href="@ViewsHelper.EchoURL(p)" title="@(p.Title)">
<div class="i-pro-top">
<div class="i-pro-pic">
<div class="pic-box">
@@ -259,7 +259,7 @@
}
</script>
<a asp-controller="Product" asp-action="Index" asp-route-id="1" title="查看更多" class="read-d">查看更多<i></i></a>
<a href="@ViewsHelper.EchoCategoryURL(1)" title="查看更多" class="read-d">查看更多<i></i></a>
</div>
</div>
@@ -289,7 +289,7 @@
@if (listNews1.Count > 0)
{
<div class="i-news-left">
<a href="/article/detail/@listNews1[0].Id" title="@listNews1[0].Title">
<a href="@(ViewsHelper.EchoURL(listNews1[0]))" title="@listNews1[0].Title">
<div class="i-news-pic">
<div class="pic-box">
<img src="@listNews1[0].Pic" alt="@listNews1[0].Title">
@@ -312,7 +312,7 @@
{
<ul class="i-news-list">
@for(int i=1; i < listNews1.Count; i++) { <li>
<a href="/article/detail/@listNews1[i].Id" title="@listNews1[i].Title">
<a href="@(ViewsHelper.EchoURL(listNews1[i]))" title="@listNews1[i].Title">
<div class="i-news-time">
<div class="pic-box">
<p>
@@ -343,7 +343,7 @@
@if (listNews2.Count > 0)
{
<div class="i-news-left">
<a href="/article/detail/@listNews2[0].Id" title="@listNews2[0].Title">
<a href="@(ViewsHelper.EchoURL(listNews2[0]))" title="@listNews2[0].Title">
<div class="i-news-pic">
<div class="pic-box">
<img src="@listNews2[0].Pic" alt="@listNews2[0].Title">
@@ -367,7 +367,7 @@
{
<ul class="i-news-list">
@for (int i = 1; i < listNews2.Count; i++) { <li>
<a href="/article/detail/@listNews2[i].Id" title="@listNews2[i].Title">
<a href="@(ViewsHelper.EchoURL(listNews2[i]))" title="@listNews2[i].Title">
<div class="i-news-time">
<div class="pic-box">
<p>
+1 -1
View File
@@ -33,7 +33,7 @@
<ul class="sec-nav-list">
@foreach (var k in sameList)
{
<li class="@(k.Id == Model.KId?"sec-on":"")"><a asp-controller="Product" asp-action="Index" asp-route-id="@(k.Id)" title="@k.KindName">@k.KindName</a></li>
<li class="@(k.Id == Model.KId?"sec-on":"")"><a href="@ViewsHelper.EchoURL(k)" title="@k.KindName">@k.KindName</a></li>
}
</ul>
+2 -2
View File
@@ -33,7 +33,7 @@
<ul class="sec-nav-list">
@foreach (var k in sameList)
{
<li class="@(k.Id == Model.Id?"sec-on":"")"><a asp-controller="Product" asp-action="Index" asp-route-id="@(k.Id)" title="@k.KindName">@k.KindName</a></li>
<li class="@(k.Id == Model.Id?"sec-on":"")"><a href="@ViewsHelper.EchoURL(k)" title="@k.KindName">@k.KindName</a></li>
}
</ul>
@@ -61,7 +61,7 @@
@foreach (Product p in ViewBag.list)
{
<li>
<a asp-controller="Product" asp-action="Detail" asp-route-id="@(p.Id)" title="@p.Title">
<a href="@ViewsHelper.EchoURL(p)" title="@p.Title">
<div class="pro-pic">
<div class="pic-box">
<img src="@p.Pic" alt="@p.Title">
+1 -1
View File
@@ -211,7 +211,7 @@
</div>
<div class="foot-bottom">
<div class="cont">
<span>@ViewBag.cfg.Copyright <a href="http://www.comcms.com/" target="_blank"> 技术支持:COMCMS</a>&nbsp;<a href="http://www.miitbeian.gov.cn/" target="_blank">粤ICP备8888888号-1</a> Powered by .NET 5.0 on @COMCMS.Common.Utils.GetOSPlatform() Server</span>
<span>@ViewBag.cfg.Copyright <a href="http://www.comcms.com/" target="_blank"> 技术支持:COMCMS</a>&nbsp;<a href="http://www.miitbeian.gov.cn/" target="_blank">粤ICP备8888888号-1</a> Powered by .NET 8.0 on @COMCMS.Common.Utils.GetOSPlatform() Server</span>
</div>
</div>
</div>