diff --git a/flyfish-data/src/main/java/com/flyfish/framework/annotations/FormItem.java b/flyfish-data/src/main/java/com/flyfish/framework/annotations/FormItem.java new file mode 100644 index 0000000..26526c5 --- /dev/null +++ b/flyfish-data/src/main/java/com/flyfish/framework/annotations/FormItem.java @@ -0,0 +1,31 @@ +package com.flyfish.framework.annotations; + +import java.lang.annotation.*; + +/** + * 表单项属性 + * + * @author wangyu + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface FormItem { + + /** + * @return 组件 + */ + String component() default "a-input"; + + /** + * 属性key=value + * + * @return 结果 + */ + FormItemProp[] props() default {}; + + /** + * @return 布局 + */ + String layout() default ""; +} diff --git a/flyfish-data/src/main/java/com/flyfish/framework/annotations/FormItemProp.java b/flyfish-data/src/main/java/com/flyfish/framework/annotations/FormItemProp.java new file mode 100644 index 0000000..ea74d1e --- /dev/null +++ b/flyfish-data/src/main/java/com/flyfish/framework/annotations/FormItemProp.java @@ -0,0 +1,28 @@ +package com.flyfish.framework.annotations; + +import java.lang.annotation.*; + +/** + * 表单域属性 + * + * @author wangyu + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface FormItemProp { + + /** + * 键 + * + * @return 键 + */ + String key(); + + /** + * 值 + * + * @return 值 + */ + String value(); +} diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java index d5e4d82..49b42a9 100644 --- a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java @@ -9,8 +9,8 @@ import com.flyfish.framework.utils.ReflectionUtils; import com.flyfish.framework.utils.StringFormats; import lombok.Data; import lombok.val; -import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.ListUtils; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.reflect.FieldUtils; @@ -45,6 +45,9 @@ public class BeanProperty { // 描述信息 private String description; + // 布局 + private String layout; + // bean属性的类型,js类型 private BeanPropertyType type; @@ -63,6 +66,9 @@ public class BeanProperty { // 所属分组,该分组必须在元数据中定义 private String group; + // 其他属性,可交由前端展开 + private Map extra = new HashMap<>(); + /** * 来自属性解释器构造 * 支持对象嵌套 @@ -100,6 +106,18 @@ public class BeanProperty { } else { property.setOrder(props.order()); } + // 优雅的设置额外的属性 + FormItem item = AnnotationUtils.findAnnotation(field, FormItem.class); + if (null != item) { + // 设置额外属性 + property.extra.put("component", item.component()); + property.layout = item.layout(); + if (ArrayUtils.isNotEmpty(item.props())) { + for (FormItemProp prop : item.props()) { + property.prop(prop.key(), prop.value()); + } + } + } } else if (strict) { property.setReadonly(true); return property; diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProps.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProps.java index 6b20f5c..82c860c 100644 --- a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProps.java +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProps.java @@ -8,4 +8,12 @@ public interface BeanProps { // 表格的列,支持组件化 String COLUMNS = "columns"; + + String LAYOUT_NORMAL = "normal"; + + String LAYOUT_FULL = "full"; + + String LAYOUT_HALF = "half"; + + String LAYOUT_TABLE = "table"; }