增加文章栏目伪静态规则1

This commit is contained in:
comm5v8
2019-05-25 17:26:40 +08:00
parent 34fdb431d4
commit 993de032b9
9 changed files with 206 additions and 34 deletions
@@ -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<Article> 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 = "修改文章栏目成功";
@@ -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" required aria-required="true" value="@Model.FilePath" placeholder="填写栏目路径,SEO优化使用,最多支持4级目录,可以输入字母、数字和-">
</div>
</div>
<div class="form-group">
@@ -37,12 +43,7 @@
<input id="SubTitle" type="text" class="form-control" name="SubTitle" placeholder="栏目副标题,非必填" value="@Model.SubTitle" maxlength="200">
</div>
</div>
<div class="form-group" style="display:none">
<label class="col-sm-3 control-label">栏目优化名称:</label>
<div class="col-sm-8">
<input id="KindDomain" name="KindDomain" maxlength="200" type="text" class="form-control" value="@Model.KindDomain" aria-required="true" placeholder="栏目优化名称,请填写英文或数字或-">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Banner图片:</label>
<div class="col-sm-8">
@@ -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 });
}
});
}
}
</script>
+29
View File
@@ -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
{
/// <summary>
/// 识图方法
/// </summary>
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
}
}
+5 -7
View File
@@ -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
+42 -16
View File
@@ -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 系统文章栏目、商品栏目路由
/// <summary>
/// 一级路径栏目
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
[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
}
+46
View File
@@ -0,0 +1,46 @@
@{
Layout = null;
ViewBag.Title = "信息提示";
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title</title>
<link href="~/lib/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="~/hplus/css/style.css" rel="stylesheet" />
<link href="~/hplus/css/font-awesome.min.css" rel="stylesheet" />
<link href="~/hplus/css/animate.min.css" rel="stylesheet" />
<link href="~/hplus/css/login.css" rel="stylesheet" />
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>@ViewBag.Title</h5>
<div class="ibox-tools">
</div>
</div>
<div class="ibox-content">
<h2>
<i class="fa fa-info-circle"></i> 信息提示<br />
</h2>
<h3>
@ViewBag.Message
</h3>
<p class="text-center">
<a class="btn btn-primary" href="/">返回首页</a>
</p>
</div>
</div>
</div>
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
</body>
</html>
+1
View File
@@ -3,4 +3,5 @@
@using COMCMS.Core
@using COMCMS.Common
@using XCode
@using COMCMS.Web.Common
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers