From e181e2b568dc97408b0944fb2452be5176ca910e Mon Sep 17 00:00:00 2001 From: comm5v8 Date: Fri, 17 May 2019 14:56:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=90=8E=E5=8F=B0=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E8=B6=85=E6=97=B6=E6=93=8D=E4=BD=9C=EF=BC=9B=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E7=B3=BB=E7=BB=9F=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=EF=BC=9B=E6=89=B9=E9=87=8F=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E5=92=8C=E6=98=BE=E7=A4=BA=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminCP/Controllers/ArticleController.cs | 126 ++++++++++++++++++ .../AdminCP/Controllers/LoginController.cs | 11 +- .../AdminCP/Views/Article/ArticleList.cshtml | 116 ++++++++++++++-- .../Views/Article/EditArticleCategory.cshtml | 6 + .../AdminCP/Views/Article/MoveArticle.cshtml | 58 ++++++++ COMCMS.Web/wwwroot/js/rtpost.js | 12 +- XCoder/data.project.xml | 2 +- 7 files changed, 316 insertions(+), 15 deletions(-) create mode 100644 COMCMS.Web/Areas/AdminCP/Views/Article/MoveArticle.cshtml diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs index 4c6f9d5..479d442 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs @@ -466,5 +466,131 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers return Json(tip); } #endregion + + #region 迁移文章 + [HttpGet] + [MyAuthorize("batch", "article")] + public IActionResult MoveArticle() + { + //获取上级栏目 + IList list = ArticleCategory.GetListTree(0, -1, true, false); + ViewBag.ListKinds = list; + return View(); + } + [HttpPost] + [MyAuthorize("batch", "article", "JSON")] + public IActionResult MoveArticle(int from, int to) + { + if (from <= 0 || to <= 0) + { + tip.Message = "请选择好栏目"; + return Json(tip); + } + if (from == to) + { + tip.Message = "迁移前后栏目一致,无法迁移"; + return Json(tip); + } + Article.Update("KId=" + to, "KId=" + from); + Core.Admin.WriteLogActions("迁移文章(from:" + from + ",to:" + to + ");"); + tip.Status = JsonTip.SUCCESS; + tip.Message = "迁移文章成功"; + tip.ReturnUrl = "close"; + return Json(tip); + } + #endregion + + #region 批量隐藏文章 + [HttpPost] + [MyAuthorize("batch", "article", "JSON")] + public IActionResult DoBatchHideArticle(string ids) + { + if (string.IsNullOrEmpty(ids)) + { + tip.Message = "请最少选择一篇文章!"; + return Json(tip); + } + List listIds = new List(); + try + { + listIds = JsonConvert.DeserializeObject>(ids); + } + catch (Exception ex) + { + tip.Message = "转换出错:" + ex.Message; + return Json(tip); + } + + if (listIds == null || listIds.Count < 1) + { + tip.Message = "请至少选择一篇文章!"; + return Json(tip); + } + + IList
list = Article.FindAll(Article._.Id.In(listIds), null, null, 0, 0); + if (list == null || list.Count < 1) + { + tip.Message = "请至少选择一篇文章!"; + return Json(tip); + } + + foreach (var item in list) + { + item.IsHide = 1; + } + + list.Update(); + Admin.WriteLogActions($"批量隐藏文章:{ids};"); + tip.Message = "批量隐藏文章成功!"; + tip.Status = JsonTip.SUCCESS; + return Json(tip); + } + #endregion + + #region 批量显示文章 + [HttpPost] + [MyAuthorize("batch", "article", "JSON")] + public IActionResult DoBatchShowArticle(string ids) + { + if (string.IsNullOrEmpty(ids)) + { + tip.Message = "请最少选择一篇文章!"; + return Json(tip); + } + List listIds = new List(); + try + { + listIds = JsonConvert.DeserializeObject>(ids); + } + catch (Exception ex) + { + tip.Message = "转换出错:" + ex.Message; + return Json(tip); + } + + if (listIds == null || listIds.Count < 1) + { + tip.Message = "请至少选择一篇文章!"; + return Json(tip); + } + + IList
list = Article.FindAll(Article._.Id.In(listIds), null, null, 0, 0); + if (list == null || list.Count < 1) + { + tip.Message = "请至少选择一篇文章!"; + return Json(tip); + } + + foreach (var item in list) + { + item.IsHide = 0; + } + list.Update(); + Admin.WriteLogActions($"批量显示文章:{ids};"); + tip.Message = "批量显示文章成功!"; + tip.Status = JsonTip.SUCCESS; + return Json(tip); + } + #endregion } } \ No newline at end of file diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs index ebb20d2..b4074f1 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/LoginController.cs @@ -56,6 +56,12 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers } //判断并解密 string key = SessionHelper.GetSession("des_key").ToString(); + if (string.IsNullOrEmpty(key)) + { + tip.Message = "页面访问超时,请刷新页面重新登录!"; + tip.Other = "reload"; + return Json(tip); + } //解密 string username = ""; string password = ""; @@ -67,14 +73,15 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers catch (Exception exp) { NewLife.Log.XTrace.WriteException(exp); - tip.Message = "用户名或者密码错误!"; + tip.Message = "页面访问超时,请刷新页面重新登录!"; + tip.Other = "reload"; return Json(tip); } //验证用户 if (string.IsNullOrEmpty(username)) { - tip.Message = "请输入用户名!"+ key; + tip.Message = "请输入用户名!"; return Json(tip); } if (string.IsNullOrEmpty(password) || Utils.GetStringLength(password) < 5) diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml index 9b67e96..d192c3e 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml @@ -41,7 +41,15 @@ 新增 } - + + + @* @@ -105,45 +113,45 @@ minimumCountColumns: 2, //最少允许的列数 clickToSelect: true, //是否启用点击选中行 height: 0, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度 - uniqueId: "Id", //每一行的唯一标识,一般为主键列 + uniqueId: "id", //每一行的唯一标识,一般为主键列 showToggle: true, //是否显示详细视图和列表视图的切换按钮 cardView: false, //是否显示详细视图 detailView: false, //是否显示父子表 columns: [{ checkbox: true }, { - field: 'Id', + field: 'id', title: 'ID' }, { - field: 'ArticleKind.KindName', + field: 'articleKind.kindName', title: '所属栏目' }, { - field: 'Title', + field: 'title', title: '文章标题' }, { - field: 'Sequence', + field: 'sequence', title: '排序' }, { - field: 'AddTime', + field: 'addTime', title: '添加时间' }, { - field: 'IsNew', + field: 'isNew', title: '最新', align: 'center', formatter: 'newFormatter' }, { - field: 'IsRecommend', + field: 'isRecommend', title: '推荐', align: 'center', formatter: 'recommendFormatter' }, { - field: 'IsHide', + field: 'isHide', title: '隐藏', align: 'center', formatter: 'hideFormatter' }, { - field: 'Id', + field: 'id', title: '操作', formatter: 'actionFormatter' } @@ -205,6 +213,92 @@ return oInit; }; + function doBatchHide() { + var list = $('#tb_departments').bootstrapTable('getAllSelections'); + var ids = []; + if (!list || list.length <1) { + layer.alert("请至少选择一篇文章!", { icon: 2 }); + return false; + } + list.map(function (item, index) { + if (item.Id) { + ids.push(item.id); + } + }) + //alert(JSON.stringify(ids)); + //执行操作 + var loading = layer.load(0, { + shade: [0.2, '#000'] //0.1透明度的背景 + }); + $.ajax({ + type: "POST", + url: "/AdminCP/Article/DoBatchHideArticle", + data: { ids: JSON.stringify(ids)}, + dataType: "JSON", + success: function (data) { + if (data.status == "success") { + layer.close(loading); + layer.msg(data.message, { + time: 1000 //2秒关闭(如果不配置,默认是3秒) + }, function () { + doSearch(); + }); + } else { + layer.close(loading); + layer.alert(data.message, { icon: 2 }); + } + }, + error: function () { + layer.close(loading); + layer.alert('执行错误,请联系管理员!', { icon: 2 }); + } + }); + return false; + } + + function doBatchShow() { + var list = $('#tb_departments').bootstrapTable('getAllSelections'); + var ids = []; + if (!list || list.length <1) { + //alert('请至少选择一行!'); + layer.alert("请至少选择一篇文章!", { icon: 2 }); + return false; + } + list.map(function (item, index) { + if (item.Id) { + ids.push(item.id); + } + }) + //alert(JSON.stringify(ids)); + //执行操作 + var loading = layer.load(0, { + shade: [0.2, '#000'] //0.1透明度的背景 + }); + $.ajax({ + type: "POST", + url: "/AdminCP/Article/DoBatchShowArticle", + data: { ids: JSON.stringify(ids)}, + dataType: "JSON", + success: function (data) { + if (data.status == "success") { + layer.close(loading); + layer.msg(data.message, { + time: 1000 //2秒关闭(如果不配置,默认是3秒) + }, function () { + doSearch(); + }); + } else { + layer.close(loading); + layer.alert(data.message, { icon: 2 }); + } + }, + error: function () { + layer.close(loading); + layer.alert('执行错误,请联系管理员!', { icon: 2 }); + } + }); + return false; + } diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml index bc8c428..0c25aff 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/EditArticleCategory.cshtml @@ -37,6 +37,12 @@ +
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/MoveArticle.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/MoveArticle.cshtml new file mode 100644 index 0000000..11aae9d --- /dev/null +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/MoveArticle.cshtml @@ -0,0 +1,58 @@ +@{ + ViewBag.title = "批量迁移文章"; +} +
+
+
+
@ViewBag.Title
+
+
+
+
+ @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "moveArticleForm", @class = "form-horizontal m-t" })) + { +
+ 注意:请务必确认迁移栏目文章,本操作不可逆,请慎重操作! +
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ + +
+
+ } +
+
+ + +
+ \ No newline at end of file diff --git a/COMCMS.Web/wwwroot/js/rtpost.js b/COMCMS.Web/wwwroot/js/rtpost.js index 2560e7f..a86898a 100644 --- a/COMCMS.Web/wwwroot/js/rtpost.js +++ b/COMCMS.Web/wwwroot/js/rtpost.js @@ -325,7 +325,17 @@ function DoAdminLogin(formId, rules, messages) { }); } else { layer.close(loading); - layer.alert(data.message, { icon: 2 }); + if (data.other == "reload") { + layer.msg('页面访问超时,正在刷新页面,请重新登录!', function () { + //关闭后的操作 + setTimeout(function () { + window.location.href = window.location.href; + },1500) + }); + } else { + layer.alert(data.message, { icon: 2 }); + } + btn.removeAttr("disabled"); } }, diff --git a/XCoder/data.project.xml b/XCoder/data.project.xml index 1f4e256..84ae2a4 100644 --- a/XCoder/data.project.xml +++ b/XCoder/data.project.xml @@ -1,5 +1,5 @@ - +