From c2f353cc8a983e57f7c81f3ca83a7b0c1b1807bb Mon Sep 17 00:00:00 2001 From: wangyu <727842003@qq.com> Date: Sun, 5 Sep 2021 17:44:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8F=90=E4=BE=9B=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=BA=A7=E5=88=AB=E7=9A=84=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/annotations/FormItem.java | 31 +++++++++++++++++++ .../framework/annotations/FormItemProp.java | 28 +++++++++++++++++ .../framework/beans/meta/BeanProperty.java | 20 +++++++++++- .../framework/beans/meta/BeanProps.java | 8 +++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 flyfish-data/src/main/java/com/flyfish/framework/annotations/FormItem.java create mode 100644 flyfish-data/src/main/java/com/flyfish/framework/annotations/FormItemProp.java 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"; }