use of org.activiti.engine.form.FormProperty in project my_curd by qinyou.
the class ActivitiUtils method getRenderedTaskFrom.
/**
* 获得任务办理表单
*
* @param task
* @return
*/
public static String getRenderedTaskFrom(Task task) {
// 简单拼字符逻辑
StringBuilder renderedForm = new StringBuilder("");
String formKey = task.getFormKey();
if (StringUtils.notEmpty(formKey)) {
// 常用表单简化
renderedForm.append("<tr> <td>审批结果:</td><td> ");
for (String key : formKey.split(",")) {
String temp = null;
switch(key) {
case "YES":
temp = "<input class='easyui-radiobutton' checked='true' name='PROCESS_approve_审批结果' value='同意' label='同意' labelPosition='after' >";
break;
case "NO":
temp = "<input style='margin-right:50px' class='easyui-radiobutton' name='PROCESS_approve_审批结果' value='拒绝' label='拒绝' labelPosition='after' >";
break;
}
if (temp != null) {
log.info("temp: {}", temp);
renderedForm.append(temp);
}
}
renderedForm.append("</td></tr>");
} else {
// 动态表单处理
List<FormProperty> formProperties = getFormService().getTaskFormData(task.getId()).getFormProperties();
for (FormProperty formProperty : formProperties) {
// 日期类型渲染
if (formProperty.getType() instanceof DateFormType) {
renderedForm.append("<tr><td>").append(formProperty.getName()).append("</td><td>");
String datePattern = (String) formProperty.getType().getInformation("datePattern");
String domClass;
// 仅支持 date 或 dateTime 常用格式
switch(datePattern) {
case "yyyy-MM-dd":
domClass = "easyui-datebox";
break;
case "yyyy-MM-dd HH:mm:ss":
domClass = "easyui-datetimebox";
break;
default:
domClass = "easyui-datetimebox";
}
renderedForm.append("<input class='").append(domClass).append("' name='").append(formProperty.getId()).append("' required='").append(formProperty.isRequired()).append("' >");
renderedForm.append("</td></tr>");
}
// 字符串类型渲染
if (formProperty.getType() instanceof StringFormType) {
renderedForm.append("<tr><td>").append(formProperty.getName()).append("</td><td>");
renderedForm.append("<input style='width:90%; height:50px' class='easyui-textbox' name='").append(formProperty.getId()).append("' required='").append(formProperty.isRequired()).append("' >");
renderedForm.append("</td></tr>");
}
// 枚举渲染为下拉框
if (formProperty.getType() instanceof EnumFormType) {
renderedForm.append("<tr><td>").append(formProperty.getName()).append("</td><td>");
renderedForm.append("<select panelHeight='auto' style='width:200px' class='easyui-combobox' name='").append(formProperty.getId()).append("' required='").append(formProperty.isRequired()).append("' >");
((Map<String, String>) formProperty.getType().getInformation("values")).forEach((key, value) -> {
renderedForm.append("<option value='").append(key).append("'>").append(value).append("</option>");
});
renderedForm.append("</select>").append("</td></tr>");
}
// 更多类型 更复杂业务 自行扩展
}
}
return renderedForm.toString();
}
Aggregations