增加文章、商品列表修改排序功能

This commit is contained in:
2021-01-11 00:21:24 +08:00
parent 7ed117d054
commit 372265d89a
8 changed files with 183 additions and 26 deletions
@@ -691,6 +691,26 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
} }
#endregion #endregion
#region 修改文章排序
[HttpPost]
[MyAuthorize("edit", "article", "JSON")]
public IActionResult DoEditArticleSequence(int id, int rank)
{
Article entity = Article.Find(Article._.Id == id);
if (entity == null)
{
tip.Message = "系统找不到本记录";
return Json(tip);
}
entity.Sequence = rank;
entity.Update();
Admin.WriteLogActions($"修改文章排序(id:{id},排序:{rank});");
tip.Message = "修改排序成功!";
tip.Status = JsonTip.SUCCESS;
return Json(tip);
}
#endregion
#region 迁移文章 #region 迁移文章
[HttpGet] [HttpGet]
[MyAuthorize("batch", "article")] [MyAuthorize("batch", "article")]
@@ -290,6 +290,26 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
} }
#endregion #endregion
#region 修改商品排序
[HttpPost]
[MyAuthorize("edit", "product", "JSON")]
public IActionResult DoEditProductSequence(int id, int rank)
{
Product entity = Product.Find(Product._.Id == id);
if (entity == null)
{
tip.Message = "系统找不到本记录";
return Json(tip);
}
entity.Sequence = rank;
entity.Update();
Admin.WriteLogActions($"修改商品排序(id:{id},排序:{rank});");
tip.Message = "修改排序成功!";
tip.Status = JsonTip.SUCCESS;
return Json(tip);
}
#endregion
#region 添加商品 #region 添加商品
[HttpGet] [HttpGet]
[MyAuthorize("add", "product")] [MyAuthorize("add", "product")]
@@ -25,7 +25,7 @@
<tr> <tr>
<th>栏目名称</th> <th>栏目名称</th>
<th>ID</th> <th>ID</th>
<th class="text-center" style="width:140px">排序</th> <th class="text-center" style="width:130px">排序</th>
<th class="text-center">文章数量</th> <th class="text-center">文章数量</th>
<th class="text-center">隐藏</th> <th class="text-center">隐藏</th>
<th width="200">操作</th> <th width="200">操作</th>
@@ -70,10 +70,10 @@
return false; return false;
} }
//console.log(rank); //console.log(rank);
//if (!isIntNum(rank)) { if (!isInt(rank)) {
// layer.alert("排序只能是数字!", { icon: 2 }); layer.alert("排序只能是数字!", { icon: 2 });
// return false; return false;
//} }
var loading = layer.load(0, { var loading = layer.load(0, {
shade: [0.2, '#000'] //0.1透明度的背景 shade: [0.2, '#000'] //0.1透明度的背景
}); });
@@ -142,33 +142,45 @@
title: '所属栏目' title: '所属栏目'
}, { }, {
field: 'title', field: 'title',
title: '文章标题' title: '文章标题',
formatter: function (value, row, index) {
return '<a href="/Article/Detail/' + row["id"] + '" target="_blank" title="新窗口打开预览文章">' + value + '</a>'
}
}, { }, {
field: 'sequence', field: 'sequence',
title: '排序' title: '排序',
width: 130,
formatter: function (value, row, index) {
return '<div class="input-group"><input type="number" class="form-control" id="ac_rank_' + row["id"] + '" name="ac_rank_' + row["id"] + '" value="' + value + '" placeholder="请输入一个数字,越小排越前"><a class="input-group-addon btn btn-primary" title="修改保存" href="javascript:;" onclick="doSaveSequence(' + row["id"] + ')"><i class="fa fa-save"></i></a></div>'
}
}, { }, {
field: 'addTime', field: 'addTime',
title: '添加时间' title: '添加时间',
width:150
}, { }, {
field: 'isNew', field: 'isNew',
title: '最新', title: '最新',
align: 'center', align: 'center',
formatter: 'newFormatter' formatter: 'newFormatter',
width: 65
}, { }, {
field: 'isRecommend', field: 'isRecommend',
title: '推荐', title: '推荐',
align: 'center', align: 'center',
formatter: 'recommendFormatter' formatter: 'recommendFormatter',
width: 65
}, { }, {
field: 'isHide', field: 'isHide',
title: '隐藏', title: '隐藏',
align: 'center', align: 'center',
formatter: 'hideFormatter' formatter: 'hideFormatter',
width: 65
}, },
{ {
field: 'id', field: 'id',
title: '操作', title: '操作',
formatter: 'actionFormatter' formatter: 'actionFormatter',
width:140
} }
] ]
}); });
@@ -228,7 +240,45 @@
}; };
return oInit; return oInit;
}; };
function doSaveSequence(id) {
var rank = $("#ac_rank_" + id).val();
if (rank == '') {
layer.alert("请输入排序!", { icon: 2 });
return false;
}
//console.log(rank);
if (!isInt(rank)) {
layer.alert("排序只能是数字!", { icon: 2 });
return false;
}
var loading = layer.load(0, {
shade: [0.2, '#000'] //0.1透明度的背景
});
$.ajax({
type: "POST",
url: "/AdminCP/Article/DoEditArticleSequence",
data: { id: id, rank: rank },
dataType: "JSON",
success: function (data) {
if (data.status == "success") {
layer.close(loading);
layer.msg(data.message, {
time: 1000 //2秒关闭(如果不配置,默认是3秒)
}, function () {
//window.location.href = window.location.href;
});
} else {
layer.close(loading);
layer.alert(data.message, { icon: 2 });
}
},
error: function () {
layer.close(loading);
layer.alert('执行错误,请联系管理员!', { icon: 2 });
}
});
}
</script> </script>
</div> </div>
</div> </div>
@@ -111,7 +111,7 @@
pageNumber: 1, //初始化加载第一页,默认第一页 pageNumber: 1, //初始化加载第一页,默认第一页
pageSize: 25, //每页的记录行数(*) pageSize: 25, //每页的记录行数(*)
pageList: [10, 25, 50, 100], //可供选择的每页的行数(*) pageList: [10, 25, 50, 100], //可供选择的每页的行数(*)
search: true, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大 search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
strictSearch: true, strictSearch: true,
showColumns: true, //是否显示所有的列 showColumns: true, //是否显示所有的列
showRefresh: true, //是否显示刷新按钮 showRefresh: true, //是否显示刷新按钮
@@ -132,37 +132,47 @@
title: '所属分类' title: '所属分类'
}, { }, {
field: 'Title', field: 'Title',
title: '商品标题' title: '商品标题',
}, { }, {
field: 'Price', field: 'Price',
title: '商品价格' title: '商品价格'
}, },
{ {
field: 'Sequence', field: 'Sequence',
title: '排序' title: '排序',
width: 130,
formatter: function (value, row, index) {
return '<div class="input-group"><input type="number" class="form-control" id="ac_rank_' + row["Id"] + '" name="ac_rank_' + row["Id"] + '" value="' + value + '" placeholder="请输入一个数字,越小排越前"><a class="input-group-addon btn btn-primary" title="修改保存" href="javascript:;" onclick="doSaveSequence(' + row["Id"] + ')"><i class="fa fa-save"></i></a></div>'
}
}, { }, {
field: 'AddTime', field: 'AddTime',
title: '添加时间' title: '添加时间',
width: 150
}, { }, {
field: 'IsNew', field: 'IsNew',
title: '最新', title: '最新',
align: 'center', align: 'center',
formatter: 'newFormatter' formatter: 'newFormatter',
width: 65
}, { }, {
field: 'IsRecommend', field: 'IsRecommend',
title: '推荐', title: '推荐',
align: 'center', align: 'center',
formatter: 'recommendFormatter' formatter: 'recommendFormatter',
width: 65
}, { }, {
field: 'IsHide', field: 'IsHide',
title: '隐藏', title: '隐藏',
align: 'center', align: 'center',
formatter: 'hideFormatter' formatter: 'hideFormatter',
width: 65
}, },
{ {
field: 'Id', field: 'Id',
title: '操作', title: '操作',
formatter: 'actionFormatter' formatter: 'actionFormatter',
width: 140
} }
] ]
}); });
@@ -223,7 +233,45 @@
}; };
return oInit; return oInit;
}; };
function doSaveSequence(id) {
var rank = $("#ac_rank_" + id).val();
if (rank == '') {
layer.alert("请输入排序!", { icon: 2 });
return false;
}
//console.log(rank);
if (!isInt(rank)) {
layer.alert("排序只能是数字!", { icon: 2 });
return false;
}
var loading = layer.load(0, {
shade: [0.2, '#000'] //0.1透明度的背景
});
$.ajax({
type: "POST",
url: "/AdminCP/Product/DoEditProductSequence",
data: { id: id, rank: rank },
dataType: "JSON",
success: function (data) {
if (data.status == "success") {
layer.close(loading);
layer.msg(data.message, {
time: 1000 //2秒关闭(如果不配置,默认是3秒)
}, function () {
//window.location.href = window.location.href;
});
} else {
layer.close(loading);
layer.alert(data.message, { icon: 2 });
}
},
error: function () {
layer.close(loading);
layer.alert('执行错误,请联系管理员!', { icon: 2 });
}
});
}
</script> </script>
</div> </div>
</div> </div>
@@ -98,11 +98,13 @@
if ($(this).attr("placeholder") && $(this).attr("placeholder") != "") { if ($(this).attr("placeholder") && $(this).attr("placeholder") != "") {
var tipstr = $(this).attr("placeholder"); var tipstr = $(this).attr("placeholder");
var id = $(this).attr("id"); var id = $(this).attr("id");
$(this).on("focusin", function () { if (id) {
layer.tips(tipstr, '#' + id, { $(this).on("focusin", function () {
tips: [1, '#3595CC'] //还可配置颜色 layer.tips(tipstr, '#' + id, {
tips: [1, '#3595CC'] //还可配置颜色
});
}); });
}); }
} }
}) })
</script> </script>
@@ -109,6 +109,10 @@ namespace COMCMS.Web.Controllers
{ {
return AlertAndGoBack("系统找不到本记录!"); return AlertAndGoBack("系统找不到本记录!");
} }
if (entity.IsHide == 1 && !Admin.IsAdminLogin())
{
return EchoTip("系统找不到本文章!");
}
ArticleCategory kind = ArticleCategory.FindById(entity.KId); ArticleCategory kind = ArticleCategory.FindById(entity.KId);
if (kind == null) if (kind == null)
{ {
+13
View File
@@ -38,3 +38,16 @@ function cancelEdit(id) {
$("#row_" + id + " .rt-editpanel").show(); $("#row_" + id + " .rt-editpanel").show();
$("#row_" + id + " .rt-savepanel").addClass('hidden'); $("#row_" + id + " .rt-savepanel").addClass('hidden');
} }
/*********
验证是否是数字
**********/
function isInt(str) {
//如果为空,则通过校验
if (str == "")
return false;
if (/^(\-?)(\d+)$/.test(str))
return true;
else
return false;
}