diff --git a/Examples/website/FreeSql.Site.DAL/BaseDAL.cs b/Examples/website/FreeSql.Site.DAL/BaseDAL.cs new file mode 100644 index 00000000..8b335872 --- /dev/null +++ b/Examples/website/FreeSql.Site.DAL/BaseDAL.cs @@ -0,0 +1,80 @@ +//using FreeSql.Site.Entity; +using FreeSql.Site.Entity; +using FreeSql.Site.Entity.Common; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text; + +namespace FreeSql.Site.DAL +{ + public class BaseDAL where T : BaseEntity + { + /// + /// 新增方法 + /// + /// + /// + public virtual long Insert(T model) + { + return DataBaseType.MySql.DB().Insert(model).ExecuteIdentity(); + } + + /// + /// 修改方法 + /// + /// + /// + public virtual bool Update(T model) + { + return DataBaseType.MySql.DB().Update(model.ID).ExecuteUpdated().Count > 0; + } + + /// + /// 删除方法 + /// + /// + /// + public virtual bool Delete(long id) + { + return DataBaseType.MySql.DB().Delete(id).ExecuteDeleted().Count > 0; + } + + /// + /// 获取一条数据 + /// + /// + /// + public virtual T GetByOne(Expression> where) + { + return DataBaseType.MySql.DB().Select() + .Where(where).ToOne(); + } + + /// + /// 查询方法 + /// + /// + /// + /// + public virtual (List list, long count) Query(Expression> where, + Expression> orderby = null, PageInfo pageInfo = null) + { + //设置查询条件 + var list = DataBaseType.MySql.DB().Select() + .Where(where); + + BaseEntity baseEntity = new BaseEntity(); + //设置排序 + if (orderby != null) list = list.OrderBy(nameof(baseEntity.CreateDt) + " desc "); + + var count = list.Count(); + //设置分页操作 + if (pageInfo != null && pageInfo.IsPaging) + list.Skip(pageInfo.PageIndex * pageInfo.PageSize).Limit(pageInfo.PageSize); + + //执行查询 + return (list.ToList(), count); + } + } +} diff --git a/Examples/website/FreeSql.Site.DAL/DocumentCommentDAL.cs b/Examples/website/FreeSql.Site.DAL/DocumentCommentDAL.cs index 0d9fcdcd..6411b57a 100644 --- a/Examples/website/FreeSql.Site.DAL/DocumentCommentDAL.cs +++ b/Examples/website/FreeSql.Site.DAL/DocumentCommentDAL.cs @@ -7,62 +7,8 @@ using System.Text; namespace FreeSql.Site.DAL { - public class DocumentCommentDAL + public class DocumentCommentDAL : BaseDAL { - /// - /// 新增方法 - /// - /// - /// - public long Insert(DocumentComment model) - { - return DataBaseType.MySql.DB().Insert(model).ExecuteIdentity(); - } - - /// - /// 修改方法 - /// - /// - /// - public bool Update(DocumentComment model) - { - return DataBaseType.MySql.DB().Update(model.ID).ExecuteUpdated().Count > 0; - } - - /// - /// 删除方法 - /// - /// - /// - public bool Delete(long id) - { - return DataBaseType.MySql.DB().Delete(id).ExecuteDeleted().Count > 0; - } - - /// - /// 获取一条数据 - /// - /// - /// - public DocumentComment GetByOne(Expression> where) - { - return DataBaseType.MySql.DB().Select() - .Where(where).ToOne(); - } - - /// - /// 查询方法 - /// - /// - /// - /// - public List Query(Expression> where, - Expression> orderby = null) - { - var list = DataBaseType.MySql.DB().Select() - .Where(where); - if (orderby != null) list = list.OrderBy(b => b.CreateDt); - return list.ToList(); - } + } } diff --git a/Examples/website/FreeSql.Site.DAL/DocumentContentDAL.cs b/Examples/website/FreeSql.Site.DAL/DocumentContentDAL.cs index 357fb0ee..333fffff 100644 --- a/Examples/website/FreeSql.Site.DAL/DocumentContentDAL.cs +++ b/Examples/website/FreeSql.Site.DAL/DocumentContentDAL.cs @@ -6,85 +6,85 @@ using System.Linq.Expressions; namespace FreeSql.Site.DAL { - public class DocumentContentDAL + public class DocumentContentDAL : BaseDAL { - /// - /// 新增 - /// - /// - /// - public long Insert(DocumentContent model) - { - return DataBaseType.MySql.DB().Insert(model).ExecuteIdentity(); - } + ///// + ///// 新增 + ///// + ///// + ///// + //public long Insert(DocumentContent model) + //{ + // return DataBaseType.MySql.DB().Insert(model).ExecuteIdentity(); + //} - /// - /// 修改 - /// - /// - /// - public bool Update(DocumentContent model) - { - var runsql = DataBaseType.MySql.DB().Update().SetSource(model); - return runsql.ExecuteAffrows() > 0; - } + ///// + ///// 修改 + ///// + ///// + ///// + //public bool Update(DocumentContent model) + //{ + // var runsql = DataBaseType.MySql.DB().Update().SetSource(model); + // return runsql.ExecuteAffrows() > 0; + //} - /// - /// 删除 - /// - /// - /// - public bool Delete(long id) - { - return DataBaseType.MySql.DB().Delete(id).ExecuteDeleted().Count > 0; - } + ///// + ///// 删除 + ///// + ///// + ///// + //public bool Delete(long id) + //{ + // return DataBaseType.MySql.DB().Delete(id).ExecuteDeleted().Count > 0; + //} - /// - /// 获取一条数据 - /// - /// - /// - public DocumentContent GetByOne(Expression> where) - { - return DataBaseType.MySql.DB().Select() - .Where(where).ToOne(); - } + ///// + ///// 获取一条数据 + ///// + ///// + ///// + //public DocumentContent GetByOne(Expression> where) + //{ + // return DataBaseType.MySql.DB().Select() + // .Where(where).ToOne(); + //} - /// - /// 获取一条数据 - /// - /// - /// - public long Count(Expression> where) - { - return DataBaseType.MySql.DB().Select() - .Where(where).Count(); - } + ///// + ///// 获取一条数据 + ///// + ///// + ///// + //public long Count(Expression> where) + //{ + // return DataBaseType.MySql.DB().Select() + // .Where(where).Count(); + //} - /// - /// 查询功能 - /// - /// - /// - /// - public (List list, long count) Query(Expression> where, - Expression> orderby = null, PageInfo pageInfo = null) - { - //设置查询条件 - var list = DataBaseType.MySql.DB().Select() - .Where(where); + ///// + ///// 查询功能 + ///// + ///// + ///// + ///// + //public (List list, long count) Query(Expression> where, + // Expression> orderby = null, PageInfo pageInfo = null) + //{ + // //设置查询条件 + // var list = DataBaseType.MySql.DB().Select() + // .Where(where); - //设置排序 - if (orderby != null) list = list.OrderBy(b => b.CreateDt); + // //设置排序 + // if (orderby != null) list = list.OrderBy(b => b.CreateDt); - var count = list.Count(); - //设置分页操作 - if (pageInfo != null && pageInfo.IsPaging) - list.Skip(pageInfo.PageIndex * pageInfo.PageSize).Limit(pageInfo.PageSize); + // var count = list.Count(); + // //设置分页操作 + // if (pageInfo != null && pageInfo.IsPaging) + // list.Skip(pageInfo.PageIndex * pageInfo.PageSize).Limit(pageInfo.PageSize); - //执行查询 - return (list.ToList(), count); - } + // //执行查询 + // return (list.ToList(), count); + //} } } diff --git a/Examples/website/FreeSql.Site.DAL/DocumentTypeDAL.cs b/Examples/website/FreeSql.Site.DAL/DocumentTypeDAL.cs index 4e03fe14..3d3088a4 100644 --- a/Examples/website/FreeSql.Site.DAL/DocumentTypeDAL.cs +++ b/Examples/website/FreeSql.Site.DAL/DocumentTypeDAL.cs @@ -1,5 +1,6 @@ //using FreeSql.Site.Entity; using FreeSql.Site.Entity; +using FreeSql.Site.Entity.Common; using System; using System.Collections.Generic; using System.Linq.Expressions; @@ -7,62 +8,8 @@ using System.Text; namespace FreeSql.Site.DAL { - public class DocumentTypeDAL + public class DocumentTypeDAL : BaseDAL { - /// - /// 新增方法 - /// - /// - /// - public long Insert(DocumentType model) - { - return DataBaseType.MySql.DB().Insert(model).ExecuteIdentity(); - } - /// - /// 修改方法 - /// - /// - /// - public bool Update(DocumentType model) - { - return DataBaseType.MySql.DB().Update(model.ID).ExecuteUpdated().Count > 0; - } - - /// - /// 删除方法 - /// - /// - /// - public bool Delete(long id) - { - return DataBaseType.MySql.DB().Delete(id).ExecuteDeleted().Count > 0; - } - - /// - /// 获取一条数据 - /// - /// - /// - public DocumentType GetByOne(Expression> where) - { - return DataBaseType.MySql.DB().Select() - .Where(where).ToOne(); - } - - /// - /// 查询方法 - /// - /// - /// - /// - public List Query(Expression> where, - Expression> orderby = null) - { - var list = DataBaseType.MySql.DB().Select() - .Where(where); - if (orderby != null) list = list.OrderBy(b => b.CreateDt); - return list.ToList(); - } } } diff --git a/Examples/website/FreeSql.Site.DAL/TemplateExampleDAL.cs b/Examples/website/FreeSql.Site.DAL/TemplateExampleDAL.cs index 75bf5c8f..18c1be9d 100644 --- a/Examples/website/FreeSql.Site.DAL/TemplateExampleDAL.cs +++ b/Examples/website/FreeSql.Site.DAL/TemplateExampleDAL.cs @@ -7,62 +7,8 @@ using System.Text; namespace FreeSql.Site.DAL { - public class TemplateExampleDAL + public class TemplateExampleDAL : BaseDAL { - /// - /// 新增方法 - /// - /// - /// - public long Insert(TemplateExample model) - { - return DataBaseType.MySql.DB().Insert(model).ExecuteIdentity(); - } - - /// - /// 修改方法 - /// - /// - /// - public bool Update(TemplateExample model) - { - return DataBaseType.MySql.DB().Update(model.ID).ExecuteUpdated().Count > 0; - } - - /// - /// 删除方法 - /// - /// - /// - public bool Delete(long id) - { - return DataBaseType.MySql.DB().Delete(id).ExecuteDeleted().Count > 0; - } - - /// - /// 获取一条数据 - /// - /// - /// - public TemplateExample GetByOne(Expression> where) - { - return DataBaseType.MySql.DB().Select() - .Where(where).ToOne(); - } - - /// - /// 查询方法 - /// - /// - /// - /// - public List Query(Expression> where, - Expression> orderby = null) - { - var list = DataBaseType.MySql.DB().Select() - .Where(where); - if (orderby != null) list = list.OrderBy(b => b.CreateDt); - return list.ToList(); - } + } } diff --git a/Examples/website/FreeSql.Site.Entity/BaseEntity.cs b/Examples/website/FreeSql.Site.Entity/BaseEntity.cs new file mode 100644 index 00000000..04fea76c --- /dev/null +++ b/Examples/website/FreeSql.Site.Entity/BaseEntity.cs @@ -0,0 +1,22 @@ +//using FreeSql.DataAnnotations; +using FreeSql.DataAnnotations; +using System; + +namespace FreeSql.Site.Entity +{ + public class BaseEntity + { + [Column(IsIdentity = true, IsPrimary = true)] + public int ID { get; set; } + + /// + /// 状态 + /// + public int Status { get; set; } + + public DateTime? CreateDt { get; set; } + + public string CreateBy { get; set; } + + } +} diff --git a/Examples/website/FreeSql.Site.Entity/Common/TreeNode.cs b/Examples/website/FreeSql.Site.Entity/Common/TreeNode.cs new file mode 100644 index 00000000..bf2befbe --- /dev/null +++ b/Examples/website/FreeSql.Site.Entity/Common/TreeNode.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace FreeSql.Site.Entity.Common +{ + public class TreeNode + { + public string id { get; set; } + + public string pid { get; set; } + + public string title { get; set; } + + } +} diff --git a/Examples/website/FreeSql.Site.Entity/DocumentComment.cs b/Examples/website/FreeSql.Site.Entity/DocumentComment.cs index 3c930630..763d2dc7 100644 --- a/Examples/website/FreeSql.Site.Entity/DocumentComment.cs +++ b/Examples/website/FreeSql.Site.Entity/DocumentComment.cs @@ -4,11 +4,8 @@ using System; namespace FreeSql.Site.Entity { - public class DocumentComment + public class DocumentComment:BaseEntity { - [Column(IsIdentity = true, IsPrimary = true)] - public int ID { get; set; } - /// /// 功能类型(文章、模板、示例等) /// @@ -43,16 +40,5 @@ namespace FreeSql.Site.Entity /// 评论内容 /// public string CommentContent { get; set; } - - /// - /// 创建时间 - /// - public DateTime? CreateDt { get; set; } - - /// - /// 创建人 - /// - public string CreateBy { get; set; } - } } diff --git a/Examples/website/FreeSql.Site.Entity/DocumentContent.cs b/Examples/website/FreeSql.Site.Entity/DocumentContent.cs index 1387bd91..1d35b917 100644 --- a/Examples/website/FreeSql.Site.Entity/DocumentContent.cs +++ b/Examples/website/FreeSql.Site.Entity/DocumentContent.cs @@ -7,11 +7,8 @@ namespace FreeSql.Site.Entity /// /// 数据库实体 /// - public class DocumentContent + public class DocumentContent : BaseEntity { - [Column(IsIdentity = true, IsPrimary = true)] - public int ID { get; set; } - /// /// 类型编号 /// @@ -33,11 +30,6 @@ namespace FreeSql.Site.Entity [Column(DbType = "text")] public string DocContent { get; set; } - /// - /// 状态 - /// - public int Status { get; set; } - /// /// 查看次数 /// @@ -48,15 +40,6 @@ namespace FreeSql.Site.Entity /// public int StarCount { get; set; } - /// - /// 创建时间 - /// - public DateTime? CreateDt { get; set; } - - /// - /// 创建人 - /// - public string CreateBy { get; set; } /// /// 修改时间 diff --git a/Examples/website/FreeSql.Site.Entity/DocumentType.cs b/Examples/website/FreeSql.Site.Entity/DocumentType.cs index 69f9a92f..2bbb818c 100644 --- a/Examples/website/FreeSql.Site.Entity/DocumentType.cs +++ b/Examples/website/FreeSql.Site.Entity/DocumentType.cs @@ -1,16 +1,20 @@ //using FreeSql.DataAnnotations; using FreeSql.DataAnnotations; +using FreeSql.Site.Entity.Common; using System; namespace FreeSql.Site.Entity { - public class DocumentType + public class DocumentType : BaseEntity { - [Column(IsIdentity = true, IsPrimary = true)] - public int ID { get; set; } - + /// + /// 类型名称 + /// public string TypeName { get; set; } + /// + /// 上级类型名称 + /// public int? UpID { get; set; } /// @@ -18,17 +22,24 @@ namespace FreeSql.Site.Entity /// public string Tag { get; set; } - /// - /// 状态 - /// - public int Status { get; set; } - - public DateTime? CreateDt { get; set; } - - public string CreateBy { get; set; } - public DateTime? UpdateDt { get; set; } public string UpdateBy { get; set; } } + + /// + /// 类型树形结构 + /// + public class DocumentTypeTreeNode : TreeNode + { + /// + /// 标签 + /// + public string tag { get; set; } + + /// + /// 创建时间 + /// + public DateTime? createdt { get; set; } + } } diff --git a/Examples/website/FreeSql.Site.Entity/TemplateExample.cs b/Examples/website/FreeSql.Site.Entity/TemplateExample.cs index ca8cd095..abd5b923 100644 --- a/Examples/website/FreeSql.Site.Entity/TemplateExample.cs +++ b/Examples/website/FreeSql.Site.Entity/TemplateExample.cs @@ -8,10 +8,8 @@ namespace FreeSql.Site.Entity /// /// 模板示例 /// - public class TemplateExample + public class TemplateExample : BaseEntity { - [Column(IsIdentity = true, IsPrimary = true)] - public int ID { get; set; } /// /// 模板图片 @@ -49,16 +47,13 @@ namespace FreeSql.Site.Entity public int StarCount { get; set; } /// - /// 状态 + /// 修改时间 /// - public int Status { get; set; } - - public DateTime? CreateDt { get; set; } - - public string CreateBy { get; set; } - public DateTime? UpdateDt { get; set; } + /// + /// 修改人 + /// public string UpdateBy { get; set; } } } diff --git a/Examples/website/FreeSql.Site.UI/Areas/Admin/Controllers/DocumentController.cs b/Examples/website/FreeSql.Site.UI/Areas/Admin/Controllers/DocumentController.cs index fa7e85f4..8704242d 100644 --- a/Examples/website/FreeSql.Site.UI/Areas/Admin/Controllers/DocumentController.cs +++ b/Examples/website/FreeSql.Site.UI/Areas/Admin/Controllers/DocumentController.cs @@ -35,15 +35,6 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers return View(model); } - #region 文档分类 - public IActionResult DocType() - { - DocumentType model = new DocumentType(); - return View(model); - } - - #endregion - #region 文档内容 public IActionResult DocContent() { @@ -82,7 +73,7 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers public ActionResult DocContentEditModule(string id) { - ViewBag.DocumentTypeList = DocumentTypeDAL.Query(w => w.Status == 1).Select(s => new SelectListItem { Text = s.TypeName, Value = s.ID.ToString() }).ToList(); + ViewBag.DocumentTypeList = DocumentTypeDAL.Query(w => w.Status == 1).list.Select(s => new SelectListItem { Text = s.TypeName, Value = s.ID.ToString() }).ToList(); DocumentContent model = new DocumentContent(); if (!string.IsNullOrEmpty(id)) { @@ -140,6 +131,109 @@ namespace FreeSql.Site.UI.Areas.Admin.Controllers return Json(resdata); } + #endregion + + #region 文档分类 + public IActionResult DocType() + { + DocumentType model = new DocumentType(); + + ViewBag.TypeList = DocumentTypeDAL.Query(w => w.Status == 1).list.Select(s => new DocumentTypeTreeNode + { + id = s.ID.ToString(), + pid = (s.UpID ?? 0).ToString(), + title = s.TypeName, + tag = s.Tag, + createdt = s.CreateDt + }).ToList(); + + return View(model); + } + + [HttpGet] + public IActionResult DocTypeList(string searchContent, string seniorQueryJson, int page = 1, int limit = 10) + { + DocumentType model = null; + if (!string.IsNullOrWhiteSpace(seniorQueryJson)) + { + model = Newtonsoft.Json.JsonConvert.DeserializeObject(seniorQueryJson); + } + Expression> predicate = i => 1 == 0; + var searchPredicate = PredicateExtensions.True(); + if (model != null) + { + searchPredicate = searchPredicate.And(u => u.Status == 1); + } + var contents = DocumentTypeDAL.Query(searchPredicate); + + return Json(new DataPage + { + code = "0", + msg = "", + count = contents.count, + data = contents.list + }); + } + + public ActionResult DocTypeEditModule(string id) + { + DocumentType model = new DocumentType(); + if (!string.IsNullOrEmpty(id)) + { + int _id = Convert.ToInt32(id); + model = DocumentTypeDAL.GetByOne(w => w.ID == _id); + } + return View(model); + } + + // POST: Documents/Create + [HttpPost] + //[ValidateAntiForgeryToken] + public ActionResult DocTypeCreate([FromBody]DocumentContent model) + { + var resdata = AutoException.Excute((result) => + { + result.Data = DocumentContentDAL.Insert(model); + if (result.Data == 0) + { + throw new Exception("数据新增异常,JSON:" + Newtonsoft.Json.JsonConvert.SerializeObject(model)); + } + }, false); + return Json(resdata); + } + + // POST: Documents/Create + [HttpPost] + //[ValidateAntiForgeryToken] + public ActionResult DocTypeUpdate([FromBody]DocumentContent model) + { + var resdata = AutoException.Excute((result) => + { + model.UpdateBy = "admin"; + model.UpdateDt = DateTime.Now; + result.Data = DocumentContentDAL.Update(model); + if (result.Data == false) + { + throw new Exception("数据新增异常,JSON:" + Newtonsoft.Json.JsonConvert.SerializeObject(model)); + } + }, false); + return Json(resdata); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult DocTypeDelete(int id, IFormCollection collection) + { + var resdata = AutoException.Excute((result) => + { + if (!DocumentContentDAL.Delete(id)) + { + throw new Exception("数据删除异常,ID:" + id); + } + }, false); + return Json(resdata); + } + #endregion } } \ No newline at end of file diff --git a/Examples/website/FreeSql.Site.UI/Areas/Admin/Views/Document/DocContent.cshtml b/Examples/website/FreeSql.Site.UI/Areas/Admin/Views/Document/DocContent.cshtml index 348fd90a..e2ff0029 100644 --- a/Examples/website/FreeSql.Site.UI/Areas/Admin/Views/Document/DocContent.cshtml +++ b/Examples/website/FreeSql.Site.UI/Areas/Admin/Views/Document/DocContent.cshtml @@ -16,7 +16,7 @@
@* - *@ + *@
高级查询 @@ -30,21 +30,11 @@ \ No newline at end of file diff --git a/Examples/website/FreeSql.Site.UI/Areas/Admin/_ViewImports.cshtml b/Examples/website/FreeSql.Site.UI/Areas/Admin/_ViewImports.cshtml new file mode 100644 index 00000000..cc1ea3f7 --- /dev/null +++ b/Examples/website/FreeSql.Site.UI/Areas/Admin/_ViewImports.cshtml @@ -0,0 +1,5 @@ +@using FreeSql.Site.UI +@using FreeSql.Site.UI.Models +@using FreeSql.Site.Entity +@using FreeSql.Site.UI.Common +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/Examples/website/FreeSql.Site.UI/Areas/Doc/Controllers/DocumentsController.cs b/Examples/website/FreeSql.Site.UI/Areas/Doc/Controllers/DocumentsController.cs index 8d81a34f..802800fa 100644 --- a/Examples/website/FreeSql.Site.UI/Areas/Doc/Controllers/DocumentsController.cs +++ b/Examples/website/FreeSql.Site.UI/Areas/Doc/Controllers/DocumentsController.cs @@ -27,7 +27,7 @@ namespace FreeSql.Site.UI.Areas.Doc.Controllers // GET: Documents public IActionResult Index(int id = 1) { - var typeList = DocumentTypeDAL.Query(d => d.ID != 0); + var typeList = DocumentTypeDAL.Query(d => d.ID != 0).list; var contentlist = DocumentContentDAL.Query(d => d.Status == 1).list; //适应两层结构即可 diff --git a/Examples/website/FreeSql.Site.UI/Common/HtmlHelperViewExtensions.cs b/Examples/website/FreeSql.Site.UI/Common/HtmlHelperViewExtensions.cs index 961c2de2..da48840e 100644 --- a/Examples/website/FreeSql.Site.UI/Common/HtmlHelperViewExtensions.cs +++ b/Examples/website/FreeSql.Site.UI/Common/HtmlHelperViewExtensions.cs @@ -13,6 +13,15 @@ namespace FreeSql.Site.UI.Common { public static class HtmlHelperViewExtensions { + public static string ToJson(this IHtmlHelper htmlHeler, object val) + { + if (val != null) + { + return Newtonsoft.Json.JsonConvert.SerializeObject(val); + } + return ""; + } + public static IHtmlContent Action(this IHtmlHelper helper, string action, object parameters = null) { var controller = (string)helper.ViewContext.RouteData.Values["controller"]; diff --git a/Examples/website/FreeSql.Site.UI/FreeSql.Site.UI.csproj b/Examples/website/FreeSql.Site.UI/FreeSql.Site.UI.csproj index 08e0cb2d..c4cef1c2 100644 --- a/Examples/website/FreeSql.Site.UI/FreeSql.Site.UI.csproj +++ b/Examples/website/FreeSql.Site.UI/FreeSql.Site.UI.csproj @@ -16,6 +16,7 @@ + diff --git a/Examples/website/FreeSql.Site.UI/Views/_ViewImports.cshtml b/Examples/website/FreeSql.Site.UI/Views/_ViewImports.cshtml index 425e6883..6f5bf531 100644 --- a/Examples/website/FreeSql.Site.UI/Views/_ViewImports.cshtml +++ b/Examples/website/FreeSql.Site.UI/Views/_ViewImports.cshtml @@ -1,3 +1,4 @@ @using FreeSql.Site.UI @using FreeSql.Site.UI.Models +@using FreeSql.Site.UI.Common @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/Examples/website/FreeSql.Site.UI/wwwroot/js/common.js b/Examples/website/FreeSql.Site.UI/wwwroot/js/common.js index 373fc159..88ba518b 100644 --- a/Examples/website/FreeSql.Site.UI/wwwroot/js/common.js +++ b/Examples/website/FreeSql.Site.UI/wwwroot/js/common.js @@ -59,6 +59,15 @@ skin: 'layer-ext-moon' }, yes, no); }, + markDownEdit: function (id, option) { + var _option = $.extend({ + width: "96%", + height: 640, + syncScrolling: "single", + path: "../../lib/editormd/lib/" + }, options); + return editormd(id, _option); + }, ajax: function (url, appendPostData, beforeFn, completeFn, successFn, errorFn, isShowLoading) { jQuery.ajax({ type: "POST", @@ -113,8 +122,129 @@ } } }); + }, + dialogWindow: { + /* + url: "/Admin/Document/DocContentEditModule", //页面地址 + paramters: { id: "" }, //参数 + ------------------------------------------------------- + title: "新增文档", //标题 + area: ['1100px', '660px'], //尺寸 + submit: { //提交参数 + url: "/Admin/Document/DocContentCreate", // 提交的地址 + }, // + callback: reloadTable //执行完成回调函数 + */ + create: function (options, formpage) { + $("#docContentEdit").load(options.url, options.paramters, function (responseText, textStatus, jqXHR) { + switch (textStatus) { + case "success": + freejs.dialogWindow.open($.extend({ + type: 1, + maxmin: true, + title: "编辑", + area: ['1100px', '660px'], + shadeClose: false, //点击遮罩关闭 + content: responseText, + submit: { + url: "/Admin/Document/DocContentCreate", + } + }, options), form); + break; + case "error": + freejs.showMessage({ title: "提示", msg: "页面加载失败", type: 2 }); + break; + } + }); + }, + /* + { + type: 1, + maxmin: true, + title: "编辑", + area: ['1100px', '660px'], + shadeClose: false, //点击遮罩关闭 + content: responseText, + submit: { + url: "/Admin/Document/DocContentCreate", + } + } + */ + open: function (options, form) { + var base_options = { + type: 1, + maxmin: true, + title: "编辑", + area: ['1100px', '660px'], + shadeClose: false //点击遮罩关闭 + }; + var new_options = $.extend(base_options, options); + new_options.success = function (layero, index) { + form.render(); + $(".form-module-content").height(dialog_Paramters.height - 110); + contentEdit = editormd("md_DocContent", { + width: "96%", + height: 640, + syncScrolling: "single", + path: "../../lib/editormd/lib/" + }); + //监听提交 + form.on('submit(formDemo)', function (data) { + $.ajax({ + type: 'POST', + url: options.submit.url,//"/Admin/Document/DocContentCreate", + data: JSON.stringify(data.field), + contentType: "application/json; charset=utf-8", + dataType: "json", + success: function (e) { + if (e.Status == 1) { + freejs.showMessage({ title: "提示", msg: e.Msg || "保存成功", type: 1 }); + if ($.isFunction(new_options.callback)) new_options.callback(); + layer.close(index); + } + else { + freejs.showMessage({ title: "提示", msg: e.Msg, type: 2 }); + } + } + }); + return false; + }); + } + layer.open(new_options); + }, + close: function () { + } } }; - window.freejs = new base(); + + /** + * 数组扩展 + * @param {any} func + */ + Array.prototype.select = function (func) { + var retValues = []; + if (this.length == 0) { + return retValues; + } + if (func == null) { + return this; + } + for (var i = 0; i < this.length; i++) { + retValues.push(func(this[i])); + } + return retValues; + }; + Array.prototype.where = function (func) { + if (func == null) { + return this; + } + var retList = []; + for (var i = 0; i < this.length; i++) { + if (func(this[i]) != false) { + retList.push(this[i]); + } + } + return retList; + } })(window); \ No newline at end of file diff --git a/Examples/website/FreeSql.Site.UI/wwwroot/layui/ext/treetable/css/frame.css b/Examples/website/FreeSql.Site.UI/wwwroot/layui/ext/treetable/css/frame.css new file mode 100644 index 00000000..5a63b974 --- /dev/null +++ b/Examples/website/FreeSql.Site.UI/wwwroot/layui/ext/treetable/css/frame.css @@ -0,0 +1,41 @@ +html,body{height: 100%;overflow-y:hidden;} +.system-top .layui-nav{height: 60px;display: inline-block;} + +.top-left{padding-left: 0;} +.top-left .iconfont{font-size: 25px;} +.top-left .layui-this:after{width: 0;} +.top-right{position: absolute;right: 0;} +.logo{background-color: #009688;height:60px;line-height:60px;font-size:18px;text-align:center;color:#fff;} +.logo .layui-nav-img{margin-right: 0;} + +.system-left{height: 100%;position: fixed;z-index: 1;top: 0px;} +.system-left .layui-nav .layui-nav-item{border-bottom: 1px solid #414d5c;} + +/** 左侧菜单展开模式 **/ +.left-full .system-left,.left-full .logo{width: 200px;} +.left-full .system-top,.left-full .system-content{padding-left:210px;} +.left-full .text{display: block;}.left-full .image{display: none;} + +/** 左侧菜单收起(迷你)模式 **/ +.left-mini .system-left,.left-mini .system-left .layui-nav{width: 56px;} +.left-mini .system-top,.left-mini .system-content{padding-left: 66px;} +.left-mini .system-left .layui-nav-item>a .title{display: none;} +.left-mini .system-left dd span{display: none;} +.left-mini .system-left .layui-nav-tree .layui-nav-more{right: 22px;} +.left-mini .layui-nav-child dd{position: relative;} +.left-mini .left-tips{position: absolute;left: 60px;top: 0;padding:0 10px;border-radius:2px;background-color: #000;} +.left-mini .left-tips i{position: absolute;left: -8px;top: 5px;width: 0;height: 0;border-width: 8px;border-color: transparent;border-style: dashed;border-bottom-style: solid;border-bottom-color: #000;} +.left-mini .logo .text{display: none;}.left-mini .logo .image{display: block;} + +.system-content .layui-tab-card{margin-bottom: 0;border: 0;} +.system-content .layui-tab-card .layui-tab-title{border-top-left-radius: 15px;border-top-right-radius: 15px;position: absolute;z-index: 9;width: 100%;bottom: 0;height: 35px;} +.system-content .layui-tab-card .layui-tab-title li{background: #f2f2f2;height: 35px;line-height: 35px;border-top-left-radius: 15px;border-top-right-radius: 15px;border-left: 1px solid #e2e2e2;border: 1px solid #e2e2e2;margin-right: 4px;} +.system-content .layui-tab-card .layui-tab-title li .layui-tab-close{border: 1px solid #c2c2c2;border-radius: 50%;} +.system-content .layui-tab-card .layui-tab-title li:first-child .layui-tab-close{display:none;} +.system-content .layui-tab-card .layui-tab-title .layui-this{background-color: #009688;color: #fff;} +.system-content .layui-tab-card .layui-tab-title .layui-this:after{border-style: none;} +.system-content .layui-tab-card .layui-tab-title .layui-this .layui-tab-close{color:#fff;border: 1px solid #fff;} +.system-content .layui-tab-card .layui-tab-content{padding: 0;} +.system-content .layui-tab-card .layui-tab-content .layui-table-view{margin:0;} + + diff --git a/Examples/website/FreeSql.Site.UI/wwwroot/layui/ext/treetable/css/globle.css b/Examples/website/FreeSql.Site.UI/wwwroot/layui/ext/treetable/css/globle.css new file mode 100644 index 00000000..b0d61cae --- /dev/null +++ b/Examples/website/FreeSql.Site.UI/wwwroot/layui/ext/treetable/css/globle.css @@ -0,0 +1,17 @@ +.hide{display: none;} +.top-title{margin-bottom: 10px;position: relative;} +.top-title .layui-form-select{display: inline-block;} +.top-title .layui-btn-group{display: inline-block;position: absolute;right: 10px;top: 7px;font-size: 14px;} +.top-title .layui-btn-group .layui-btn{margin-top: -4px;height: 36px;} +.top-title .layui-form-select .layui-input{background: #009688;color:#fff;} +.top-title .layui-form-select .layui-input::-webkit-input-placeholder{color:#fff;} +.layui-table-page{text-align: center;} +.layui-table-view{margin-bottom: 0;} + +.table-search-form{padding:10px;} +.table-search-form .layui-form-item{margin-bottom:10px;} +.table-search-form .layui-layer-btn a{width: 100%;margin: 5px 0;padding: 0;} + +td[data-field=action] .layui-table-cell{overflow: unset;padding: 0;} +td[data-field=action] .layui-form-select{position: absolute;width: 120px;margin-left: 7px;} +td[data-field=action] .layui-form-select .layui-input{height:30px;border: 0;background-color: #009688;color: #fff;} \ No newline at end of file diff --git a/Examples/website/FreeSql.Site.UI/wwwroot/layui/ext/treetable/img/header.png b/Examples/website/FreeSql.Site.UI/wwwroot/layui/ext/treetable/img/header.png new file mode 100644 index 00000000..f611cec2 Binary files /dev/null and b/Examples/website/FreeSql.Site.UI/wwwroot/layui/ext/treetable/img/header.png differ diff --git a/Examples/website/FreeSql.Site.UI/wwwroot/layui/ext/treetable/img/statistics.png b/Examples/website/FreeSql.Site.UI/wwwroot/layui/ext/treetable/img/statistics.png new file mode 100644 index 00000000..b090fcba Binary files /dev/null and b/Examples/website/FreeSql.Site.UI/wwwroot/layui/ext/treetable/img/statistics.png differ diff --git a/Examples/website/FreeSql.Site.UI/wwwroot/layui/lay/modules/treetable.js b/Examples/website/FreeSql.Site.UI/wwwroot/layui/lay/modules/treetable.js new file mode 100644 index 00000000..c58b7466 --- /dev/null +++ b/Examples/website/FreeSql.Site.UI/wwwroot/layui/lay/modules/treetable.js @@ -0,0 +1,217 @@ +layui.define(["form"], function (exports) { + var MOD_NAME = "treetable", + o = layui.jquery, + form = layui.form, + tree = function () { }; + tree.prototype.cinfig = function (e) { + this.c = o.extend({ + elem: "#tree-table", + field: "id", + icon_class: "down", + icon_val: { + open: "", + close: "" + }, + space: 4, + new_data: [], + childs: [], + is_open: false, + }, e) + }; + tree.prototype.on = function (events, callback) { + return layui.onevent.call(this, MOD_NAME, events, callback) + }; + tree.prototype.template = function (data) { + var t = this, + level = [], + tbody = "", + thead = t.c.is_checkbox ? '' : ''; + o.each(t.c.cols, function (idx, obj) { + thead += '' + obj.title + "" + }); + o.each(data, function (index, item) { + var checked = t.c.is_checkbox && t.c.checked && o.inArray(item.id, t.c.checked) > -1 && 'checked', + hide_class = 'class="' + (item.pid == 0 || item.pid == t.cache(item.pid) || t.c.is_open ? "" : "hide") + '"', + tr = '" + + (t.c.is_checkbox ? '
' : ""); + item.level = level[item.id] = item.pid > 0 ? (level[item.pid] + 1) : 0; + o.each(t.c.cols, function (idx, obj) { + tr += ''; + if (obj.field == t.c.field) { + tr += (" ".repeat(level[item.id] * t.c.space)); + if (t.c.childs[item.id]) { + tr += '' + (item.id == t.cache(item.id) || t.c.is_open ? t.c.icon_val.close : t.c.icon_val.open) + "" + } + } + tr += (obj.template ? obj.template(item) : (item[obj.field] !== undefined ? item[obj.field] : '')) + "" + }); + tbody += tr + ""; + }); + return '' + thead + "" + tbody + "" + }; + tree.prototype.render = function (e) { + var t = this, + data = []; + t.cinfig(e); + o.each(t.c.data, function (index, item) { + if (!t.c.childs[item.pid]) { + t.c.childs[item.pid] = [] + } + t.c.childs[item.pid][item.id] = t.c.new_data[item.id] = data[item.id] = item + }); + var tree = this.tree(data, 0, [], 0), + template = t.template(tree); + o(t.c.elem).html(template).on("click", "td", function () { + var id = o(this).parents("tr").data("id"), + pid = o(this).parents("tr").data("pid"), + status = o(t.c.elem).find("tr[data-pid=" + id + "]").is(":visible"), + dt = o(this).find("." + t.c.icon_class); + if (dt.length) { + if (status) { + t.hide(id); + dt.html(t.c.icon_val.open) + } else { + o(t.c.elem).find("tr[data-pid=" + id + "]").removeClass('hide'); + t.cache(id, true); + dt.html(t.c.icon_val.close) + } + } + var filter = o(this).parents("[lay-filter]").attr("lay-filter"); + return filter ? layui.event.call(this, MOD_NAME, MOD_NAME + "(" + filter + ")", { + elem: o(this), + status: status, + item: t.c.new_data[id], + childs: t.c.childs[id], + siblings: t.c.childs[pid], + index: o(this).index(), + is_last: o(this).index() + 1 == o(this).parents("tr").find("td").length, + }) : "" + }).on("click", "td [lay-filter]", function () { + var id = o(this).parents("tr").data("id"), + filter = o(this).attr("lay-filter"); + return layui.event.call(this, MOD_NAME, MOD_NAME + "(" + filter + ")", { + elem: o(this), + item: t.c.new_data[id], + }) + }) + form.render('checkbox').on('checkbox(lay-t)', function (data) { + var status = o(data.othis).hasClass('layui-form-checked'), + tr = o(data.elem).parents('tr'); + t.child_to_choose(tr.data('id'), status); + t.parent_to_choose(tr.data('pid')); + form.render('checkbox'); + }) + }; + tree.prototype.parent_to_choose = function (id) { + var t = this, + pt = o(t.c.elem).find('[data-pid=' + id + ']'), + pl = pt.find('[lay-skin=primary]:checked').length, + bt = o(t.c.elem).find('[data-id=' + id + '] [lay-skin=primary]'), + pid = o(t.c.elem).find('[data-id=' + id + ']').data('pid'); + if (pt.length == pl || pl == 0) { + bt.prop('checked', pt.length == pl); + pid > -1 && t.parent_to_choose(pid); + } + }; + tree.prototype.child_to_choose = function (id, status) { + var t = this; + o(t.c.elem).find("tr[data-pid=" + id + "]").each(function () { + o(this).find('[lay-skin=primary]').prop('checked', status); + var id = o(this).data("id"); + t.child_to_choose(id, status) + }); + }; + tree.prototype.hide = function (id) { + var t = this; + o(t.c.elem).find("tr[data-pid=" + id + "]").each(function () { + o(this).addClass('hide'); + o(this).find("." + t.c.icon_class).html(t.c.icon_val.open); + var id = o(this).data("id"); + t.hide(id) + }); + t.cache(id, false) + }; + tree.prototype.show = function (id) { + var t = this; + o(t.c.elem).find("tr[data-pid=" + id + "]").each(function () { + o(this).removeClass('hide'); + o(this).find("." + t.c.icon_class).html(t.c.icon_val.close); + var id = o(this).data("id"); + t.show(id) + }); + t.cache(id, true) + }; + tree.prototype.tree = function (lists, pid, data) { + var t = this; + if (lists[pid]) { + data.push(lists[pid]); + delete lists[pid] + } + o.each(t.c.data, function (index, item) { + if (item.pid == pid) { + data.concat(t.tree(lists, item.id, data)) + } + }); + return data + }; + tree.prototype.cache = function (val, option) { + var t = this, + name = "tree-table-open-item", + val = val.toString(), + cache = t.get_cookie(name) ? t.get_cookie(name).split(",") : [], + index = o.inArray(val, cache); + if (option === undefined) { + return index == -1 ? false : val + } + if (option && index == -1) { + cache.push(val) + } + if (!option && index > -1) { + cache.splice(index, 1) + } + t.set_cookie(name, cache.join(",")) + }; + tree.prototype.set_cookie = function (name, value, days) { + var exp = new Date(); + exp.setTime(exp.getTime() + (days ? days : 30) * 24 * 60 * 60 * 1000); + document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + }; + tree.prototype.get_cookie = function (name) { + var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); + if (arr = document.cookie.match(reg)) { + return unescape(arr[2]) + } else { + return null + } + }; + tree.prototype.all = function (type) { + var t = this; + if (type == "up") { + o(t.c.elem).find("tr[data-pid=0]").each(function () { + var id = o(this).data("id"); + t.hide(id); + o(this).find("." + t.c.icon_class).html(t.c.icon_val.open) + }) + } else if (type == "down") { + o(t.c.elem).find("tr[data-pid=0]").each(function () { + var id = o(this).data("id"); + t.show(id); + o(this).find("." + t.c.icon_class).html(t.c.icon_val.close) + }) + } else if (type == "checked") { + var ids = [], + data = []; + o(t.c.elem).find("tbody [lay-skin=primary]:checked").each(function () { + var id = o(this).parents('tr').data("id"); + data.push(t.c.new_data[id]); + ids.push(id); + }) + return { + ids: ids, + data: data + }; + } + }; + var tree = new tree(); + exports(MOD_NAME, tree) +}); \ No newline at end of file