From 00cf82092550632b4962b56e32358c55727f685e Mon Sep 17 00:00:00 2001 From: "DESKTOP-CLI22EN\\HogenWang" Date: Thu, 6 Aug 2020 01:16:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E4=B8=80=E5=8D=8A=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COMCMS.Core/Models/JsonTip.cs | 4 + .../Controllers/DataDictionaryController.cs | 143 ++++++++++++ .../AdminCP/Views/DataDictionary/Index.cshtml | 213 ++++++++++++++---- COMCMS.Web/wwwroot/hplus/js/common.js | 6 +- COMCMS.Web/wwwroot/js/rtpost.js | 43 ++-- 5 files changed, 345 insertions(+), 64 deletions(-) diff --git a/COMCMS.Core/Models/JsonTip.cs b/COMCMS.Core/Models/JsonTip.cs index 597c47a..a37c83d 100644 --- a/COMCMS.Core/Models/JsonTip.cs +++ b/COMCMS.Core/Models/JsonTip.cs @@ -45,6 +45,10 @@ namespace COMCMS.Core /// 返回URL /// public string ReturnUrl { get; set; } + /// + /// 其他详情 + /// + public object Detail { get; set; } /// /// 获取JSON字符串 diff --git a/COMCMS.Web/Areas/AdminCP/Controllers/DataDictionaryController.cs b/COMCMS.Web/Areas/AdminCP/Controllers/DataDictionaryController.cs index 4bcc2e7..4d36ec9 100644 --- a/COMCMS.Web/Areas/AdminCP/Controllers/DataDictionaryController.cs +++ b/COMCMS.Web/Areas/AdminCP/Controllers/DataDictionaryController.cs @@ -20,6 +20,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers [MyAuthorize("viewlist", "datadictionary")] public IActionResult Index() { + Admin.WriteLogActions($"查看数据字典页面;"); return View(); } #endregion @@ -53,5 +54,147 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers } #endregion + #region 获取数据字典 + [HttpPost] + [MyAuthorize("edit", "datadictionary", "JSON")] + public IActionResult GetDataDictionary(int id) + { + var entity = DataDictionary.Find(DataDictionary._.Id == id); + if(entity == null) + { + tip.Message = "系统找不到本记录!"; + return Json(tip); + } + var detail = new + { + id = entity.Id, + rank = entity.Rank, + description = entity.Description, + key = entity.Key + }; + tip.Detail = detail; + tip.Message = "获取成功!"; + tip.Status = JsonTip.SUCCESS; + Admin.WriteLogActions($"查看数据字典({entity.Id});"); + return Json(tip); + } + #endregion + + #region 保存(添加或者修改)数据字典 + [HttpPost] + [MyAuthorize("add", "datadictionary", "JSON")] + public IActionResult DoSaveDataDictionary(DataDictionary model) + { + if (string.IsNullOrEmpty(model.Key)) + { + tip.Message = "请输入字典Key"; + return Json(tip); + } + if(model.Id==0 && DataDictionary.FindCount(DataDictionary._.Key== model.Key, null, null, 0, 0) > 0) + { + tip.Message = "此字典Key已经存在,请填写其他的!"; + return Json(tip); + } + if(model.Id> 0 && DataDictionary.FindCount(DataDictionary._.Key == model.Key & DataDictionary._.Id !=model.Id, null, null, 0, 0) > 0) + { + tip.Message = "此字典Key已经存在,请填写其他的!"; + return Json(tip); + } + DataDictionary entity = null; + string tipMessage = ""; + if (model.Id > 0) + { + entity = DataDictionary.Find(DataDictionary._.Id == model.Id); + if(entity == null) + { + tip.Message = "系统找不到本记录!"; + return Json(tip); + } + tipMessage = "修改"; + } + else + { + entity = new DataDictionary(); + entity.AddTime = DateTime.Now; + tipMessage = "添加"; + } + entity.Key = model.Key; + entity.Description = model.Description; + entity.Rank = model.Rank; + entity.Save(); + + tip.Status = JsonTip.SUCCESS; + tip.Message = $"{tipMessage}数据字典成功!"; + Admin.WriteLogActions($"{tipMessage}数据字典成功({entity.Id});"); + return Json(tip); + } + #endregion + + #region 删除数据字典 + [HttpPost] + [MyAuthorize("del", "datadictionary", "JSON")] + public IActionResult DelDataDictionary(int id) + { + var entity = DataDictionary.Find(DataDictionary._.Id == id); + if (entity == null) + { + tip.Message = "系统找不到本记录!"; + return Json(tip); + } + //获取数据字典详情 + IList list = DataDictionaryDetail.FindAll(DataDictionaryDetail._.DataDictionaryId == entity.Id, null, null, 0, 0); + if (list.Count > 0) + { + list.Delete(); + } + Admin.WriteLogActions($"删除数据字典({entity.Id});"); + entity.Delete(); + + + tip.Message = "删除数据字典成功!"; + tip.Status = JsonTip.SUCCESS; + return Json(tip); + } + #endregion + + + #region 获取字典值列表 + [HttpPost] + [MyAuthorize("edit", "datadictionary", "JSON")] + public IActionResult GetDataDictionaryDetail(int id) + { + var entity = DataDictionary.Find(DataDictionary._.Id == id); + if (entity == null) + { + tip.Message = "系统找不到本记录!"; + return Json(tip); + } + //获取数据字典详情 + IList list = DataDictionaryDetail.FindAll(DataDictionaryDetail._.DataDictionaryId == entity.Id, DataDictionaryDetail._.Rank.Asc().And(DataDictionaryDetail._.Id.Desc()), null, 0, 0); + + List detail = new List(); + + foreach (var item in list) + { + detail.Add(new + { + dataDictionaryId = item.DataDictionaryId, + id = item.Id, + val = item.Val, + title = item.Title, + description = item.Description, + rank = item.Rank, + isDefault = item.IsDefault, + addTime = item.AddTime.ToString("yyyy-MM-dd HH:mm") + }); + } + tip.Detail = detail; + tip.Message = "获取成功!"; + tip.Status = JsonTip.SUCCESS; + Admin.WriteLogActions($"查看数据字典值列表({entity.Id});"); + return Json(tip); + } + #endregion + } } diff --git a/COMCMS.Web/Areas/AdminCP/Views/DataDictionary/Index.cshtml b/COMCMS.Web/Areas/AdminCP/Views/DataDictionary/Index.cshtml index dd94178..081e347 100644 --- a/COMCMS.Web/Areas/AdminCP/Views/DataDictionary/Index.cshtml +++ b/COMCMS.Web/Areas/AdminCP/Views/DataDictionary/Index.cshtml @@ -30,7 +30,6 @@
-