From 3f993c838f859335e9bc1e86574a1920a3d47c26 Mon Sep 17 00:00:00 2001 From: "DESKTOP-M4V1LH5\\Jin" Date: Wed, 15 Jul 2020 19:21:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8E=E5=8F=B0=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E9=97=AE=E9=A2=98=EF=BC=8C=E8=B0=83=E6=95=B4=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E5=88=97=E8=A1=A8=E6=89=B9=E9=87=8F=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E4=BE=8B=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COMCMS.Core/Core/管理员.Biz.cs | 5 +- .../AdminCP/Controllers/ArticleController.cs | 46 +++++++ .../AdminCP/Controllers/AttachController.cs | 58 +++++++++ .../AdminCP/Controllers/UploadController.cs | 6 +- .../AdminCP/Views/Article/AddArticle.cshtml | 5 +- .../AdminCP/Views/Article/ArticleList.cshtml | 113 ++---------------- .../AdminCP/Views/Index/NotAuthorize.cshtml | 14 +-- .../AdminCP/Views/Shared/_CommonLayout.cshtml | 18 +-- COMCMS.Web/Common/MyAuthorizeAttribute.cs | 6 +- COMCMS.Web/wwwroot/js/rtpost.js | 58 ++++++++- 10 files changed, 196 insertions(+), 133 deletions(-) create mode 100644 COMCMS.Web/Areas/AdminCP/Controllers/AttachController.cs diff --git a/COMCMS.Core/Core/管理员.Biz.cs b/COMCMS.Core/Core/管理员.Biz.cs index 84a8435..2312d4f 100644 --- a/COMCMS.Core/Core/管理员.Biz.cs +++ b/COMCMS.Core/Core/管理员.Biz.cs @@ -424,7 +424,10 @@ namespace COMCMS.Core AdminLog log = AdminLog.FindByGUID(adminLogId); if (log != null) { - log.Actions = log.Actions + $"|||{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}: {action}"; + if (string.IsNullOrEmpty(log.Actions)) + log.Actions = $"{DateTime.Now:yyyy-MM-dd HH:mm}: {action}"; + else + log.Actions = log.Actions + $"|||{DateTime.Now:yyyy-MM-dd HH:mm}: {action}"; log.LastUpdateTime = DateTime.Now; log.Update(); diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs index 9d66dbf..9d9ed5d 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/ArticleController.cs @@ -717,5 +717,51 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers return Json(tip); } #endregion + + #region 批量删除文章 + [HttpPost] + [MyAuthorize("batch", "article", "JSON")] + public IActionResult DoBatchDelArticle(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.Delete(); + 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/AttachController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/AttachController.cs new file mode 100644 index 0000000..3e775e6 --- /dev/null +++ b/COMCMS.Web/Areas/AdminCP/Controllers/AttachController.cs @@ -0,0 +1,58 @@ +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; +using COMCMS.Web.Models; +using Microsoft.AspNetCore.Hosting; +using COMCMS.Core.Models; +using Microsoft.Extensions.Options; +using System.IO; + +namespace COMCMS.Web.Areas.AdminCP.Controllers +{ + public class AttachController : AdminBaseController + { + private readonly SystemSetting _attachsetting; + private IWebHostEnvironment _env; + private AttachConfigEntity attach; + public AttachController(IWebHostEnvironment env, IOptions attachsetting) + { + attach = Config.GetSystemConfig().AttachConfigEntity; + _env = env; + _attachsetting = attachsetting.Value; + } + + + + #region 附件管理 + [HttpGet] + [MyAuthorize("viewlist", "attach")] + public IActionResult AttachList() + { + return View(); + } + #endregion + + #region 获取附件所有目录 + [HttpPost] + [MyAuthorize("viewlist", "attach","JSON")] + public IActionResult GetDirList(string subdir) + { + string attachPath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}{attach.AttachPatch}{Path.DirectorySeparatorChar}"; + + + + //Directory.GetDirectories() + return Json(tip); + } + #endregion + } +} diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/UploadController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/UploadController.cs index 6fe4439..f46b309 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/UploadController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/UploadController.cs @@ -74,7 +74,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers return Json(errorJson); } //判断是否是图片类型 - List imgtypelist = new List { "image/pjpeg", "image/png", "image/x-png", "image/gif", "image/bmp", "image/jpeg" }; + List imgtypelist = new List { "image/jpg", "image/png", "image/x-png", "image/gif", "image/bmp", "image/jpeg" }; if (imgtypelist.FindIndex(x => x == upload.ContentType) == -1) { errorJson.error.message = "请选择一张图片!"; @@ -244,7 +244,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers //判断是否是图片,如果是图片,后面需要生成缩略图并可能的话,就加上水印 bool isImage = false; //判断是否是图片类型 - List imgtypelist = new List { "image/pjpeg", "image/png", "image/x-png", "image/gif", "image/bmp" }; + List imgtypelist = new List { "image/jpg", "image/png", "image/x-png", "image/gif", "image/bmp", "image/jpeg" }; if (imgtypelist.FindIndex(x => x == upload.ContentType) >= 0) { isImage = true; @@ -556,7 +556,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers if (data != null) { //判断是否是图片类型 - List imgtypelist = new List { "image/pjpeg", "image/png", "image/x-png", "image/gif", "image/bmp", "image/jpeg" }; + List imgtypelist = new List { "image/jpg", "image/png", "image/x-png", "image/gif", "image/bmp", "image/jpeg" }; if (imgtypelist.FindIndex(x => x == data.ContentType) == -1) { msg = "只能上传一张图片格式文件!"; diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticle.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticle.cshtml index b0de8c6..4ecfca0 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticle.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/AddArticle.cshtml @@ -11,8 +11,7 @@
- @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "addArticleForm", @class = "form-horizontal m-t" })) - { +
@@ -156,7 +155,7 @@
- } +
diff --git a/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml index 6d0c26b..6d31649 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Article/ArticleList.cshtml @@ -42,20 +42,16 @@ } - - - @* - *@ +
@@ -106,7 +102,7 @@ pageNumber: 1, //初始化加载第一页,默认第一页 pageSize: 25, //每页的记录行数(*) pageList: [10, 25, 50, 100], //可供选择的每页的行数(*) - search: true, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大 + search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大 strictSearch: true, showColumns: true, //是否显示所有的列 showRefresh: true, //是否显示刷新按钮 @@ -164,8 +160,9 @@ var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的 limit: params.limit, //页面大小 page: (params.offset / params.limit)+1, //页码 - kid:$("#kid").val(), - departmentname: $("#keyword").val() + kid: $("#kid").val(), + keyword: $("#keyword").val(), + isshowsub: $("#isshowsub").prop("checked") ? 1 : 0 }; return temp; }; @@ -213,92 +210,6 @@ 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/Index/NotAuthorize.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Index/NotAuthorize.cshtml index a806a90..a9fe343 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Index/NotAuthorize.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Index/NotAuthorize.cshtml @@ -26,12 +26,12 @@ - - - - - - - + + + + + + + \ No newline at end of file diff --git a/COMCMS.Web/Areas/AdminCP/Views/Shared/_CommonLayout.cshtml b/COMCMS.Web/Areas/AdminCP/Views/Shared/_CommonLayout.cshtml index 16fd962..f1dec41 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/Shared/_CommonLayout.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/Shared/_CommonLayout.cshtml @@ -22,7 +22,7 @@ - + @@ -38,23 +38,13 @@ - - + + - + diff --git a/COMCMS.Web/Common/MyAuthorizeAttribute.cs b/COMCMS.Web/Common/MyAuthorizeAttribute.cs index 6198ed6..79585c5 100644 --- a/COMCMS.Web/Common/MyAuthorizeAttribute.cs +++ b/COMCMS.Web/Common/MyAuthorizeAttribute.cs @@ -14,7 +14,7 @@ namespace COMCMS.Web.Common /// /// 后台授权过滤器 /// - public class MyAuthorizeAttribute : ResultFilterAttribute + public class MyAuthorizeAttribute : Attribute, IAuthorizationFilter { /// /// 菜单key @@ -35,7 +35,7 @@ namespace COMCMS.Web.Common _returnType = !string.IsNullOrWhiteSpace(returnType) && returnType.ToLower() == "json" ? "JSON" : "HTML"; } - public override void OnResultExecuting(ResultExecutingContext context) + public void OnAuthorization(AuthorizationFilterContext context) { bool isOK = false; if (Admin.IsAdminLogin()) @@ -89,7 +89,7 @@ namespace COMCMS.Web.Common } } } - base.OnResultExecuting(context); + //base.OnResultExecuting(context); } } } diff --git a/COMCMS.Web/wwwroot/js/rtpost.js b/COMCMS.Web/wwwroot/js/rtpost.js index a86898a..570d4a1 100644 --- a/COMCMS.Web/wwwroot/js/rtpost.js +++ b/COMCMS.Web/wwwroot/js/rtpost.js @@ -1,4 +1,4 @@ -//所有异步提交 formId 不需要加上# last:2015-11-12 by Hogen Wang +//所有异步提交 formId 不需要加上# last:2020-07-15 by Hogen Wang //依赖jquery jquery.form jquery.validate jquery.metadata function DoPost(formId, rules, messages) { //提交地址 @@ -348,4 +348,60 @@ function DoAdminLogin(formId, rules, messages) { } }); return false; +} + + +//后台列表执行批量操作 +function doBatchAction(url, title) { + 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); + } + }) + + layer.confirm('确认要执行批量' + title + '吗?', { + icon: 3, + title: '系统提示', + btn: ['确定', '取消 '] //按钮 + }, function () { + var loading = layer.load(0, { + shade: [0.2, '#000'] //0.1透明度的背景 + }); + $.ajax({ + type: "POST", + url: url, + 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 () { + //执行重新载入 + if (doSearch) { + doSearch(); + } else { + refreshCurrentTab(); + } + }); + } else { + layer.close(loading); + layer.alert(data.message, { icon: 2 }); + + } + }, + error: function () { + layer.close(loading); + layer.alert('执行错误,请联系管理员!', { icon: 2 }); + } + }); + }, function () { + }); } \ No newline at end of file