/// <summary> /// 复制在组件上定义的标注的属性到 自动创建的 标注对象上,避免自动创建的标注对象丢失了属性; /// </summary> /// <param name="autoCreateOrOriginalAttr">自动创建的标注实例或者原始标注实例</param> /// <param name="attrDefineInProperty">在 属性 上定义的原始标注 实例</param> private static void CopyPropertyInAttributeDefine(AbstractPropertyComponentAttribute autoCreateOrOriginalAttr, AbstractPropertyComponentAttribute attrDefineInProperty) { if (autoCreateOrOriginalAttr.label == null) { autoCreateOrOriginalAttr.label = GetDisplay(attrDefineInProperty.property); } if (autoCreateOrOriginalAttr == attrDefineInProperty) { return; } autoCreateOrOriginalAttr.property = attrDefineInProperty.property; if (attrDefineInProperty != null) { autoCreateOrOriginalAttr.serial = attrDefineInProperty.serial; autoCreateOrOriginalAttr.limitRequestEntityType = attrDefineInProperty.limitRequestEntityType; autoCreateOrOriginalAttr.showCondition = attrDefineInProperty.showCondition; autoCreateOrOriginalAttr.showConditionValue = attrDefineInProperty.showConditionValue; autoCreateOrOriginalAttr.anyPrivilege = attrDefineInProperty.anyPrivilege; autoCreateOrOriginalAttr.allPrivilege = attrDefineInProperty.allPrivilege; autoCreateOrOriginalAttr.inline = attrDefineInProperty.inline; autoCreateOrOriginalAttr.editspan = attrDefineInProperty.editspan; autoCreateOrOriginalAttr.sortable = attrDefineInProperty.sortable; autoCreateOrOriginalAttr.sortableProperty = attrDefineInProperty.sortableProperty; autoCreateOrOriginalAttr.userType = attrDefineInProperty.userType; if (!string.IsNullOrEmpty(attrDefineInProperty.propertyPath)) //自动创建的 AbstractPropertyComponentAttribute 可能会设置 propertyPath { autoCreateOrOriginalAttr.propertyPath = attrDefineInProperty.propertyPath; } if (!string.IsNullOrEmpty(attrDefineInProperty.width)) //自动创建的 AbstractPropertyComponentAttribute 可能会设置 width { autoCreateOrOriginalAttr.width = attrDefineInProperty.width; } if (!string.IsNullOrEmpty(attrDefineInProperty.label)) //自动创建的 AbstractPropertyComponentAttribute 可能会设置 label { autoCreateOrOriginalAttr.label = attrDefineInProperty.label; } } }
/// <summary> /// 构造函数 /// </summary> /// <param name="prop"></param> /// <param name="attr"></param> public PropertyAndVuecompontAttribute(PropertyInfo prop, AbstractPropertyComponentAttribute attr) { this.Property = prop; this.VueComponentAttribute = attr; }
/// <summary> /// 根据 Type, Property, AbstractPropertyComponentAttribut 进行如下操作: /// a. 填充 AbstractPropertyComponentAttribut.label /// b. 当 componentAttr.componentType == EnumComponentType.Auto 时,需要根据 PropertyInfo 转换为具体的 组件类型; /// </summary> /// <param name="entityType"></param> /// <param name="property"></param> /// <param name="componentAttr"> 为null时表示自动构建 </param> /// <param name="schema"></param> /// <returns></returns> private static AbstractPropertyComponentAttribute ConvertToClientVueComponentAttribute(Type entityType, PropertyInfo property, AbstractPropertyComponentAttribute componentAttr, EnumComponentSchema schema) { var inputComponentAttr = componentAttr; componentAttr.property = property; if (componentAttr == null || componentAttr.componentType == EnumComponentType.auto) //为空或者自动 { var name = property.Name; if (name == "Id" || name == "Xid" || name == "Guid" || name == "LastModifyDateTime") //这些列不可编辑,不可过滤,也不会显示在列表中; { return(null); } if (schema == EnumComponentSchema.Edit && (name == "CreateDateTime" || name == "LastModifyDateTime")) { return(null); } var propertyType = property.PropertyType; Type innerType = propertyType; if (propertyType.IsGenericType) { innerType = propertyType.GenericTypeArguments[0]; } AbstractConvertable convertible = null; if (propertyType == typeof(string)) { convertible = new StringConvertable(entityType, property); } else if (propertyType == typeof(DateTime) || innerType == typeof(DateTime)) { convertible = new DatetimeConvertable(entityType, property); } else if (propertyType.IsEnum || innerType.IsEnum) { convertible = new EnumConvertable(entityType, property); } else if (propertyType == typeof(Int32) || innerType == typeof(Int32)) { convertible = new IntConvertable(entityType, property); } else if (propertyType == typeof(Int64) || innerType == typeof(Int64)) { convertible = new Int64Convertable(entityType, property); } else if (propertyType == typeof(decimal) || innerType == typeof(decimal)) { convertible = new DecimalConvertable(entityType, property); } else if (propertyType == typeof(Boolean) || innerType == typeof(Boolean)) { convertible = new BoolConvertable(entityType, property); } else { convertible = new StringConvertable(entityType, property); //默认使用字符串转换类型; } /*{ * throw new Exception("不支持的类型转换: ("); * }*/ if (componentAttr != null) { if (property.Name == "CreateUserId") { componentAttr.width = "80"; } if (property.Name == "CreateDateTime") { componentAttr.width = "160"; } if (property.Name == "Name") { componentAttr.width = "180"; } } if (schema == EnumComponentSchema.Filter) { componentAttr = convertible.ConvertToFilterVueComponentAttribute(entityType, property); } else if (schema == EnumComponentSchema.Edit) { componentAttr = convertible.ConvertToClientEditVueComponentAttribute(entityType, property); } else if (schema == EnumComponentSchema.List) { componentAttr = convertible.ConvertToClientTableColumnVueComponentAttribute(entityType, property); } } if (componentAttr != null) { if (property.Name == "CreateUserId" && componentAttr.serial == 0) { componentAttr.serial = 999; } if (property.Name == "CreateDateTime" && componentAttr.serial == 0) { componentAttr.serial = 1000; } if (property.Name == "Name" && componentAttr.serial == 0) { componentAttr.serial = -1; } CopyPropertyInAttributeDefine(componentAttr, inputComponentAttr); } return(componentAttr); }