初步更新文章栏目路径功能

This commit is contained in:
comm5v8
2019-05-21 21:46:16 +08:00
parent ecc0c97c66
commit 34fdb431d4
96 changed files with 24881 additions and 162 deletions
@@ -65,6 +65,34 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
tip.Message = "文章栏目标题不能为空!";
return Json(tip);
}
if (string.IsNullOrEmpty(model.FilePath))
{
tip.Message = "文章栏目路径不能为空!";
return Json(tip);
}
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 (!AdminUtils.CheckFilePathIsOK(model.FilePath, 0, 0))
{
tip.Message = "栏目路径不可用,请重新填写!";
return Json(tip);
}
model.Insert();
Core.Admin.WriteLogActions("添加文章栏目(id:" + model.Id + ");");
tip.Status = JsonTip.SUCCESS;
@@ -127,6 +155,32 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
Json(tip);
}
if (string.IsNullOrEmpty(model.FilePath))
{
tip.Message = "文章栏目路径不能为空!";
return Json(tip);
}
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 (!AdminUtils.CheckFilePathIsOK(model.FilePath, entity.Id, 0))
{
tip.Message = "栏目路径不可用,请重新填写!";
return Json(tip);
}
if (entity.PId != model.PId)
{
if (entity.Id == model.PId)
@@ -171,6 +225,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
entity.KindDomain = model.KindDomain;
entity.Rank = model.Rank;
entity.Pic = model.Pic;
model.FilePath = model.FilePath;
entity.Save();
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using COMCMS.Common;
using COMCMS.Core;
using XCode;
using Newtonsoft.Json;
using COMCMS.Web.Common;
using Microsoft.AspNetCore.Http;
namespace COMCMS.Web.Areas.AdminCP.Controllers
{
public class ServerController : AdminBaseController
{
#region 中文转拼音
public IActionResult Hanzi2Pinyin(string name)
{
string pinyin = "";
if (!string.IsNullOrEmpty(name))
{
pinyin = PinYinHelper.GetPinyin(name).ToLower().Replace(" ","-");
}
tip.Status = JsonTip.SUCCESS;
tip.Message = pinyin;
return Json(tip);
}
#endregion
}
}
@@ -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" 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" required aria-required="true" placeholder="填写栏目路径,SEO优化使用,最多支持4级目录,可以输入字母、数字和-">
</div>
</div>
<div class="form-group">
@@ -154,4 +160,28 @@
DoPost("addArticleKindForm");
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>
+8 -8
View File
@@ -5,18 +5,18 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MailKit" Version="2.1.4" />
<PackageReference Include="MailKit" Version="2.1.5.1" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="MimeKit" Version="2.1.4" />
<PackageReference Include="MimeKit" Version="2.1.5.1" />
<PackageReference Include="MySql.Data" Version="8.0.16" />
<PackageReference Include="NewLife.XCode" Version="9.11.2019.415" />
<PackageReference Include="NewLife.XCode" Version="9.11.2019.510" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Senparc.Weixin" Version="6.3.11" />
<PackageReference Include="Senparc.Weixin.MP" Version="16.6.15" />
<PackageReference Include="Senparc.Weixin.TenPay" Version="1.2.1" />
<PackageReference Include="Senparc.Weixin.WxOpen" Version="3.3.10" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
<PackageReference Include="Senparc.Weixin" Version="6.4.3" />
<PackageReference Include="Senparc.Weixin.MP" Version="16.7.4.2" />
<PackageReference Include="Senparc.Weixin.TenPay" Version="1.3.0.1" />
<PackageReference Include="Senparc.Weixin.WxOpen" Version="3.4.2.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
<PackageReference Include="ZKWeb.System.Drawing" Version="4.0.1" />
</ItemGroup>
+43
View File
@@ -54,5 +54,48 @@ namespace COMCMS.Web.Common
}
#endregion
#region 判断文章栏目或者商品栏目,栏目路径是否已经存在
/// <summary>
/// 判断路径名称是否合法
/// </summary>
/// <param name="pathname"></param>
/// <param name="kid">id,大于0是修改</param>
/// <param name="typeid">类型,0文章,1商品</param>
/// <returns></returns>
public static bool CheckFilePathIsOK(string pathname, int kid, int typeid)
{
bool flag = true;
if (string.IsNullOrEmpty(pathname))
{
return false;
}
if(typeid ==0)//文章
{
if (ArticleCategory.FindCount(ArticleCategory._.FilePath == pathname & ArticleCategory._.Id != kid, null, null, 0, 0) > 0)
{
return false;
}
if (Category.FindCount(Category._.FilePath == pathname, null, null, 0, 0) > 0)
{
return false;
}
}
else if(typeid == 1)
{
if (ArticleCategory.FindCount(ArticleCategory._.FilePath == pathname , null, null, 0, 0) > 0)
{
return false;
}
if (Category.FindCount(Category._.FilePath == pathname & Category._.Id != kid, null, null, 0, 0) > 0)
{
return false;
}
}
return flag;
}
#endregion
}
}
+21 -3
View File
@@ -47,12 +47,30 @@ namespace COMCMS.Web.Controllers
}
#region 测试
[Route("{path:regex([[a-zA-Z-/]])}/index.html")]
public IActionResult Test(string path="")
[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);
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 测试拼音
public IActionResult Test3()
{
return Content(PinYinHelper.GetPinyin("关于 我们about us") + "|" + PinYinHelper.GetFirstPinyin("关于 我们") + "||" + "/sd/dsd/sd/sd/sd/sd".Count(x => x == '/'));
}
#endregion
#region 系统文章、商品路由
#endregion
}