feat: 提供组件级别的属性
This commit is contained in:
parent
ad8869184a
commit
c2f353cc8a
@ -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 "";
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
@ -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;
|
||||||
|
@ -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";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user