public override void Process(TagHelperContext context, TagHelperOutput output) { if (Loading == null) { Loading = true; } var vmQualifiedName = Vm.Model.GetType().AssemblyQualifiedName; vmQualifiedName = vmQualifiedName.Substring(0, vmQualifiedName.LastIndexOf(", Version=", StringComparison.CurrentCulture)); var tempGridTitleId = Guid.NewGuid().ToNoSplitString(); output.TagName = "table"; output.Attributes.Add("id", Id); output.Attributes.Add("lay-filter", Id); output.TagMode = TagMode.StartTagAndEndTag; if (Limit == null) { Limit = GlobalServices.GetRequiredService <Configs>()?.UiOptions.DataTable.RPP; } if (Limits == null) { Limits = new int[] { 10, 20, 50, 80, 100, 150, 200 }; if (!Limits.Contains(Limit.Value)) { var list = Limits.ToList(); list.Add(Limit.Value); Limits = list.OrderBy(x => x).ToArray(); } } if (UseLocalData) // 不需要分页 { ListVM.NeedPage = false; } else { if (string.IsNullOrEmpty(Url)) { Url = "/_Framework/GetPagingData"; } if (Filter == null) { Filter = new Dictionary <string, object>(); } Filter.Add("_DONOT_USE_VMNAME", vmQualifiedName); Filter.Add("_DONOT_USE_CS", ListVM.CurrentCS); Filter.Add("SearcherMode", ListVM.SearcherMode); if (ListVM.Ids != null && ListVM.Ids.Count > 0) { Filter.Add("Ids", ListVM.Ids); } // 为首次加载添加Searcher查询参数 if (ListVM.Searcher != null) { var props = ListVM.Searcher.GetType().GetProperties(); props = props.Where(x => !_excludeTypes.Contains(x.PropertyType)).ToArray(); foreach (var prop in props) { if (!_excludeParams.Contains(prop.Name)) { if (prop.PropertyType.IsGenericType == false || (prop.PropertyType.GenericTypeArguments[0] != typeof(ComboSelectListItem) && prop.PropertyType.GenericTypeArguments[0] != typeof(TreeSelectListItem))) { Filter.Add($"Searcher.{prop.Name}", prop.GetValue(ListVM.Searcher)); } } } } } // 是否需要分页 var page = ListVM.NeedPage; #region 生成 Layui 所需的表头 var rawCols = ListVM?.GetHeaders(); var maxDepth = (ListVM?.ChildrenDepth) ?? 1; var layuiCols = new List <List <LayuiColumn> >(); var tempCols = new List <LayuiColumn>(); layuiCols.Add(tempCols); // 添加复选框 if (!HiddenCheckbox) { var checkboxHeader = new LayuiColumn() { Type = LayuiColumnTypeEnum.Checkbox, LAY_CHECKED = CheckedAll, Rowspan = maxDepth, Fixed = GridColumnFixedEnum.Left, UnResize = true, //Width = 45 }; tempCols.Add(checkboxHeader); } // 添加序号列 if (!HiddenGridIndex) { var gridIndex = new LayuiColumn() { Type = LayuiColumnTypeEnum.Numbers, Rowspan = maxDepth, Fixed = GridColumnFixedEnum.Left, UnResize = true, //Width = 45 }; tempCols.Add(gridIndex); } var nextCols = new List <IGridColumn <TopBasePoco> >();// 下一级列头 generateColHeader(rawCols, nextCols, tempCols, maxDepth); if (nextCols.Count > 0) { CalcChildCol(layuiCols, nextCols, maxDepth, 1); } if (layuiCols.Count > 0 && layuiCols[0].Count > 0) { layuiCols[0][0].TotalRowText = ListVM?.TotalText; } #endregion #region 处理 DataTable 操作按钮 var actionCol = ListVM?.GridActions; var rowBtnStrBuilder = new StringBuilder(); // Grid 行内按钮 var toolBarBtnStrBuilder = new StringBuilder(); // Grid 工具条按钮 var gridBtnEventStrBuilder = new StringBuilder(); // Grid 按钮事件 if (actionCol != null && actionCol.Count > 0) { var vm = Vm.Model as BaseVM; foreach (var item in actionCol) { AddSubButton(vmQualifiedName, rowBtnStrBuilder, toolBarBtnStrBuilder, gridBtnEventStrBuilder, vm, item); } } #endregion #region DataTable var vmName = string.Empty; if (VMType != null) { var vmQualifiedName1 = VMType.AssemblyQualifiedName; vmName = vmQualifiedName1.Substring(0, vmQualifiedName1.LastIndexOf(", Version=", StringComparison.CurrentCulture)); } output.PostElement.AppendHtml($@" <script> var {Id}option = null; /* 监听工具条 */ function wtToolBarFunc_{Id}(obj){{ //注:tool是工具条事件名,test是table原始容器的属性 lay-filter=""对应的值"" var data = obj.data, layEvent = obj.event, tr = obj.tr; //获得当前行 tr 的DOM对象 {(gridBtnEventStrBuilder.Length == 0 ? string.Empty : $@"switch(layEvent){{{gridBtnEventStrBuilder}default:break;}}")} return; }} layui.use(['table'], function(){{ var table = layui.table; {Id}option = {{ elem: '#{Id}' ,id: '{Id}' {(!NeedShowTotal ? string.Empty : ",totalRow:true")} {(UseLocalData ? string.Empty : $",url: '{Url}'")} {(Filter == null || Filter.Count == 0 ? string.Empty : $",where: {JsonConvert.SerializeObject(Filter)}")} {(Method == null ? ",method:'post'" : $",method: '{Method.Value.ToString().ToLower()}'")} {(Loading ?? true ? string.Empty : ",loading:false")} {(page ? string.Empty : ",page:{layout:['count']}")} {(page ? $",limit:{Limit}" : $",limit:{(UseLocalData ? ListVM.GetEntityList().Count().ToString() : "0")}")} {(page ? (Limits == null || Limits.Length == 0 ? string.Empty : $",limits:[{string.Join(',', Limits)}]" ) : string.Empty)} {(!Width.HasValue ? string.Empty : $",width: {Width.Value}")} {(!Height.HasValue ? string.Empty : (Height.Value >= 0 ? $",height: {Height.Value}" : $",height: 'full{Height.Value}'"))} ,cols:{JsonConvert.SerializeObject(layuiCols, _jsonSerializerSettings)} {(!Skin.HasValue ? string.Empty : $",skin: '{Skin.Value.ToString().ToLower()}'")} {(Even.HasValue && !Even.Value ? $",even: false" : string.Empty)} {(!Size.HasValue ? string.Empty : $",size: '{Size.Value.ToString().ToLower()}'")} ,done: function(res,curr,count){{ var tab = $('#{Id} + .layui-table-view');tab.find('table').css('border-collapse','separate'); {(Height == null ? $"tab.css('overflow','hidden').addClass('donotuse_fill donotuse_pdiv');tab.children('.layui-table-box').addClass('donotuse_fill donotuse_pdiv').css('height','100px');tab.find('.layui-table-main').addClass('donotuse_fill');tab.find('.layui-table-header').css('min-height','40px');ff.triggerResize();" : string.Empty)} {(MultiLine == true ? $"tab.find('.layui-table-cell').css('height','auto').css('white-space','normal');" : string.Empty)} {(string.IsNullOrEmpty(DoneFunc) ? string.Empty : $"{DoneFunc}(res,curr,count)")}
public override void Process(TagHelperContext context, TagHelperOutput output) { if (Loading == null) { Loading = true; } var vmQualifiedName = Vm.Model.GetType().AssemblyQualifiedName; vmQualifiedName = vmQualifiedName.Substring(0, vmQualifiedName.LastIndexOf(", Version=", StringComparison.CurrentCulture)); var tempGridTitleId = Guid.NewGuid().ToNoSplitString(); output.TagName = "table"; output.Attributes.Add("id", Id); output.Attributes.Add("lay-filter", Id); output.TagMode = TagMode.StartTagAndEndTag; var config = GlobalServices.GetRequiredService <Configs>(); if (UseLocalData == false) { if (NeedShowPrint == null) { NeedShowPrint = config?.UiOptions.DataTable.ShowPrint; } if (NeedShowFilter == null) { NeedShowFilter = config?.UiOptions.DataTable.ShowFilter; } } var righttoolbar = ",defaultToolbar: []"; int lefttoolbarmergin = -120; if (NeedShowFilter == true && NeedShowPrint == true) { righttoolbar = ",defaultToolbar: ['filter', 'print']"; lefttoolbarmergin = -45; } else { if (NeedShowFilter == true) { righttoolbar = ",defaultToolbar: ['filter']"; lefttoolbarmergin = -80; } if (NeedShowPrint == true) { righttoolbar = ",defaultToolbar: ['print']"; lefttoolbarmergin = -80; } } if (Limit == null) { Limit = config?.UiOptions.DataTable.RPP; } if (Limits == null) { Limits = new int[] { 10, 20, 50, 80, 100, 150, 200 }; if (!Limits.Contains(Limit.Value)) { var list = Limits.ToList(); list.Add(Limit.Value); Limits = list.OrderBy(x => x).ToArray(); } } if (UseLocalData) // 不需要分页 { ListVM.NeedPage = false; } else { if (string.IsNullOrEmpty(Url)) { // TODO 已废弃,预计v3.0版本及v2.10版本开始将删除 Url = "/_Framework/GetPagingData"; } if (Filter == null) { Filter = new Dictionary <string, object>(); } Filter.Add("_DONOT_USE_VMNAME", vmQualifiedName); Filter.Add("_DONOT_USE_CS", ListVM.CurrentCS); Filter.Add("SearcherMode", ListVM.SearcherMode); Filter.Add("ViewDivId", ListVM.ViewDivId); if (ListVM.Ids != null && ListVM.Ids.Count > 0) { Filter.Add("Ids", ListVM.Ids); } // 为首次加载添加Searcher查询参数 if (ListVM.Searcher != null) { var props = ListVM.Searcher.GetType().GetProperties(); props = props.Where(x => !_excludeTypes.Contains(x.PropertyType)).ToArray(); foreach (var prop in props) { if (!_excludeParams.Contains(prop.Name)) { if (prop.PropertyType.IsGenericType == false || (prop.PropertyType.GenericTypeArguments[0] != typeof(ComboSelectListItem) && prop.PropertyType.GenericTypeArguments[0] != typeof(TreeSelectListItem))) { var listvalue = prop.GetValue(ListVM.Searcher); if (listvalue != null) { Filter.Add($"Searcher.{prop.Name}", prop.GetValue(ListVM.Searcher)); } } } } } } // 是否需要分页 var page = ListVM.NeedPage; #region 生成 Layui 所需的表头 var rawCols = ListVM?.GetHeaders(); var maxDepth = (ListVM?.GetChildrenDepth()) ?? 1; var layuiCols = new List <List <LayuiColumn> >(); var tempCols = new List <LayuiColumn>(); layuiCols.Add(tempCols); // 添加复选框 if (!HiddenCheckbox) { var checkboxHeader = new LayuiColumn() { Type = LayuiColumnTypeEnum.Checkbox, LAY_CHECKED = CheckedAll, Rowspan = maxDepth, Fixed = GridColumnFixedEnum.Left, UnResize = true, //Width = 45 }; tempCols.Add(checkboxHeader); } // 添加序号列 if (!HiddenGridIndex) { var gridIndex = new LayuiColumn() { Type = LayuiColumnTypeEnum.Numbers, Rowspan = maxDepth, Fixed = GridColumnFixedEnum.Left, UnResize = true, //Width = 45 }; tempCols.Add(gridIndex); } var nextCols = new List <IGridColumn <TopBasePoco> >();// 下一级列头 generateColHeader(rawCols, nextCols, tempCols, maxDepth); if (nextCols.Count > 0) { CalcChildCol(layuiCols, nextCols, maxDepth, 1); } if (layuiCols.Count > 0 && layuiCols[0].Count > 0) { layuiCols[0][0].TotalRowText = ListVM?.TotalText; } #endregion #region 处理 DataTable 操作按钮 var actionCol = ListVM?.GetGridActions(); var rowBtnStrBuilder = new StringBuilder(); // Grid 行内按钮 var toolBarBtnStrBuilder = new StringBuilder(); // Grid 工具条按钮 var gridBtnEventStrBuilder = new StringBuilder(); // Grid 按钮事件 if (actionCol != null && actionCol.Count > 0) { var vm = Vm.Model as BaseVM; foreach (var item in actionCol) { AddSubButton(vmQualifiedName, rowBtnStrBuilder, toolBarBtnStrBuilder, gridBtnEventStrBuilder, vm, item); } } if (hasButtonGroup == true) { toolBarBtnStrBuilder.Append($@"<script type=""text/javascript"" des=""buttongroup"">layui.use([""form""], function () {{ var form = layui.form, $ = layui.jquery; $("".downpanel"").on(""click"", "".layui-select-title"", function(e) {{ $("".layui-form-select"").not($(this).parents("".layui-form-select"")).removeClass(""layui-form-selected""); $(this).parents("".layui-form-select"").toggleClass(""layui-form-selected""); e.stopPropagation(); }}); $(document).click(function(event) {{ var _con2 = $("".downpanel""); if (!_con2.is (event.target) && (_con2.has(event.target).length === 0)) {{ _con2.removeClass(""layui -form-selected""); }} }}); }});</script>"); } #endregion #region DataTable var toolbardef = ""; if (toolBarBtnStrBuilder.Length > 0 || NeedShowFilter == true || NeedShowPrint == true) { toolbardef = $" ,toolbar: '#{ToolBarId}2'"; } var vmName = string.Empty; if (VMType != null) { var vmQualifiedName1 = VMType.AssemblyQualifiedName; vmName = vmQualifiedName1.Substring(0, vmQualifiedName1.LastIndexOf(", Version=", StringComparison.CurrentCulture)); } output.PostElement.AppendHtml($@" <script> var {Id}option = null; /* 监听工具条 */ function wtToolBarFunc_{Id}(obj){{ //注:tool是工具条事件名,test是table原始容器的属性 lay-filter=""对应的值"" var data = obj.data, layEvent = obj.event, tr = obj.tr; //获得当前行 tr 的DOM对象 {(gridBtnEventStrBuilder.Length == 0 ? string.Empty : $@"var ids; var objs;switch(layEvent){{{gridBtnEventStrBuilder}default:break;}}")} return; }} layui.use(['table'], function(){{ var table = layui.table; {Id}option = {{ elem: '#{Id}' ,id: '{Id}' ,text:{{ none:'{Program._localizer["NoData"]}' }} {toolbardef} {righttoolbar} {(!NeedShowTotal ? string.Empty : ",totalRow:true")} {(UseLocalData ? string.Empty : $",url: '{Url}'")} ,headers: {{layuisearch: 'true'}} {(Filter == null || Filter.Count == 0 ? string.Empty : $",where: {JsonConvert.SerializeObject(Filter)}")} {(Method == null ? ",method:'post'" : $",method: '{Method.Value.ToString().ToLower()}'")} {(Loading ?? true ? string.Empty : ",loading:false")} {(page ? $@",page:{{ rpptext:'{Program._localizer["RecordsPerPage"]}', totaltext:'{Program._localizer["Total"]}', recordtext:'{Program._localizer["Record"]}', gototext:'{Program._localizer["Goto"]}', pagetext:'{Program._localizer["Page"]}', oktext:'{Program._localizer["GotoButtonText"]}', }}":",page:false")} {(page ? $",limit:{Limit}" : $",limit:{(UseLocalData ? ListVM.GetEntityList().Count().ToString() : "0")}")} {(page ? (Limits == null || Limits.Length == 0 ? string.Empty : $",limits:[{string.Join(',', Limits)}]" ) : string.Empty)} {(!Width.HasValue ? string.Empty : $",width: {Width.Value}")} {(!Height.HasValue ? string.Empty : (Height.Value >= 0 ? $",height: {Height.Value}" : $",height: 'full{Height.Value}'"))} ,cols:{JsonConvert.SerializeObject(layuiCols, _jsonSerializerSettings)} {(!Skin.HasValue ? string.Empty : $",skin: '{Skin.Value.ToString().ToLower()}'")} {(Even.HasValue && !Even.Value ? $",even: false" : string.Empty)} {(!Size.HasValue ? string.Empty : $",size: '{Size.Value.ToString().ToLower()}'")} ,done: function(res,curr,count){{ this.where={Id}defaultfilter.where; if(res.Code == 401){{ layui.layer.confirm(res.Msg,{{title:'{Program._localizer["Error"]}'}}, function(index){{window.location.reload();layer.close(index);}});}} if(res.Code != undefined && res.Code != 200){{ layui.layer.alert(res.Msg,{{title:'{Program._localizer["Error"]}'}});}} var tab = $('#{Id} + .layui-table-view');tab.find('table').css('border-collapse','separate'); {(Height == null ? $"tab.css('overflow','hidden').addClass('donotuse_fill donotuse_pdiv');tab.children('.layui-table-box').addClass('donotuse_fill donotuse_pdiv').css('height','100px');tab.find('.layui-table-main').addClass('donotuse_fill');tab.find('.layui-table-header').css('min-height','40px');ff.triggerResize();" : string.Empty)} {(MultiLine == true ? $"tab.find('.layui-table-cell').css('height','auto').css('white-space','normal');" : string.Empty)} tab.find('div [lay-event=\'LAYTABLE_COLS\']').attr('title','{Program._localizer["ColumnFilter"]}'); tab.find('div [lay-event=\'LAYTABLE_PRINT\']').attr('title','{Program._localizer["Print"]}'); {(string.IsNullOrEmpty(DoneFunc) ? string.Empty : $"{DoneFunc}(res,curr,count)")}
public override void Process(TagHelperContext context, TagHelperOutput output) { if (Loading == null) { Loading = true; } var vmQualifiedName = Vm.Model.GetType().AssemblyQualifiedName; vmQualifiedName = vmQualifiedName.Substring(0, vmQualifiedName.LastIndexOf(", Version=")); var tempGridTitleId = Guid.NewGuid().ToNoSplitString(); output.TagName = "table"; output.Attributes.Add("id", Id); output.Attributes.Add("lay-filter", Id); output.TagMode = TagMode.StartTagAndEndTag; //IEnumerable<TopBasePoco> data = null; if (Limit == null) { Limit = GlobalServices.GetRequiredService <Configs>()?.RPP; } if (Limits == null) { Limits = new int[] { 10, 20, 50, 80, 100, 150, 200 }; if (!Limits.Contains(Limit.Value)) { var list = Limits.ToList(); list.Add(Limit.Value); Limits = list.OrderBy(x => x).ToArray(); } } // TODO 转换有问题 Page = ListVM.NeedPage; if (UseLocalData) { // 不需要分页 ListVM.NeedPage = false; //data = ListVM.GetEntityList().ToList(); } else if (string.IsNullOrEmpty(Url)) { Url = "/_Framework/GetPagingData"; if (Filter == null) { Filter = new Dictionary <string, object>(); } Filter.Add("_DONOT_USE_VMNAME", vmQualifiedName); Filter.Add("_DONOT_USE_CS", ListVM.CurrentCS); Filter.Add("SearcherMode", ListVM.SearcherMode); if (ListVM.Ids != null && ListVM.Ids.Count > 0) { Filter.Add("Ids", ListVM.Ids); } // 为首次加载添加Searcher查询参数 if (ListVM.Searcher != null) { var props = ListVM.Searcher.GetType().GetProperties(); props = props.Where(x => !_excludeTypes.Contains(x.PropertyType)).ToArray(); foreach (var prop in props) { if (!_excludeParams.Contains(prop.Name)) { Filter.Add($"Searcher.{prop.Name}", prop.GetValue(ListVM.Searcher)); } } } } var request = new Dictionary <string, object> { { "pageName", "Searcher.Page" }, //页码的参数名称,默认:page { "limitName", "Searcher.Limit" }, //每页数据量的参数名,默认:limit }; var response = new Dictionary <string, object> { { "statusName", "Code" }, //数据状态的字段名称,默认:code { "statusCode", 200 }, //成功的状态码,默认:0 { "msgName", "Msg" }, //状态信息的字段名称,默认:msg { "countName", "Count" }, //数据总数的字段名称,默认:count { "dataName", "Data" } //数据列表的字段名称,默认:data }; #region 生成 Layui 所需的表头 var rawCols = ListVM?.GetHeaders(); var maxDepth = (ListVM?.ChildrenDepth) ?? 1; var layuiCols = new List <List <LayuiColumn> >(); var tempCols = new List <LayuiColumn>(); layuiCols.Add(tempCols); // 添加复选框 if (!HiddenCheckbox) { var checkboxHeader = new LayuiColumn() { Type = LayuiColumnTypeEnum.Checkbox, LAY_CHECKED = CheckedAll, Rowspan = maxDepth }; tempCols.Add(checkboxHeader); } // 添加序号列 if (!HiddenGridIndex) { var gridIndex = new LayuiColumn() { Type = LayuiColumnTypeEnum.Numbers, Rowspan = maxDepth }; tempCols.Add(gridIndex); } var nextCols = new List <IGridColumn <TopBasePoco> >();// 下一级列头 foreach (var item in rawCols) { var tempCol = new LayuiColumn() { Title = item.Title, Field = item.Field, Width = item.Width, Sort = item.Sort, Fixed = item.Fixed, Align = item.Align, UnResize = item.UnResize, Hide = item.Hide, //Style = "height:auto !important;white-space:normal !important" //EditType = item.EditType }; switch (item.ColumnType) { case GridColumnTypeEnum.Space: tempCol.Type = LayuiColumnTypeEnum.Space; break; case GridColumnTypeEnum.Action: tempCol.Toolbar = $"#{ToolBarId}"; break; default: break; } if (item.Children != null && item.Children.Count() > 0) { tempCol.Colspan = item.ChildrenLength; } if (maxDepth > 1 && (item.Children == null || item.Children.Count() == 0)) { tempCol.Rowspan = maxDepth; } tempCols.Add(tempCol); if (item.Children != null && item.Children.Count() > 0) { nextCols.AddRange(item.Children); } } if (nextCols.Count > 0) { CalcChildCol(layuiCols, nextCols, maxDepth, 1); } #endregion #region 处理 DataTable 操作按钮 var actionCol = ListVM?.GridActions; var rowBtnStrBuilder = new StringBuilder(); // Grid 行内按钮 var toolBarBtnStrBuilder = new StringBuilder(); // Grid 工具条按钮 var gridBtnEventStrBuilder = new StringBuilder(); // Grid 按钮事件 if (actionCol != null && actionCol.Count > 0) { var vm = Vm.Model as BaseVM; foreach (var item in actionCol) { AddSubButton(vmQualifiedName, rowBtnStrBuilder, toolBarBtnStrBuilder, gridBtnEventStrBuilder, vm, item); } } #endregion #region DataTable var vmName = string.Empty; if (VMType != null) { var vmQualifiedName1 = VMType.AssemblyQualifiedName; vmName = vmQualifiedName1.Substring(0, vmQualifiedName1.LastIndexOf(", Version=")); } output.PostElement.AppendHtml($@" <script> var table = layui.table; /* 暂时解决 layui table首次及table.reload()无loading的bug */ var layer = layui.layer; var msg = layer.msg('数据请求中', {{ icon: 16, time: -1, anim: -1, fixed: false }}) /* 暂时解决 layui table首次及table.reload()无loading的bug */ var {Id}option = {{ elem: '#{Id}' ,id: '{Id}' ,autoSort: false {(string.IsNullOrEmpty(Url) ? string.Empty : $",url: '{Url}'")} {(Filter == null || Filter.Count == 0 ? string.Empty : $",where: {JsonConvert.SerializeObject(Filter)}")} {(Method == null ? ",method:'post'" : $",method: '{Method.Value.ToString().ToLower()}'")} {(UseLocalData ? $",data: {ListVM.GetDataJson()}" : string.Empty)} {(!Loading.HasValue ? string.Empty : $",loading: {Loading.Value.ToString().ToLower()}")} ,request: {JsonConvert.SerializeObject(request)} ,response: {JsonConvert.SerializeObject(response)} {(Page ?? true ? ",page:true" : ",page:{layout:['count']}")} ,limit: {(Page ?? true ? $"{Limit ?? 50}" : $"{(UseLocalData ? ListVM.GetEntityList().Count().ToString() : "0")}")} {(Page ?? true ? (Limits == null || Limits.Length == 0 ? ",limits:[10,20,50,80,100,150,200]" : $",limits:{JsonConvert.SerializeObject(Limits)}") : string.Empty)} {(!Width.HasValue ? string.Empty : $",width: {Width.Value}")} {(!Height.HasValue ? string.Empty : (Height.Value >= 0 ? $",height: {Height.Value}" : $",height: 'full{Height.Value}'"))} ,cols:{JsonConvert.SerializeObject(layuiCols, _jsonSerializerSettings)} {(!Skin.HasValue ? string.Empty : $",skin: '{Skin.Value.ToString().ToLower()}'")} {(!Even.HasValue ? ",even: true" : $",even: {Even.Value.ToString().ToLower()}")} {(!Size.HasValue ? string.Empty : $",size: '{Size.Value.ToString().ToLower()}'")} ,done: function(res,curr,count){{layer.close(msg); var tab = $('#{Id} + .layui-table-view');tab.find('table').css('border-collapse','separate'); {(Height == null ? $"tab.css('overflow','hidden').addClass('donotuse_fill donotuse_pdiv');tab.children('.layui-table-box').addClass('donotuse_fill donotuse_pdiv').css('height','100px');tab.find('.layui-table-main').addClass('donotuse_fill');tab.find('.layui-table-header').css('min-height','40px');ff.triggerResize();" : string.Empty)} {(MultiLine == true ? $"tab.find('.layui-table-cell').css('height','auto').css('white-space','normal');" : string.Empty)} {(string.IsNullOrEmpty(DoneFunc) ? string.Empty : $"{DoneFunc}(res,curr,count)")}
public override void Process(TagHelperContext context, TagHelperOutput output) { if (Loading == null) { Loading = true; } var vmQualifiedName = Vm.Model.GetType().AssemblyQualifiedName; vmQualifiedName = vmQualifiedName.Substring(0, vmQualifiedName.LastIndexOf(", Version=")); var tempGridTitleId = Guid.NewGuid().ToNoSplitString(); output.TagName = "table"; output.Attributes.Add("id", Id); output.Attributes.Add("lay-filter", Id); output.TagMode = TagMode.StartTagAndEndTag; //IEnumerable<TopBasePoco> data = null; if (Limit == null) { Limit = GlobalServices.GetRequiredService <Configs>()?.RPP; } if (Limits == null) { Limits = new int[] { 10, 20, 50, 80, 100, 150, 200 }; if (!Limits.Contains(Limit.Value)) { var list = Limits.ToList(); list.Add(Limit.Value); Limits = list.OrderBy(x => x).ToArray(); } } // TODO 转换有问题 Page = ListVM.NeedPage; if (UseLocalData) { // 不需要分页 ListVM.NeedPage = false; //data = ListVM.GetEntityList().ToList(); } else if (string.IsNullOrEmpty(Url)) { Url = "/_Framework/GetPagingData"; if (Filter == null) { Filter = new Dictionary <string, object>(); } Filter.Add("_DONOT_USE_VMNAME", vmQualifiedName); Filter.Add("SearcherMode", ListVM.SearcherMode); if (ListVM.Ids != null && ListVM.Ids.Count > 0) { Filter.Add("Ids", ListVM.Ids); } // 为首次加载添加Searcher查询参数 if (ListVM.Searcher != null) { var props = ListVM.Searcher.GetType().GetProperties(); props = props.Where(x => !_excludeTypes.Contains(x.PropertyType)).ToArray(); foreach (var prop in props) { if (!_excludeParams.Contains(prop.Name)) { Filter.Add($"Searcher.{prop.Name}", prop.GetValue(ListVM.Searcher)); } } } } var request = new Dictionary <string, object> { { "pageName", "Searcher.Page" }, //页码的参数名称,默认:page { "limitName", "Searcher.Limit" }, //每页数据量的参数名,默认:limit }; var response = new Dictionary <string, object> { { "statusName", "Code" }, //数据状态的字段名称,默认:code { "statusCode", 200 }, //成功的状态码,默认:0 { "msgName", "Msg" }, //状态信息的字段名称,默认:msg { "countName", "Count" }, //数据总数的字段名称,默认:count { "dataName", "Data" } //数据列表的字段名称,默认:data }; #region 生成 Layui 所需的表头 var rawCols = ListVM?.GetHeaders(); var maxDepth = (ListVM?.ChildrenDepth) ?? 1; var layuiCols = new List <List <LayuiColumn> >(); var tempCols = new List <LayuiColumn>(); layuiCols.Add(tempCols); // 添加复选框 if (!HiddenCheckbox) { var checkboxHeader = new LayuiColumn() { Type = LayuiColumnTypeEnum.Checkbox, LAY_CHECKED = CheckedAll, Rowspan = maxDepth }; tempCols.Add(checkboxHeader); } // 添加序号列 if (!HiddenGridIndex) { var gridIndex = new LayuiColumn() { Type = LayuiColumnTypeEnum.Numbers, Rowspan = maxDepth }; tempCols.Add(gridIndex); } var nextCols = new List <IGridColumn <TopBasePoco> >();// 下一级列头 foreach (var item in rawCols) { var tempCol = new LayuiColumn() { Title = item.Title, Field = item.Field, Width = item.Width, Sort = item.Sort, Fixed = item.Fixed, Align = item.Align, UnResize = item.UnResize, //EditType = item.EditType }; switch (item.ColumnType) { case GridColumnTypeEnum.Space: tempCol.Type = LayuiColumnTypeEnum.Space; break; case GridColumnTypeEnum.Action: tempCol.Toolbar = $"#{ToolBarId}"; break; default: break; } if (item.Children != null && item.Children.Count() > 0) { tempCol.Colspan = item.ChildrenLength; } if (maxDepth > 1 && (item.Children == null || item.Children.Count() == 0)) { tempCol.Rowspan = maxDepth; } tempCols.Add(tempCol); if (item.Children != null && item.Children.Count() > 0) { nextCols.AddRange(item.Children); } } if (nextCols.Count > 0) { CalcChildCol(layuiCols, nextCols, maxDepth, 1); } #endregion #region 处理 DataTable 操作按钮 var actionCol = ListVM?.GridActions; var rowBtnStrBuilder = new StringBuilder(); // Grid 行内按钮 var toolBarBtnStrBuilder = new StringBuilder(); // Grid 工具条按钮 var gridBtnEventStrBuilder = new StringBuilder(); // Grid 按钮事件 if (actionCol != null && actionCol.Count > 0) { var vm = Vm.Model as BaseVM; foreach (var item in actionCol) { if (vm.LoginUserInfo?.IsAccessable(item.Url) == true || item.ParameterType == GridActionParameterTypesEnum.AddRow || item.ParameterType == GridActionParameterTypesEnum.RemoveRow) { // Grid 行内按钮 if (item.ShowInRow) { if (item.ParameterType != GridActionParameterTypesEnum.RemoveRow) { rowBtnStrBuilder.Append($@"<a class=""layui-btn layui-btn-primary layui-btn-xs"" lay-event=""{item.Area + item.ControllerName + item.ActionName + item.QueryString}"">{item.Name}</a>"); } else { rowBtnStrBuilder.Append($@"<a class=""layui-btn layui-btn-primary layui-btn-xs"" onclick=""ff.RemoveGridRow('{Id}',{Id}option,{{{{d.LAY_INDEX}}}});"">{item.Name}</a>"); } } // Grid 工具条按钮 if (!item.HideOnToolBar) { var icon = string.Empty; switch (item.ActionName) { case "Create": icon = @"<i class=""layui-icon""></i>"; break; case "Delete": case "BatchDelete": icon = @"<i class=""layui-icon""></i>"; break; case "Edit": case "BatchEdit": icon = @"<i class=""layui-icon""></i>"; break; case "Details": icon = @"<i class=""layui-icon""></i>"; break; case "Import": icon = @"<i class=""layui-icon""></i>"; break; case "GetExportExcel": icon = @"<i class=""layui-icon""></i>"; break; } toolBarBtnStrBuilder.Append($@"<a href=""javascript:void(0)"" onclick=""wtToolBarFunc_{Id}({{event:'{item.Area + item.ControllerName + item.ActionName + item.QueryString}'}});"" class=""layui-btn layui-btn-sm"">{icon}{item.Name}</a>"); } var url = item.Url; if (item.ControllerName == "_Framework" && item.ActionName == "GetExportExcel") // 导出按钮 接口地址 { url = $"{url}&_DONOT_USE_VMNAME={vmQualifiedName}"; } var script = new StringBuilder($"var tempUrl = '{url}';"); if (SPECIAL_ACTION.Contains(item.ActionName)) { script.Append($@"tempUrl = tempUrl + '&id=' + data.ID;"); } else { switch (item.ParameterType) { case GridActionParameterTypesEnum.NoId: break; case GridActionParameterTypesEnum.SingleId: script.Append($@" if(data==undefined||data==null||data.ID==undefined||data.ID==null){{ var ids = ff.GetSelections('{Id}'); if(ids.length == 0){{ layui.layer.msg('请选择一行'); return; }}else if(ids.length > 1){{ layui.layer.msg('最多只能选择一行'); return; }}else{{ tempUrl = tempUrl + '&id=' + ids[0]; }} }}else{{ tempUrl = tempUrl + '&id=' + data.ID; }} "); break; case GridActionParameterTypesEnum.MultiIds: script.Append($@" isPost = true; var ids = ff.GetSelections('{Id}'); if(ids.length == 0){{ layui.layer.msg('请至少选择一行'); return; }} "); break; case GridActionParameterTypesEnum.SingleIdWithNull: script.Append($@" var ids = []; if(data != null && data.ID != null){{ ids.push(data.ID); }} else {{ ids = ff.GetSelections('{Id}'); }} if(ids.length > 1){{ layui.layer.msg('最多只能选择一行'); return; }}else if(ids.length == 1){{ tempUrl = tempUrl + '&id=' + ids[0]; }} "); break; case GridActionParameterTypesEnum.MultiIdWithNull: script.Append($@" var ids = ff.GetSelections('{Id}'); {(item.ControllerName == "_Framework" && item.ActionName == "GetExportExcel" ? "if(ids.length>0) tempUrl = tempUrl + '&Ids=' + ids.join('&Ids=');" : "isPost = true;")} "); break; default: break; } } gridBtnEventStrBuilder.Append($@" case '{item.Area + item.ControllerName + item.ActionName + item.QueryString}':{{"); if (item.ParameterType == GridActionParameterTypesEnum.AddRow) { gridBtnEventStrBuilder.Append($@"ff.AddGridRow(""{Id}"",{Id}option,{ListVM.GetSingleDataJson(null)}); "); } else if (item.ParameterType == GridActionParameterTypesEnum.RemoveRow) { } else { gridBtnEventStrBuilder.Append($@" var isPost = false; {script} {(string.IsNullOrEmpty(item.OnClickFunc) ? (item.ShowDialog ? $"ff.OpenDialog(tempUrl,'{Guid.NewGuid().ToNoSplitString()}','{item.DialogTitle}',{(item.DialogWidth == null ? "null" : item.DialogWidth.ToString())},{(item.DialogHeight == null ? "null" : item.DialogHeight.ToString())},isPost===true&&ids!==null&&ids!==undefined?{{'Ids':ids}}:undefined);" : (item.Area == string.Empty && item.ControllerName == "_Framework" && item.ActionName == "GetExportExcel" ? $"ff.DownloadExcelOrPdf(tempUrl,'{SearchPanelId}',{JsonConvert.SerializeObject(Filter)});" : $"ff.BgRequest(tempUrl, isPost===true&&ids!==null&&ids!==undefined?{{'Ids':ids}}:undefined);" ) ) : $"{item.OnClickFunc}();")}"); } gridBtnEventStrBuilder.Append($@"}};break; "); } } }