public static AutoTable Convert(string fullName) { var objectCache = Ioc.Resolve <IObjectCache>(); return(objectCache.GetOrSet(() => { var type = fullName.GetTypeByFullName(); var classDescription = fullName.GetClassDescription(); if (classDescription == null) { return null; } var classPropertyAttribute = classDescription.ClassPropertyAttribute; var auto = new AutoTable { Type = fullName, }; auto.Border = new Border(classPropertyAttribute); #region 如果不包含操作按钮,则不显示操作这一列 if (classPropertyAttribute.IsTableAction) { // 如果不包含操作按钮,则不显示操作这一列 auto.TableActions = GetActions(type, classPropertyAttribute); // 操作链接 } if (auto.TableActions != null && auto.TableActions.Any(r => r.ActionType == TableActionType.ColumnAction)) { // 构建字段 var actionColumn = new AutoTableColumn { Label = "操作", Prop = "action", }; actionColumn.Style.ColumnStyle = ColumnStyle.Action; actionColumn.Style.Width = "105"; auto.Columns.Add(actionColumn); } #endregion 如果不包含操作按钮,则不显示操作这一列 #region 列相关的字段操作 var propertys = classDescription.Propertys; int decimalIndex = 0; foreach (var item in propertys) { if (item.FieldAttribute != null && item.FieldAttribute.ListShow) { if (item.Name == "Id") { continue; } var tableColumn = new AutoTableColumn { Label = item.DisplayAttribute?.Name, Prop = item.Property.Name.ToFristLower(), }; tableColumn = GetType(type, tableColumn, item.Property, item.FieldAttribute, ref decimalIndex); auto.Columns.Add(tableColumn); } } #endregion 列相关的字段操作 auto.SearchOptions = GetSearchOptions(propertys); // 搜索相关链接 auto.Tabs = GetTabs(propertys); // Tabs导航 auto.Columns = HanderWidth(auto.Columns); // 宽度处理 return auto; }, fullName + "AutoTable").Value); }
public static AutoTableColumn GetType(Type type, AutoTableColumn tableColumn, PropertyInfo propertyInfo, FieldAttribute fieldAttributes, ref int decimalIndex) { if (!fieldAttributes.Width.IsNullOrEmpty()) { tableColumn.Style.Width = fieldAttributes.Width; } // 主字段 if (fieldAttributes.IsMain && fieldAttributes.Link.IsNullOrEmpty()) { var instanceFind = type.FullName.GetInstanceByName(); if (instanceFind is IAutoConfig) { tableColumn.Style.ColumnStyle = ColumnStyle.Link; tableColumn.Style.Parameter = $"/Admin/AutoConfig/Edit?Key={type.Name}&id=[[id]]"; return(tableColumn); } if (instanceFind is IEntity) { tableColumn.Style.ColumnStyle = ColumnStyle.Link; tableColumn.Style.Parameter = $"/Admin/{type.Name}/Edit?&id=[[id]]"; return(tableColumn); } } if (fieldAttributes.ControlsType == ControlsType.ChildList) { // var childPathUrl = $"/Admin/{type.Name}"; //tableColumn.Style.Parameter = // $"<a href='{childPathUrl}/ChildList?Id=[[Id]]&field={propertyInfo.Name}'><i class='fa fa-eye'>{propertyInfo.GetDisplayName()}</i></a>"; } if (propertyInfo.Name.Contains("UserName", StringComparison.OrdinalIgnoreCase)) { tableColumn.Style.ColumnStyle = ColumnStyle.Normal; tableColumn.Style.Parameter = fieldAttributes.Link; return(tableColumn); } if (propertyInfo.PropertyType.BaseType == typeof(System.Enum)) { tableColumn.Style.ColumnStyle = ColumnStyle.Enum; tableColumn.Style.Parameter = propertyInfo.PropertyType.Name; return(tableColumn); } if (propertyInfo.PropertyType == typeof(bool) || propertyInfo.PropertyType == typeof(bool)) { tableColumn.Style.ColumnStyle = ColumnStyle.Bool; return(tableColumn); } if (propertyInfo.PropertyType == typeof(long) || propertyInfo.PropertyType == typeof(decimal) || propertyInfo.PropertyType == typeof(short) || propertyInfo.PropertyType == typeof(int) || propertyInfo.PropertyType == typeof(long)) { if (decimalIndex == 0) { tableColumn.Style.ColumnStyle = ColumnStyle.Code; decimalIndex++; return(tableColumn); } if (decimalIndex <= 7) { tableColumn.Style.ColumnStyle = ColumnStyle.Label; decimalIndex.IntToEnum <LabelColor>(out var labelColor); tableColumn.Style.Parameter = labelColor.GetCssClass()?.CssClass; decimalIndex++; return(tableColumn); } } if (fieldAttributes.ControlsType == ControlsType.Image || fieldAttributes.ColumnStyle == ColumnStyle.Image) { tableColumn.Style.Width = "90"; tableColumn.Style.ColumnStyle = ColumnStyle.Image; return(tableColumn); } if (fieldAttributes.ControlsType == ControlsType.Icon) { tableColumn.Style.ColumnStyle = ColumnStyle.Icon; return(tableColumn); } if (!fieldAttributes.Link.IsNullOrEmpty()) { tableColumn.Style.ColumnStyle = ColumnStyle.Link; tableColumn.Style.Parameter = fieldAttributes.Link; return(tableColumn); } if (fieldAttributes.ColumnStyle == ColumnStyle.Code) { tableColumn.Style.ColumnStyle = ColumnStyle.Code; return(tableColumn); } if (fieldAttributes.ColumnStyle == ColumnStyle.Grade) { tableColumn.Style.ColumnStyle = ColumnStyle.Grade; return(tableColumn); } return(tableColumn); }