mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	新增文档分类列表树
This commit is contained in:
		
							
								
								
									
										80
									
								
								Examples/website/FreeSql.Site.DAL/BaseDAL.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								Examples/website/FreeSql.Site.DAL/BaseDAL.cs
									
									
									
									
									
										Normal file
									
								
							@@ -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<T> where T : BaseEntity
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 新增方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="model"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public virtual long Insert(T model)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Insert<T>(model).ExecuteIdentity();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 修改方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="model"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public virtual bool Update(T model)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Update<T>(model.ID).ExecuteUpdated().Count > 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 删除方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="id"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public virtual bool Delete(long id)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Delete<T>(id).ExecuteDeleted().Count > 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 获取一条数据
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="where"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public virtual T GetByOne(Expression<Func<T, bool>> where)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Select<T>()
 | 
			
		||||
                .Where(where).ToOne();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 查询方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="where"></param>
 | 
			
		||||
        /// <param name="orderby"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public virtual (List<T> list, long count) Query(Expression<Func<T, bool>> where,
 | 
			
		||||
            Expression<Func<T, T>> orderby = null, PageInfo pageInfo = null)
 | 
			
		||||
        {
 | 
			
		||||
            //设置查询条件
 | 
			
		||||
            var list = DataBaseType.MySql.DB().Select<T>()
 | 
			
		||||
                .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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -7,62 +7,8 @@ using System.Text;
 | 
			
		||||
 | 
			
		||||
namespace FreeSql.Site.DAL
 | 
			
		||||
{
 | 
			
		||||
    public class DocumentCommentDAL
 | 
			
		||||
    public class DocumentCommentDAL : BaseDAL<DocumentComment>
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 新增方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="model"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public long Insert(DocumentComment model)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Insert<DocumentComment>(model).ExecuteIdentity();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 修改方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="model"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public bool Update(DocumentComment model)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Update<DocumentComment>(model.ID).ExecuteUpdated().Count > 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 删除方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="id"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public bool Delete(long id)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Delete<DocumentComment>(id).ExecuteDeleted().Count > 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 获取一条数据
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="where"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public DocumentComment GetByOne(Expression<Func<DocumentComment, bool>> where)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Select<DocumentComment>()
 | 
			
		||||
                 .Where(where).ToOne();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 查询方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="where"></param>
 | 
			
		||||
        /// <param name="orderby"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public List<DocumentComment> Query(Expression<Func<DocumentComment, bool>> where,
 | 
			
		||||
            Expression<Func<DocumentComment, DocumentComment>> orderby = null)
 | 
			
		||||
        {
 | 
			
		||||
            var list = DataBaseType.MySql.DB().Select<DocumentComment>()
 | 
			
		||||
                .Where(where);
 | 
			
		||||
            if (orderby != null) list = list.OrderBy(b => b.CreateDt);
 | 
			
		||||
            return list.ToList();
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,85 +6,85 @@ using System.Linq.Expressions;
 | 
			
		||||
 | 
			
		||||
namespace FreeSql.Site.DAL
 | 
			
		||||
{
 | 
			
		||||
    public class DocumentContentDAL
 | 
			
		||||
    public class DocumentContentDAL : BaseDAL<DocumentContent>
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 新增
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="model"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public long Insert(DocumentContent model)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Insert<DocumentContent>(model).ExecuteIdentity();
 | 
			
		||||
        }
 | 
			
		||||
        ///// <summary>
 | 
			
		||||
        ///// 新增
 | 
			
		||||
        ///// </summary>
 | 
			
		||||
        ///// <param name="model"></param>
 | 
			
		||||
        ///// <returns></returns>
 | 
			
		||||
        //public long Insert(DocumentContent model)
 | 
			
		||||
        //{
 | 
			
		||||
        //    return DataBaseType.MySql.DB().Insert<DocumentContent>(model).ExecuteIdentity();
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 修改
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="model"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public bool Update(DocumentContent model)
 | 
			
		||||
        {
 | 
			
		||||
            var runsql = DataBaseType.MySql.DB().Update<DocumentContent>().SetSource(model);
 | 
			
		||||
            return runsql.ExecuteAffrows() > 0;
 | 
			
		||||
        }
 | 
			
		||||
        ///// <summary>
 | 
			
		||||
        ///// 修改
 | 
			
		||||
        ///// </summary>
 | 
			
		||||
        ///// <param name="model"></param>
 | 
			
		||||
        ///// <returns></returns>
 | 
			
		||||
        //public bool Update(DocumentContent model)
 | 
			
		||||
        //{
 | 
			
		||||
        //    var runsql = DataBaseType.MySql.DB().Update<DocumentContent>().SetSource(model);
 | 
			
		||||
        //    return runsql.ExecuteAffrows() > 0;
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 删除
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="id"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public bool Delete(long id)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Delete<DocumentContent>(id).ExecuteDeleted().Count > 0;
 | 
			
		||||
        }
 | 
			
		||||
        ///// <summary>
 | 
			
		||||
        ///// 删除
 | 
			
		||||
        ///// </summary>
 | 
			
		||||
        ///// <param name="id"></param>
 | 
			
		||||
        ///// <returns></returns>
 | 
			
		||||
        //public bool Delete(long id)
 | 
			
		||||
        //{
 | 
			
		||||
        //    return DataBaseType.MySql.DB().Delete<DocumentContent>(id).ExecuteDeleted().Count > 0;
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 获取一条数据
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="where"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public DocumentContent GetByOne(Expression<Func<DocumentContent, bool>> where)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Select<DocumentContent>()
 | 
			
		||||
                 .Where(where).ToOne();
 | 
			
		||||
        }
 | 
			
		||||
        ///// <summary>
 | 
			
		||||
        ///// 获取一条数据
 | 
			
		||||
        ///// </summary>
 | 
			
		||||
        ///// <param name="where"></param>
 | 
			
		||||
        ///// <returns></returns>
 | 
			
		||||
        //public DocumentContent GetByOne(Expression<Func<DocumentContent, bool>> where)
 | 
			
		||||
        //{
 | 
			
		||||
        //    return DataBaseType.MySql.DB().Select<DocumentContent>()
 | 
			
		||||
        //         .Where(where).ToOne();
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 获取一条数据
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="where"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public long Count(Expression<Func<DocumentContent, bool>> where)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Select<DocumentContent>()
 | 
			
		||||
                 .Where(where).Count();
 | 
			
		||||
        }
 | 
			
		||||
        ///// <summary>
 | 
			
		||||
        ///// 获取一条数据
 | 
			
		||||
        ///// </summary>
 | 
			
		||||
        ///// <param name="where"></param>
 | 
			
		||||
        ///// <returns></returns>
 | 
			
		||||
        //public long Count(Expression<Func<DocumentContent, bool>> where)
 | 
			
		||||
        //{
 | 
			
		||||
        //    return DataBaseType.MySql.DB().Select<DocumentContent>()
 | 
			
		||||
        //         .Where(where).Count();
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 查询功能
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="where"></param>
 | 
			
		||||
        /// <param name="orderby"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public (List<DocumentContent> list, long count) Query(Expression<Func<DocumentContent, bool>> where,
 | 
			
		||||
            Expression<Func<DocumentContent, DocumentContent>> orderby = null, PageInfo pageInfo = null)
 | 
			
		||||
        {
 | 
			
		||||
            //设置查询条件
 | 
			
		||||
            var list = DataBaseType.MySql.DB().Select<DocumentContent>()
 | 
			
		||||
                .Where(where);
 | 
			
		||||
        ///// <summary>
 | 
			
		||||
        ///// 查询功能
 | 
			
		||||
        ///// </summary>
 | 
			
		||||
        ///// <param name="where"></param>
 | 
			
		||||
        ///// <param name="orderby"></param>
 | 
			
		||||
        ///// <returns></returns>
 | 
			
		||||
        //public (List<DocumentContent> list, long count) Query(Expression<Func<DocumentContent, bool>> where,
 | 
			
		||||
        //    Expression<Func<DocumentContent, DocumentContent>> orderby = null, PageInfo pageInfo = null)
 | 
			
		||||
        //{
 | 
			
		||||
        //    //设置查询条件
 | 
			
		||||
        //    var list = DataBaseType.MySql.DB().Select<DocumentContent>()
 | 
			
		||||
        //        .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);
 | 
			
		||||
        //}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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<DocumentType>
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 新增方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="model"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public long Insert(DocumentType model)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Insert<DocumentType>(model).ExecuteIdentity();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 修改方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="model"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public bool Update(DocumentType model)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Update<DocumentType>(model.ID).ExecuteUpdated().Count > 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 删除方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="id"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public bool Delete(long id)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Delete<DocumentType>(id).ExecuteDeleted().Count > 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 获取一条数据
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="where"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public DocumentType GetByOne(Expression<Func<DocumentType, bool>> where)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Select<DocumentType>()
 | 
			
		||||
                 .Where(where).ToOne();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 查询方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="where"></param>
 | 
			
		||||
        /// <param name="orderby"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public List<DocumentType> Query(Expression<Func<DocumentType, bool>> where,
 | 
			
		||||
            Expression<Func<DocumentType, DocumentType>> orderby = null)
 | 
			
		||||
        {
 | 
			
		||||
            var list = DataBaseType.MySql.DB().Select<DocumentType>()
 | 
			
		||||
                .Where(where);
 | 
			
		||||
            if (orderby != null) list = list.OrderBy(b => b.CreateDt);
 | 
			
		||||
            return list.ToList();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,62 +7,8 @@ using System.Text;
 | 
			
		||||
 | 
			
		||||
namespace FreeSql.Site.DAL
 | 
			
		||||
{
 | 
			
		||||
    public class TemplateExampleDAL
 | 
			
		||||
    public class TemplateExampleDAL : BaseDAL<TemplateExample>
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 新增方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="model"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public long Insert(TemplateExample model)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Insert<TemplateExample>(model).ExecuteIdentity();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 修改方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="model"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public bool Update(TemplateExample model)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Update<TemplateExample>(model.ID).ExecuteUpdated().Count > 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 删除方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="id"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public bool Delete(long id)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Delete<TemplateExample>(id).ExecuteDeleted().Count > 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 获取一条数据
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="where"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public TemplateExample GetByOne(Expression<Func<TemplateExample, bool>> where)
 | 
			
		||||
        {
 | 
			
		||||
            return DataBaseType.MySql.DB().Select<TemplateExample>()
 | 
			
		||||
                 .Where(where).ToOne();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 查询方法
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="where"></param>
 | 
			
		||||
        /// <param name="orderby"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public List<TemplateExample> Query(Expression<Func<TemplateExample, bool>> where,
 | 
			
		||||
            Expression<Func<TemplateExample, TemplateExample>> orderby = null)
 | 
			
		||||
        {
 | 
			
		||||
            var list = DataBaseType.MySql.DB().Select<TemplateExample>()
 | 
			
		||||
                .Where(where);
 | 
			
		||||
            if (orderby != null) list = list.OrderBy(b => b.CreateDt);
 | 
			
		||||
            return list.ToList();
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										22
									
								
								Examples/website/FreeSql.Site.Entity/BaseEntity.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								Examples/website/FreeSql.Site.Entity/BaseEntity.cs
									
									
									
									
									
										Normal file
									
								
							@@ -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; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 状态
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int Status { get; set; }
 | 
			
		||||
 | 
			
		||||
        public DateTime? CreateDt { get; set; }
 | 
			
		||||
 | 
			
		||||
        public string CreateBy { get; set; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								Examples/website/FreeSql.Site.Entity/Common/TreeNode.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								Examples/website/FreeSql.Site.Entity/Common/TreeNode.cs
									
									
									
									
									
										Normal file
									
								
							@@ -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; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 功能类型(文章、模板、示例等)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
@@ -43,16 +40,5 @@ namespace FreeSql.Site.Entity
 | 
			
		||||
        /// 评论内容
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string CommentContent { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 创建时间
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DateTime? CreateDt { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 创建人
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string CreateBy { get; set; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,11 +7,8 @@ namespace FreeSql.Site.Entity
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 数据库实体
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class DocumentContent
 | 
			
		||||
    public class DocumentContent : BaseEntity
 | 
			
		||||
    {
 | 
			
		||||
        [Column(IsIdentity = true, IsPrimary = true)]
 | 
			
		||||
        public int ID { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 类型编号
 | 
			
		||||
        /// </summary>
 | 
			
		||||
@@ -33,11 +30,6 @@ namespace FreeSql.Site.Entity
 | 
			
		||||
        [Column(DbType = "text")]
 | 
			
		||||
        public string DocContent { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 状态
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int Status { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 查看次数
 | 
			
		||||
        /// </summary>
 | 
			
		||||
@@ -48,15 +40,6 @@ namespace FreeSql.Site.Entity
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int StarCount { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 创建时间
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DateTime? CreateDt { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 创建人
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string CreateBy { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 修改时间
 | 
			
		||||
 
 | 
			
		||||
@@ -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; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 类型名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string TypeName { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 上级类型名称
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int? UpID { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
@@ -18,17 +22,24 @@ namespace FreeSql.Site.Entity
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string Tag { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 状态
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        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; }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 类型树形结构
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class DocumentTypeTreeNode : TreeNode
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 标签
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string tag { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 创建时间
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DateTime? createdt { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,10 +8,8 @@ namespace FreeSql.Site.Entity
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 模板示例
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class TemplateExample
 | 
			
		||||
    public class TemplateExample : BaseEntity
 | 
			
		||||
    {
 | 
			
		||||
        [Column(IsIdentity = true, IsPrimary = true)]
 | 
			
		||||
        public int ID { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 模板图片
 | 
			
		||||
@@ -49,16 +47,13 @@ namespace FreeSql.Site.Entity
 | 
			
		||||
        public int StarCount { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 状态
 | 
			
		||||
        /// 修改时间
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int Status { get; set; }
 | 
			
		||||
 | 
			
		||||
        public DateTime? CreateDt { get; set; }
 | 
			
		||||
 | 
			
		||||
        public string CreateBy { get; set; }
 | 
			
		||||
 | 
			
		||||
        public DateTime? UpdateDt { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 修改人
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string UpdateBy { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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<DocumentType>(seniorQueryJson);
 | 
			
		||||
            }
 | 
			
		||||
            Expression<Func<DocumentType, bool>> predicate = i => 1 == 0;
 | 
			
		||||
            var searchPredicate = PredicateExtensions.True<DocumentType>();
 | 
			
		||||
            if (model != null)
 | 
			
		||||
            {
 | 
			
		||||
                searchPredicate = searchPredicate.And(u => u.Status == 1);
 | 
			
		||||
            }
 | 
			
		||||
            var contents = DocumentTypeDAL.Query(searchPredicate);
 | 
			
		||||
 | 
			
		||||
            return Json(new DataPage<DocumentType>
 | 
			
		||||
            {
 | 
			
		||||
                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<long>((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<bool>((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<long>((result) =>
 | 
			
		||||
            {
 | 
			
		||||
                if (!DocumentContentDAL.Delete(id))
 | 
			
		||||
                {
 | 
			
		||||
                    throw new Exception("数据删除异常,ID:" + id);
 | 
			
		||||
                }
 | 
			
		||||
            }, false);
 | 
			
		||||
            return Json(resdata);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion 
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -16,7 +16,7 @@
 | 
			
		||||
    <div class="layui-btn-container">
 | 
			
		||||
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
 | 
			
		||||
        @*<button class="layui-btn layui-btn-sm" lay-event="delete">删除</button>
 | 
			
		||||
        <button class="layui-btn layui-btn-sm" lay-event="update">编辑</button>*@
 | 
			
		||||
            <button class="layui-btn layui-btn-sm" lay-event="update">编辑</button>*@
 | 
			
		||||
        <div style="float:right;border:0px solid red;">
 | 
			
		||||
            <input type="text" name="search_txt" lay-verify="title" autocomplete="off" placeholder="标题" class="layui-input" style="height: 30px;width:160px;float:left;">
 | 
			
		||||
            <a href="#" style="line-height:30px;margin-left:8px;">高级查询</a>
 | 
			
		||||
@@ -30,21 +30,11 @@
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
    var testEditor;
 | 
			
		||||
    layui.use(['form', 'layedit', 'laydate', 'table'], function () {
 | 
			
		||||
    var contentEdit;
 | 
			
		||||
    layui.use(['form', 'table'], function () {
 | 
			
		||||
        var table = layui.table;
 | 
			
		||||
        var form = layui.form
 | 
			
		||||
            , layer = layui.layer
 | 
			
		||||
            , layedit = layui.layedit
 | 
			
		||||
            , laydate = layui.laydate;
 | 
			
		||||
 | 
			
		||||
        //日期
 | 
			
		||||
        laydate.render({
 | 
			
		||||
            elem: '#date'
 | 
			
		||||
        });
 | 
			
		||||
        laydate.render({
 | 
			
		||||
            elem: '#date1'
 | 
			
		||||
        });
 | 
			
		||||
            , layer = layui.layer;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        table.render({
 | 
			
		||||
@@ -65,7 +55,7 @@
 | 
			
		||||
                , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 }
 | 
			
		||||
            ]]
 | 
			
		||||
            , page: true
 | 
			
		||||
            , id : 'docContentTable'
 | 
			
		||||
            , id: 'docContentTable'
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        var reloadTable = function () {
 | 
			
		||||
@@ -77,6 +67,26 @@
 | 
			
		||||
            });
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        var deleteObj = function (removeRowDatas) {
 | 
			
		||||
            layer.confirm('确定要删除吗?', function (index) {
 | 
			
		||||
                //调用删除
 | 
			
		||||
                $.ajax({
 | 
			
		||||
                    type: "POST",
 | 
			
		||||
                    url: "/Admin/Document/DocContentDelete",
 | 
			
		||||
                    data: { id: rowid },
 | 
			
		||||
                    dataType: "html",
 | 
			
		||||
                    success: function (data) {
 | 
			
		||||
                        obj.del();
 | 
			
		||||
                        layer.close(index);
 | 
			
		||||
                    },
 | 
			
		||||
                    error: function () {
 | 
			
		||||
                        layer.close(index);
 | 
			
		||||
                        layer.alert("删除失败!");
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //监听事件
 | 
			
		||||
        table.on('toolbar(test)', function (obj) {
 | 
			
		||||
            var checkStatus = table.checkStatus(obj.config.id);
 | 
			
		||||
@@ -91,10 +101,11 @@
 | 
			
		||||
                        },
 | 
			
		||||
                        callback: reloadTable
 | 
			
		||||
                    };
 | 
			
		||||
                    dialogWindow.create(options);
 | 
			
		||||
                    freejs.dialogWindow.create(options);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'delete':
 | 
			
		||||
                    layer.msg('删除');
 | 
			
		||||
                    var data = checkStatus.data;
 | 
			
		||||
                    deleteObj(data);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 'update':
 | 
			
		||||
                    layer.msg('编辑');
 | 
			
		||||
@@ -106,6 +117,7 @@
 | 
			
		||||
        table.on('tool(test)', function (obj) {
 | 
			
		||||
            var data = obj.data;
 | 
			
		||||
            if (obj.event === 'del') {
 | 
			
		||||
                deleteObj(obj.data);
 | 
			
		||||
                layer.confirm('确定要删除吗?', function (index) {
 | 
			
		||||
                    //调用删除
 | 
			
		||||
                    $.ajax({
 | 
			
		||||
@@ -133,92 +145,10 @@
 | 
			
		||||
                    },
 | 
			
		||||
                    callback: reloadTable
 | 
			
		||||
                };
 | 
			
		||||
                dialogWindow.create(options);
 | 
			
		||||
 | 
			
		||||
                //form.render();
 | 
			
		||||
                //layer.prompt({
 | 
			
		||||
                //    formType: 2
 | 
			
		||||
                //    , value: data.email
 | 
			
		||||
                //}, function (value, index) {
 | 
			
		||||
                //    obj.update({
 | 
			
		||||
                //        email: value
 | 
			
		||||
                //    });
 | 
			
		||||
                //    layer.close(index);
 | 
			
		||||
                //});
 | 
			
		||||
                freejs.dialogWindow.create(options);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        //先简单封装下
 | 
			
		||||
        var dialogWindow = {
 | 
			
		||||
            create: function (options, formpage) {
 | 
			
		||||
                $("#docContentEdit").load(options.url, options.paramters, function (responseText, textStatus, jqXHR) {
 | 
			
		||||
                    switch (textStatus) {
 | 
			
		||||
                        case "success":
 | 
			
		||||
                            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;
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            },
 | 
			
		||||
            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);
 | 
			
		||||
                    testEditor = 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 () {
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        $(document).on('click', '#btnSubmit', function () {
 | 
			
		||||
            layer.msg('响应点击事件');
 | 
			
		||||
        });
 | 
			
		||||
 
 | 
			
		||||
@@ -3,125 +3,108 @@
 | 
			
		||||
 | 
			
		||||
    //Layout = "~/Areas/Admin/Shared/_Layout.cshtml";
 | 
			
		||||
}
 | 
			
		||||
<style>
 | 
			
		||||
    body {
 | 
			
		||||
        padding: 10px 30px;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
<div id="myeditor" style="display: none">
 | 
			
		||||
    <!-- 富文本编辑器 -->
 | 
			
		||||
    <div id="test-editormd"></div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div id="markdownToHTML" style="margin-left: 100px">
 | 
			
		||||
    <textarea id="content" style="display:none;" placeholder="markdown语言"></textarea>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div class="layui-btn-container" style="margin: 10px">
 | 
			
		||||
    <button id="showEditor" class="layui-btn">显示编辑器</button>
 | 
			
		||||
    <button id="getMarkdownContent" class="layui-btn">获取Markdown源码</button>
 | 
			
		||||
    <button id="getHtmlContent" class="layui-btn">获取Html源码</button>
 | 
			
		||||
    <button id="showHTML" class="layui-btn">Markdown解析成HTML</button>
 | 
			
		||||
</div>
 | 
			
		||||
    .hide {
 | 
			
		||||
        display: none
 | 
			
		||||
    }
 | 
			
		||||
</style>
 | 
			
		||||
<button class="layui-btn layui-btn-primary down-up-all">全部收起/展开</button>
 | 
			
		||||
<button class="layui-btn layui-btn-primary get-checked">获取选中</button>
 | 
			
		||||
 | 
			
		||||
<table class="layui-table layui-form" id="doctype-tree-table"></table>
 | 
			
		||||
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
    layui.use(['layer', 'jquery'], function () {
 | 
			
		||||
        var layer = layui.layer
 | 
			
		||||
            , $ = layui.jquery;
 | 
			
		||||
    layui.use(['treetable', 'form'], function () {
 | 
			
		||||
        var data = @Html.Raw(Html.ToJson(ViewBag.TypeList as List<DocumentTypeTreeNode>));
 | 
			
		||||
 | 
			
		||||
        var testEditor;
 | 
			
		||||
        $('#showEditor').on('click', function () {
 | 
			
		||||
            // 弹出框
 | 
			
		||||
            layer.open({
 | 
			
		||||
                type: 1
 | 
			
		||||
                , content: $('#myeditor')
 | 
			
		||||
                , btn: '关闭全部'
 | 
			
		||||
                , btnAlign: 'c' //按钮居中
 | 
			
		||||
                , shade: 0 //不显示遮罩
 | 
			
		||||
                , area: ['800px', '600px']
 | 
			
		||||
                , yes: function () {
 | 
			
		||||
                    layer.closeAll();
 | 
			
		||||
                },
 | 
			
		||||
                success: function () {
 | 
			
		||||
                    testEditor = editormd("test-editormd", {
 | 
			
		||||
                        width: "90%",
 | 
			
		||||
                        height: 740,
 | 
			
		||||
                        path: "../../lib/editormd/lib/",
 | 
			
		||||
                        theme: "default",
 | 
			
		||||
                        previewTheme: "default",
 | 
			
		||||
                        editorTheme: "default",
 | 
			
		||||
                        //markdown : md,             // 初始化编辑区的内容
 | 
			
		||||
                        codeFold: true,
 | 
			
		||||
                        //syncScrolling : false,
 | 
			
		||||
                        saveHTMLToTextarea: true,    // 保存 HTML 到 Textarea
 | 
			
		||||
                        searchReplace: true,
 | 
			
		||||
                        //watch : false,                // 关闭实时预览
 | 
			
		||||
                        htmlDecode: "style,script,iframe|on*",            // 开启 HTML 标签解析,为了安全性,默认不开启
 | 
			
		||||
                        //toolbar  : false,             //关闭工具栏
 | 
			
		||||
                        //previewCodeHighlight : false, // 关闭预览 HTML 的代码块高亮,默认开启
 | 
			
		||||
                        emoji: true,
 | 
			
		||||
                        taskList: true,
 | 
			
		||||
                        tocm: true,         // Using [TOCM]
 | 
			
		||||
                        tex: true,                   // 开启科学公式TeX语言支持,默认关闭
 | 
			
		||||
                        flowChart: true,             // 开启流程图支持,默认关闭
 | 
			
		||||
                        sequenceDiagram: true,       // 开启时序/序列图支持,默认关闭,
 | 
			
		||||
                        //dialogLockScreen : false,   // 设置弹出层对话框不锁屏,全局通用,默认为true
 | 
			
		||||
                        //dialogShowMask : false,     // 设置弹出层对话框显示透明遮罩层,全局通用,默认为true
 | 
			
		||||
                        //dialogDraggable : false,    // 设置弹出层对话框不可拖动,全局通用,默认为true
 | 
			
		||||
                        //dialogMaskOpacity : 0.4,    // 设置透明遮罩层的透明度,全局通用,默认值为0.1
 | 
			
		||||
                        //dialogMaskBgColor : "#000", // 设置透明遮罩层的背景颜色,全局通用,默认为#fff
 | 
			
		||||
                        imageUpload: true,
 | 
			
		||||
                        imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
 | 
			
		||||
                        imageUploadURL: "./php/upload.php", // 文件上传路径,返回值为图片加载的路径
 | 
			
		||||
                        onload: function () {
 | 
			
		||||
                            // 加载后富文本编辑器成功后的回调
 | 
			
		||||
                            console.log('onload', this);
 | 
			
		||||
                            //this.fullscreen();
 | 
			
		||||
                            //this.unwatch();
 | 
			
		||||
                            //this.watch().fullscreen();
 | 
			
		||||
 | 
			
		||||
                            //this.setMarkdown("#PHP");
 | 
			
		||||
                            //this.width("100%");
 | 
			
		||||
                            //this.height(480);
 | 
			
		||||
                            //this.resize("100%", 640);
 | 
			
		||||
 | 
			
		||||
                            // 异步请求md文件,用于编辑时的数据回显
 | 
			
		||||
                            $.get('test.md', function (md) {
 | 
			
		||||
                                testEditor.setMarkdown(md);
 | 
			
		||||
                            });
 | 
			
		||||
        var o = layui.$, treetable = layui.treetable;
 | 
			
		||||
        var form = layui.form, layer = layui.layer;
 | 
			
		||||
        treetable.render({
 | 
			
		||||
            elem: '#doctype-tree-table',
 | 
			
		||||
            data: data,
 | 
			
		||||
            field: 'title',
 | 
			
		||||
            is_checkbox: true,
 | 
			
		||||
            checked: [1, 2, 3, 4],
 | 
			
		||||
            /*icon_val: {
 | 
			
		||||
                open: "",
 | 
			
		||||
                close: ""
 | 
			
		||||
            },
 | 
			
		||||
            space: 4,*/
 | 
			
		||||
            cols: [
 | 
			
		||||
                {
 | 
			
		||||
                    field: 'title',
 | 
			
		||||
                    title: '标题',
 | 
			
		||||
                    width: '40%',
 | 
			
		||||
                    template: function (item) {
 | 
			
		||||
                        if (item.level == 1) {
 | 
			
		||||
                            return '<span style="color:red;">' + item.title + '</span>';
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
                        if (item.level == 2) {
 | 
			
		||||
                            return '<span style="color:green;">' + item.title + '</span>';
 | 
			
		||||
                        }
 | 
			
		||||
                        return item.title;
 | 
			
		||||
                    }
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    field: 'id',
 | 
			
		||||
                    title: '编号',
 | 
			
		||||
                    width: '10%'
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    title: '标签',
 | 
			
		||||
                    width: '10%',
 | 
			
		||||
                    template: function (item) {
 | 
			
		||||
                        return item.tag||"";//'<input type="checkbox" lay-skin="switch" lay-filter="status" lay-text="开启|关闭">';
 | 
			
		||||
                    }
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    title: '创建时间',
 | 
			
		||||
                    width: '20%',
 | 
			
		||||
                    template: function (item) {
 | 
			
		||||
                        return item.createdt.replace('T',' ') || "";//'<input type="checkbox" lay-skin="switch" lay-filter="status" lay-text="开启|关闭">';
 | 
			
		||||
                    }
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    field: 'actions',
 | 
			
		||||
                    title: '操作',
 | 
			
		||||
                    width: '20%',
 | 
			
		||||
                    template: function (item) {
 | 
			
		||||
                        var tem = [];
 | 
			
		||||
                        tem.push('<button class="layui-btn layui-btn-xs layui-btn-normal">添加子级</button>');
 | 
			
		||||
                        tem.push('<button class="layui-btn layui-btn-xs">编辑</button>');
 | 
			
		||||
                        return tem.join(' ')
 | 
			
		||||
                    },
 | 
			
		||||
                },
 | 
			
		||||
            ]
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        // 获取markdown源码
 | 
			
		||||
        $('#getMarkdownContent').on('click', function () {
 | 
			
		||||
            var mdContent = $('.editormd-markdown-textarea').val();
 | 
			
		||||
            console.log(mdContent);
 | 
			
		||||
            var content = testEditor.getMarkdown();
 | 
			
		||||
            console.log(content);
 | 
			
		||||
        });
 | 
			
		||||
        // 获取解析后的html
 | 
			
		||||
        $('#getHtmlContent').on('click', function () {
 | 
			
		||||
            var content = testEditor.getHTML();
 | 
			
		||||
        treetable.on('treetable(add)', function (data) {
 | 
			
		||||
            layer.msg('添加操作');
 | 
			
		||||
            console.log(data);
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
            console.log(content);
 | 
			
		||||
        });
 | 
			
		||||
        treetable.on('treetable(edit)', function (data) {
 | 
			
		||||
            layer.msg('编辑操作');
 | 
			
		||||
            console.log(data);
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        // 页面解析markdown为html进行显示
 | 
			
		||||
        $('#showHTML').on('click', function () {
 | 
			
		||||
            // 模拟从数据库中取内容
 | 
			
		||||
            $.get('test.md', function (md) {
 | 
			
		||||
                // 给textarea赋值
 | 
			
		||||
                $('#content').val(md);
 | 
			
		||||
                // 解析
 | 
			
		||||
                editormd.markdownToHTML("markdownToHTML", {
 | 
			
		||||
                    htmlDecode: "style,script,iframe",
 | 
			
		||||
                    emoji: true,  // 解析表情
 | 
			
		||||
                    taskList: true,  // 解析列表
 | 
			
		||||
                    tex: true,  // 默认不解析
 | 
			
		||||
                    flowChart: true,  // 默认不解析
 | 
			
		||||
                    sequenceDiagram: true  // 默认不解析
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
        o('.down-up-all').click(function () {
 | 
			
		||||
            var expandStatus = o(this).attr("expandStatus");
 | 
			
		||||
            expandStatus == "down" ? treetable.all('up') : treetable.all('down');
 | 
			
		||||
            expandStatus == "down" ? o(this).attr('expandStatus', 'up') : o(this).attr('expandStatus', 'down');
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        o('.get-checked').click(function () {
 | 
			
		||||
            console.log(treetable.all('checked'));
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        form.on('switch(status)', function (data) {
 | 
			
		||||
            layer.msg('监听状态操作');
 | 
			
		||||
            console.log(data);
 | 
			
		||||
        })
 | 
			
		||||
    });
 | 
			
		||||
</script>
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
            //适应两层结构即可
 | 
			
		||||
 
 | 
			
		||||
@@ -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"];
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@
 | 
			
		||||
    <Folder Include="Areas\Doc\Models\" />
 | 
			
		||||
    <Folder Include="Areas\Example\Data\" />
 | 
			
		||||
    <Folder Include="Areas\Example\Models\" />
 | 
			
		||||
    <Folder Include="wwwroot\layui\ext\treetable\js\" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
@using FreeSql.Site.UI
 | 
			
		||||
@using FreeSql.Site.UI.Models
 | 
			
		||||
@using FreeSql.Site.UI.Common
 | 
			
		||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
@@ -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;}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -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;}
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 7.4 KiB  | 
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 116 KiB  | 
@@ -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 ? '<td><input type="checkbox" lay-skin="primary" lay-filter="lay-t"></td>' : '';
 | 
			
		||||
        o.each(t.c.cols, function (idx, obj) {
 | 
			
		||||
            thead += '<th style="width:' + obj.width + '">' + obj.title + "</th>"
 | 
			
		||||
        });
 | 
			
		||||
        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 = '<tr data-id="' + item.id + '" data-pid="' + item.pid + '" ' + hide_class + ">" +
 | 
			
		||||
                    (t.c.is_checkbox ? '<td><div><input type="checkbox" lay-skin="primary" lay-filter="lay-t" ' + checked + '></div></td>' : "");
 | 
			
		||||
            item.level = level[item.id] = item.pid > 0 ? (level[item.pid] + 1) : 0;
 | 
			
		||||
            o.each(t.c.cols, function (idx, obj) {
 | 
			
		||||
                tr += '<td style="width:' + obj.width + '">';
 | 
			
		||||
                if (obj.field == t.c.field) {
 | 
			
		||||
                    tr += (" ".repeat(level[item.id] * t.c.space));
 | 
			
		||||
                    if (t.c.childs[item.id]) {
 | 
			
		||||
                        tr += '<i class="layui-icon ' + t.c.icon_class + '">' + (item.id == t.cache(item.id) || t.c.is_open ? t.c.icon_val.close : t.c.icon_val.open) + "</i>"
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                tr += (obj.template ? obj.template(item) : (item[obj.field] !== undefined ? item[obj.field] : '')) + "</td>"
 | 
			
		||||
            });
 | 
			
		||||
            tbody += tr + "</tr>";
 | 
			
		||||
        });
 | 
			
		||||
        return '<thead><tr data-id="0" data-pid="-1">' + thead + "</tr></thead><tbody>" + tbody + "</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)
 | 
			
		||||
});
 | 
			
		||||
		Reference in New Issue
	
	Block a user