feat: 提供组件级别的属性

This commit is contained in:
wangyu 2021-09-05 17:44:30 +08:00
parent ad8869184a
commit c2f353cc8a
4 changed files with 86 additions and 1 deletions

View File

@ -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 "";
}

View File

@ -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();
}

View File

@ -9,8 +9,8 @@ import com.flyfish.framework.utils.ReflectionUtils;
import com.flyfish.framework.utils.StringFormats; import com.flyfish.framework.utils.StringFormats;
import lombok.Data; import lombok.Data;
import lombok.val; import lombok.val;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.reflect.FieldUtils;
@ -45,6 +45,9 @@ public class BeanProperty {
// 描述信息 // 描述信息
private String description; private String description;
// 布局
private String layout;
// bean属性的类型js类型 // bean属性的类型js类型
private BeanPropertyType type; private BeanPropertyType type;
@ -63,6 +66,9 @@ public class BeanProperty {
// 所属分组该分组必须在元数据中定义 // 所属分组该分组必须在元数据中定义
private String group; private String group;
// 其他属性可交由前端展开
private Map<String, Object> extra = new HashMap<>();
/** /**
* 来自属性解释器构造 * 来自属性解释器构造
* 支持对象嵌套 * 支持对象嵌套
@ -100,6 +106,18 @@ public class BeanProperty {
} else { } else {
property.setOrder(props.order()); 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) { } else if (strict) {
property.setReadonly(true); property.setReadonly(true);
return property; return property;

View File

@ -8,4 +8,12 @@ public interface BeanProps {
// 表格的列支持组件化 // 表格的列支持组件化
String COLUMNS = "columns"; String COLUMNS = "columns";
String LAYOUT_NORMAL = "normal";
String LAYOUT_FULL = "full";
String LAYOUT_HALF = "half";
String LAYOUT_TABLE = "table";
} }