SearchConditionItem 为前端页面搜索栏目的实体类,可通过向此类赋值,来为前台配置出Ecology几乎所有种类的搜索条件,本文将会提供 SearchConditionItem 的使用方法以及部分底层运行原理
(浏览按钮相关内容暂在优化中)
@Author:Jaylan Zhou
@RefTitleAuthor:Andy Zhang
@Date:2019.11
@Version:1.0
在 E9 的开发中,你可以用SearchConditionItem,编写出如下类型的搜索条件:
- 文本输入框
- 下拉框
- 浏览按钮
- 日期条件(不带输入框)
- 时间条件(不带输入框)
引用类
- 下属子类:
- SearchConditionOption:选择框值实体类
- ConditionFactory:查询条件创建工厂类
- SearchConditionGroup
- 枚举类:
- ConditionType:条件类型枚举类
相关参数
变量名 | 变量类型 | 描述 |
---|---|---|
conditionType | ConditionType(枚举类) | 条件类型枚举类,此条件标记了这个类为何种类型的查询条件,包含以下几个值: INPUT 文本输入框 TEXTAREA 文本域 SELECT 选择框 DATE 日期格式 DATEPICKER 日期格式,不带区间 TIMEPICKER 时间格式,不带区间 RANGEPICKER 日期区间 DATE_INTERVAL 日期区间 TIME_INTERVAL 时间区间 BROWSER 浏览按钮 SELECT_LINKAGE 下拉选择框联动 INPUT_INTERVAL input 区间 SCOPE input 区间 CHECKBOX check框 SWITCH 开关 CUSTOM 自定义组件(流程自定义查询相关)RESOURCEIMG 人力资源 COLORPICKER 颜色选择器 CASCADER 级联组件 INPUTNUMBER 单个数字输入框 CUSTOMFIELD 自定义区域 TIMERANGEPICKER 时间区间 UPLOAD 附件上传 RICHTEXT 富文本 TAGGROUP 标签组 TEXT 文本 CASCADERCUSTOMFIELD CASCADER子组件 PASSWORD 密码框 DESCRIPTION 描述类型 RADIO 单选框 |
customType | String | 当 conditionType 为 custom 时启动此参数 |
otherParams | Map<String, Object> | 不同类型组件可能需要不同参数,扩展个Map存储,前端可合并到父级传输到组件 |
key | String | 标识参数 |
label | String | 此查询条件的前端文字描述 |
relatekey | String | 条件联动三值之一,代表的SearchConditionItem的key |
domkey | String[] | (未知) |
parentDomkey | String[] | (未知) |
options | List<SearchConditionOption>(下拉框值实体类) | 选择框类型查询条件的值,每一个值作为一个SearchConditionOption对象放在List里 |
viewAttr | int | (未知,浏览数据定义相关) |
value | Object | (未知,浏览数据定义相关) |
hide | boolean | (未知,浏览数据定义相关) |
length | int | (未知,浏览数据定义相关) |
stringLength | int | (未知,浏览数据定义相关) |
labelcol | int | 布局属性:label(查询条件前的文字描述)所占列数 |
fieldcol | int | 布局属性:查询条件所占列数 |
browserConditionParam | BrowserBean(浏览按钮实体类) | 浏览按钮实体类,存储了浏览按钮的相关信息(相关原理在整理) |
colSpan | int | 定义一行显示条件数,默认值为2,当值为1时标识该条件单独占一行 |
isQuickSearch | boolean | (未知) |
isBase64 | boolean | 是否base64加密 |
inputType | String | |
selectLinkageDatas | Map<String, SearchConditionItem> | 选择框联动的其他选择框 |
selectWidth | String | 选择框联动时定义select所占宽度 支持百分比、固定宽度 |
precision | Int | 数字精度保留位数 |
min | String | (未知) |
max | String | (未知) |
step | String | (未知) |
minRows | String | 多行文本:最小行数 |
maxRows | String | 多行文本:最大行数 |
rules | String | (未知)前端是否校验必填及显示信息 数据格式 required |
regExp | String | (未知)前端是否校验必填及显示信息 数据格式 required |
startValue | String | (未知)前端是否校验必填及显示信息 数据格式 required |
endValue | String | (未知)前端是否校验必填及显示信息 数据格式 required |
detailtype | int | select组件detailtype属性 1:正常显示 2:checkbox多选 3:radio单选 |
supportCancel | boolean | select组件是否支持取消 |
multiple | boolean | 是否支持select多选 |
uploadUrl | String | 上传文件目标地址 |
category | String | (未知) |
listType | String | (未知) |
maxFilesNumber | int | 文件上传的最大个数 |
maxUploadSize | int | 文件上传的在最大大小/MB |
multiSelection | boolean | true:多文件上传 false:单文件上传 |
btnSize | String | 按钮大小/px |
datas | List<Object> | (未知)附件上传默认值 |
helpfulTip | String | (未知)帮助Tips |
helpfulTipProps | Map<String,Object> | (未知)帮助Tips Map |
showOrder | int | 显示顺序 |
checkbox | boolean | checkbox是否可以复选 |
checkboxValue | boolean | (未知)字段复选框的值 |
tip | String | inputnumber 组件的文字说明 |
display | String | (未知) |
placeholder | String | (未知)display 属性 |
entSearch | boolean | 是否允许输入回车(enter)搜索 |
dateGroup | boolean | 不限日期区间 |
valueList | List<String> |
构造方法
/**
* 构造方法1
* 无参构造方法 没用
*/
public SearchConditionItem() {
}
/**
* 构造方法2
* 为全局变量赋值
*/
public SearchConditionItem(String key, String label, String relatekey,
String[] domkey, List<SearchConditionOption> options, int labelcol, int fieldcol) {
this.key = key;
this.label = label;
this.relatekey = relatekey;
this.domkey = domkey;
this.options = options;
this.labelcol = labelcol;
this.fieldcol = fieldcol;
}
/**
* 构造方法3
* 为全局变量赋值
*/
public SearchConditionItem(ConditionType conditionType, String label, String[] domkey) {
this.conditionType = conditionType;
this.label = label;
this.domkey = domkey;
}
/**
* 构造方法4
* 为全局变量赋值
*/
public SearchConditionItem(ConditionType conditionType, String label, String[] domkey, BrowserBean browserConditionParam) {
this.conditionType = conditionType;
this.label = label;
this.domkey = domkey;
this.browserConditionParam = browserConditionParam;
}
/**
* 构造方法5
* 为全局变量赋值
*/
public SearchConditionItem(ConditionType conditionType, String label, String relatekey, String[] domkey, List<SearchConditionOption> options, int labelcol, int fieldcol,
BrowserBean browserConditionParam) {
super();
this.conditionType = conditionType;
this.label = label;
this.relatekey = relatekey;
this.domkey = domkey;
this.options = options;
this.labelcol = labelcol;
this.fieldcol = fieldcol;
this.browserConditionParam = browserConditionParam;
}
/**
* 构造方法6
* 为全局变量赋值
*/
public SearchConditionItem(ConditionType conditionType, String label, String relatekey, String[] domkey,
List<SearchConditionOption> options, int labelcol, int fieldcol, boolean dateGroup) {
super();
this.conditionType = conditionType;
this.label = label;
this.relatekey = relatekey;
this.domkey = domkey;
this.options = options;
this.labelcol = labelcol;
this.fieldcol = fieldcol;
this.dateGroup = dateGroup;
}
/**
* 构造方法7
* 为全局变量赋值
*/
public SearchConditionItem(String key, String label, String relatekey, String[] domkey, List<SearchConditionOption> options, int labelcol, int fieldcol, BrowserBean browserConditionParam) {
this.key = key;
this.label = label;
this.relatekey = relatekey;
this.domkey = domkey;
this.options = options;
this.labelcol = labelcol;
this.fieldcol = fieldcol;
this.browserConditionParam = browserConditionParam;
}
公共方法
SearchConditionItem 无公共方法
执行原理
SearchConditionItem 一般不由构造方法创建,而是由ConditionFactory去进行创建,根据选择不同的conditionType,调用不同的工厂创建对象方法,创建完对象后,通过set方法,对其查询类型应赋值的属性通过set方法进行赋值,进行一系列操作后,返回SearchConditionGroup对象的集合,并将集合以JSON格式返回前台,前台解析数据生成页面
SearchConditionGroup 存储了 SearchConditionItem 对象的集合
具体执行过程如下
-
1.实例化 ConditionFactory 工厂类
ConditionFactory conditionFactory = new ConditionFactory(user); //User 为当前登录用户
-
2.实例化 SearchConditionGroup,SearchConditionItem 集合
List<SearchConditionGroup> addGroups = new ArrayList<SearchConditionGroup>(); List<SearchConditionItem> conditionItems = new ArrayList<SearchConditionItem>();
-
3.根据想要创建的条件类型,实例化对象,填入信息,并将对象放入 SearchConditionItem 集合中
//示例:文本框类型查询条件 SearchConditionItem requestname = conditionFactory.createCondition(ConditionType.INPUT,502327, "requestname");//ConditionType.INPUT 标记了此查询类型为文本框 requestname.setColSpan(2);//定义一行显示条件数,默认值为2,当值为1时标识该条件单独占一行 requestname.setFieldcol(16); //条件输入框所占宽度,默认值18 requestname.setLabelcol(8); requestname.setViewAttr(3); // 编辑权限 1:只读,2:可编辑, 3:必填 默认2 requestname.setLabel("请求标题"); //设置文本值 这个将覆盖多语言标签的值 requestname.setRules("required"); conditionItems.add(requestname); //将设置好的 SearchConditionItem 放入集合
-
4.初始化 SearchConditionGroup 对象,并放入 SearchConditionGroup 集合
//形参1:标题 形参2:是否展示 形参3:SearchConditionItem 集合 addGroups.add(new SearchConditionGroup("标题",true,conditionItems))
-
新建Map<String,Object>,将结果存入Map
//HashMap 中存储了两个参数 //第一个叫hasRight,前台解析时会根据true,false来判断当前用户是否有权限查看 //第二个叫condition,就是 SearchConditionGroup 集合 Map<String,Object> result = new HashMap<>(); result.put("hasRight",true); result.put("condition",addGroups);
执行示例
-
1.demo 示例
package com.engine.demo.demo01.cmd; import com.api.browser.bean.SearchConditionGroup; import com.api.browser.bean.SearchConditionItem; import com.api.browser.bean.SearchConditionOption; import com.api.browser.util.ConditionFactory; import com.api.browser.util.ConditionType; import com.engine.common.biz.AbstractCommonCommand; import com.engine.common.entity.BizLogContext; import com.engine.core.interceptor.CommandContext; import weaver.hrm.HrmUserVarify; import weaver.hrm.User; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /* * @Author :wyl * @Date :2019/3/21 15:51 * @Version 1.0 : * @Description : 表单示例的demo **/ public class GetFormDemoCmd extends AbstractCommonCommand<Map<String,Object>> { public GetFormDemoCmd(User user, Map<String,Object> params) { this.user = user; this.params = params; } @Override public BizLogContext getLogContext() { return null; } @Override public Map<String, Object> execute(CommandContext commandContext) { //定义返回数据 Map<String, Object> apidatas = new HashMap<String, Object>(); //角色判断参考代码 // if(!HrmUserVarify.checkUserRight("LogView:View", user)){ // apidatas.put("hasRight", false); // return apidatas; // } if (null == user){ apidatas.put("hasRight", false); return apidatas; } apidatas.put("hasRight", true); ConditionFactory conditionFactory = new ConditionFactory(user); //输入框类 List<SearchConditionItem> inputItems = new ArrayList<SearchConditionItem>(); //日期时间类 List<SearchConditionItem> dateTimeItems = new ArrayList<SearchConditionItem>(); //选择框类 List<SearchConditionItem> selectItems = new ArrayList<SearchConditionItem>(); //其他 List<SearchConditionItem> otherItems = new ArrayList<SearchConditionItem>(); List<SearchConditionGroup> addGroups = new ArrayList<SearchConditionGroup>(); /** *输入框类 */ //文本框设置 //SearchConditionItem demo_input = new SearchConditionItem(ConditionType.INPUT,"文本框",new String[]{"demo_input"}); //创建SearchConditionItem工厂方法 SearchConditionItem demo_input = conditionFactory.createCondition(ConditionType.INPUT,502327, "input"); demo_input.setColSpan(2);//定义一行显示条件数,默认值为2,当值为1时标识该条件单独占一行 demo_input.setFieldcol(12); //条件输入框所占宽度,默认值18 demo_input.setViewAttr(3); // 编辑权限 1:只读,2:可编辑, 3:必填 默认2 demo_input.setLength(10); // 设置输入长度 demo_input.setLabel("文本输入框"); //设置文本值 这个将覆盖多语言标签的值 demo_input.setRules("required"); //设置字段填入规则 demo_input.setValue("我是默认值"); //这里设置数据的默认值,开发可以通过从数据库取出数据传入 inputItems.add(demo_input); //整数 SearchConditionItem demo_inputnumber = conditionFactory.createCondition(ConditionType.INPUTNUMBER,502227, "inputNumber"); demo_inputnumber.setColSpan(2); demo_inputnumber.setFieldcol(12); demo_inputnumber.setViewAttr(2); // demo_inputnumber.setLabel("数字输入框"); demo_inputnumber.setRules("required"); //设置字段填入规则 inputItems.add(demo_inputnumber); //密码框设置 SearchConditionItem demo_password = conditionFactory.createCondition(ConditionType.PASSWORD,502227,"password"); demo_password.setColSpan(2); demo_password.setFieldcol(12); demo_password.setViewAttr(2); demo_password.setLabel("密码输入框"); demo_password.setRules("required"); demo_password.setIsQuickSearch(true); demo_password.setValue(""); inputItems.add(demo_password); // //密码框设置 // SearchConditionItem demo_inputsearch = conditionFactory.createCondition(ConditionType.INPUTSEARCH,502227,"inputSearch"); // demo_inputsearch.setColSpan(2); // demo_inputsearch.setFieldcol(12); // demo_inputsearch.setViewAttr(2); // demo_inputsearch.setViewAttr(2); // demo_inputsearch.setLabel("带放大镜输入框"); // demo_inputsearch.setRules("required"); // demo_inputsearch.setIsQuickSearch(true); // inputItems.add(demo_inputsearch); //多行文本框设置 SearchConditionItem demo_textarea = conditionFactory.createCondition(ConditionType.TEXTAREA,502227, "textarea"); demo_textarea.setColSpan(2); demo_textarea.setFieldcol(12); demo_textarea.setLabelcol(6); demo_textarea.setViewAttr(2); demo_textarea.setIsQuickSearch(true); demo_textarea.setLabel("多行文本框"); inputItems.add(demo_textarea); //浏览按钮 SearchConditionItem demo_browser = conditionFactory.createCondition(ConditionType.BROWSER,502227,"browser","17"); demo_browser.setValue("demo_browser"); demo_browser.setColSpan(2); demo_browser.setFieldcol(12); demo_browser.setLabelcol(6); demo_browser.setViewAttr(2); demo_browser.setIsQuickSearch(false); demo_browser.setLabel("浏览按钮"); demo_browser.setRules("required|string"); inputItems.add(demo_browser); //富文本框 SearchConditionItem demo_richtext = conditionFactory.createCondition(ConditionType.RICHTEXT,502227, "richText"); demo_richtext.setColSpan(2); demo_richtext.setFieldcol(12); demo_richtext.setLabelcol(6); demo_richtext.setViewAttr(2); demo_richtext.setLabel("富文本"); inputItems.add(demo_richtext); addGroups.add(new SearchConditionGroup("输入框类",true,inputItems)); /** *时间日期类 */ //日期格式 SearchConditionItem demo_datepicker = conditionFactory.createCondition(ConditionType.DATEPICKER,502227,"datePicker"); demo_datepicker.setColSpan(2); demo_datepicker.setFieldcol(12); demo_datepicker.setLabelcol(6); demo_datepicker.setViewAttr(2); demo_datepicker.setIsQuickSearch(true); demo_datepicker.setLabel("日期"); demo_datepicker.setRules("required"); dateTimeItems.add(demo_datepicker); //日期组合 SearchConditionItem demo_dategroup = conditionFactory.createCondition(ConditionType.DATE,502227,"dateGroup"); demo_dategroup.setColSpan(2); demo_dategroup.setFieldcol(12); demo_dategroup.setLabelcol(6); demo_dategroup.setViewAttr(2); demo_dategroup.setIsQuickSearch(true); demo_dategroup.setLabel("日期组合"); demo_dategroup.setRules("required"); dateTimeItems.add(demo_dategroup); //日期区间 SearchConditionItem demo_rangepicker = conditionFactory.createCondition(ConditionType.TIMEPICKER,502227,new String[]{"resourcename1","resourcename2"}); demo_rangepicker.setColSpan(2); demo_rangepicker.setFieldcol(12); demo_rangepicker.setLabelcol(6); demo_rangepicker.setViewAttr(2); demo_rangepicker.setLabel("日期区间"); demo_rangepicker.setRules("required"); dateTimeItems.add(demo_rangepicker); //时间区间 SearchConditionItem demo_timepicker = conditionFactory.createCondition(ConditionType.TIMERANGEPICKER,502227,new String[]{"seclevel1","seclevel2"}); demo_timepicker.setColSpan(2); demo_timepicker.setFieldcol(12); demo_timepicker.setLabelcol(6); demo_timepicker.setViewAttr(2); demo_timepicker.setLabel("时间区间"); demo_timepicker.setRules("required"); dateTimeItems.add(demo_timepicker); // //时间选择断 // SearchConditionItem demo_period = conditionFactory.createCondition(ConditionType.PERIOD,502227,new String[]{"startTime","endTime"}); // demo_period.setColSpan(2); // demo_period.setFieldcol(12); // demo_period.setLabelcol(6); // demo_period.setViewAttr(2); // demo_period.setLabel("时间区间"); // demo_period.setRules("required"); // demo_period.setValue(new int[]{0,22}); // dateTimeItems.add(demo_period); //联动组件 //设置主值 SearchConditionItem demo_selectlinkage = conditionFactory.createCondition(ConditionType.SELECT_LINKAGE,502227, new String[]{"seclevellink1","seclevellink2"}); //设置选项值 List<SearchConditionOption> selectlinkage_options = new ArrayList <>(); //设置联动 selectlinkage_options.add(new SearchConditionOption("0","全部")); selectlinkage_options.add(new SearchConditionOption("1","今天",true)); selectlinkage_options.add(new SearchConditionOption("2","本周")); selectlinkage_options.add(new SearchConditionOption("2","本年")); selectlinkage_options.add(new SearchConditionOption("4","上个月")); selectlinkage_options.add(new SearchConditionOption("5","上一年")); selectlinkage_options.add(new SearchConditionOption("6","指定日期范围")); demo_selectlinkage.setOptions(selectlinkage_options); //设置被联动出来的值 SearchConditionItem demo_selectlinkage_0 = conditionFactory.createCondition(ConditionType.INPUT,502227,"INPUT"); SearchConditionItem demo_selectlinkage_1 = conditionFactory.createCondition(ConditionType.CHECKBOX,502227,"CHECKBOX"); SearchConditionItem demo_selectlinkage_2 = conditionFactory.createCondition(ConditionType.RANGEPICKER,502227,new String[]{"start","end"}); Map<String,SearchConditionItem> map1 = new HashMap<>(); map1.put("1",demo_selectlinkage_0); map1.put("2",demo_selectlinkage_1); map1.put("6",demo_selectlinkage_2); demo_selectlinkage.setColSpan(2); demo_selectlinkage.setFieldcol(12); demo_selectlinkage.setLabelcol(6); // demo_inputsearch.setViewAttr(2); demo_selectlinkage.setSelectLinkageDatas(map1); demo_selectlinkage.setLabel("联动组件"); dateTimeItems.add(demo_selectlinkage); addGroups.add(new SearchConditionGroup("日期时间类",true,dateTimeItems)); /** * 选择框类 */ //下拉选择框类 SearchConditionItem demo_select = conditionFactory.createCondition(ConditionType.SELECT,502227,"SELECT"); List<SearchConditionOption> selectOptions = new ArrayList <>(); //设置选项值 selectOptions.add(new SearchConditionOption("0","",true)); selectOptions.add(new SearchConditionOption("1","男")); selectOptions.add(new SearchConditionOption("2","女")); demo_select.setOptions(selectOptions); demo_select.setColSpan(2); demo_select.setFieldcol(12); demo_select.setLabelcol(6); demo_select.setIsQuickSearch(false); demo_select.setLabel("下拉选择框"); selectItems.add(demo_select); //check框 SearchConditionItem demo_checkbox = conditionFactory.createCondition(ConditionType.CHECKBOX,502227,"check"); demo_checkbox.setColSpan(2); demo_checkbox.setFieldcol(12); demo_checkbox.setLabelcol(6); demo_checkbox.setViewAttr(2); demo_checkbox.setIsQuickSearch(false); demo_checkbox.setLabel("check框"); demo_checkbox.setRules("required"); selectItems.add(demo_checkbox); //switch框 SearchConditionItem demo_switch = conditionFactory.createCondition(ConditionType.SWITCH,502227, "demo_switch"); demo_switch.setColSpan(2); demo_switch.setFieldcol(12); demo_switch.setLabelcol(6); demo_checkbox.setViewAttr(2); demo_switch.setIsQuickSearch(false); demo_switch.setLabel("switch框"); selectItems.add(demo_switch); addGroups.add(new SearchConditionGroup("选择框类",true,selectItems)); /** * 其他 */ //安全级别 SearchConditionItem demo_scope = conditionFactory.createCondition(ConditionType.SCOPE,502227,new String[]{"seclevel","seclevelTo"}); demo_scope.setColSpan(2); demo_scope.setFieldcol(12); demo_scope.setLabelcol(6); demo_scope.setEndValue("100"); demo_scope.setIsQuickSearch(false); demo_scope.setLabel("安全级别"); demo_scope.setStartValue("0"); demo_scope.setPrecision(0); demo_scope.setRules("scopeRequired"); otherItems.add(demo_scope); //颜色选择器 SearchConditionItem demo_colorpicker = conditionFactory.createCondition(ConditionType.COLORPICKER,502227, "colorPicker"); demo_colorpicker.setColSpan(2); demo_colorpicker.setFieldcol(12); demo_colorpicker.setLabelcol(6); demo_colorpicker.setViewAttr(2); demo_colorpicker.setLabel("颜色选择"); otherItems.add(demo_colorpicker); //附件上传 SearchConditionItem demo_upload = conditionFactory.createCondition(ConditionType.UPLOAD,502227, "upload"); demo_upload.setColSpan(2); demo_upload.setFieldcol(12); demo_upload.setLabelcol(6); demo_upload.setIsQuickSearch(false); demo_upload.setLabel("附件上传"); demo_upload.setRules("required"); demo_upload.setViewAttr(2); demo_upload.setUploadUrl("/api/doc/upload/uploadFile"); demo_upload.setCategory("string"); demo_upload.setHelpfulTip("123123哈哈哈"); demo_upload.setMaxUploadSize(100); //文件大小 demo_upload.setMaxFilesNumber(10); //文件个数 otherItems.add(demo_upload); //人力资源 SearchConditionItem demo_taggroup = conditionFactory.createCondition(ConditionType.TAGGROUP,502227,"tagGroup","17"); demo_taggroup.setValue("demo_taggroup"); demo_taggroup.setColSpan(2); demo_taggroup.setFieldcol(12); demo_taggroup.setLabelcol(6); demo_taggroup.setIsQuickSearch(false); demo_taggroup.setLabel("标签组"); demo_taggroup.setViewAttr(2); demo_taggroup.setRules("required|string"); otherItems.add(demo_taggroup); addGroups.add(new SearchConditionGroup("其他",true,otherItems)); apidatas.put("condition", addGroups ); return apidatas; } }