* @param modulePath 多级非叶子模块(路径名称等于模块英文名称)
* @param module 叶子模块(路径名称等于模块英文名称)
* @return
*/
public static String getContent(String modulePath, String module) {
Model model=actionToModel.get(module);
if(model==null){
return "";
}
String templateName="js.ftl";
LOG.info("开始生成JS");
Map<String, Object> context = new HashMap<>();
List<ModelFieldData> attrs=model.getAllRenderModelAttr();
//去除重复的词典,便于在修改页面加载各个不同的下拉菜单
Set<String> dicNames=new HashSet<String>();
for(ModelFieldData attr : attrs){
if(!"".equals(attr.getSimpleDic())){
dicNames.add(attr.getSimpleDic());
}
if(!"".equals(attr.getTreeDic())){
dicNames.add(attr.getTreeDic());
}
}
int baseHeight=120;
//添加,分为两列
List<ModelFieldData> modelAttrs=model.getModelAttr();
int len=modelAttrs.size()/2+modelAttrs.size()%2;
int createHeight=baseHeight+len*16*2;
int labelWidth=80;
int maxLength=0;
List<ModelFieldData> leftModelAttrs=new ArrayList<>();
for(int i=0;i<len;i++){
ModelFieldData data=modelAttrs.get(i);
leftModelAttrs.add(data);
int length=data.getChinese().length();
if(length>4){
maxLength=length>maxLength?length:maxLength;
}
}
List<ModelFieldData> rightModelAttrs=new ArrayList<>();
for(int i=len;i<modelAttrs.size();i++){
ModelFieldData data=modelAttrs.get(i);
rightModelAttrs.add(data);
int length=data.getChinese().length();
if(length>4){
maxLength=length>maxLength?length:maxLength;
}
}
if(maxLength>0){
labelWidth=(maxLength-4)*10+80;
}
//搜索,分为两列
List<ModelFieldData> searchableAttrs=model.getAllModelSearchableAttr();
len=searchableAttrs.size()/2+searchableAttrs.size()%2;
int searchHeight=baseHeight+len*16*2;
List<ModelFieldData> leftSearchableAttrs=new ArrayList<>();
for(int i=0;i<len;i++){
leftSearchableAttrs.add(searchableAttrs.get(i));
}
List<ModelFieldData> rightSearchableAttrs=new ArrayList<>();
for(int i=len;i<searchableAttrs.size();i++){
rightSearchableAttrs.add(searchableAttrs.get(i));
}
if(modulePath.startsWith("/")){
modulePath=modulePath.substring(1);
}
if(modulePath.endsWith("/")){
modulePath=modulePath.substring(0,modulePath.length()-1);
}
if(createHeight>999){
createHeight=999;
}
Integer createWidth=(createHeight*16)/9;
if(createWidth<800){
createWidth=800;
}
if(searchHeight>999){
searchHeight=999;
}
Integer searchWidth=(searchHeight*16)/9;
if(searchWidth<800){
searchWidth=800;
}
context.put("namespace", modulePath);
context.put("action", dealWithAcdtion(module));
context.put("attrs", attrs);
context.put("dicNames", dicNames);
context.put("labelWidth", labelWidth);
context.put("createWidth", createWidth.toString());
context.put("createHeight", createHeight);
context.put("searchWidth", searchWidth.toString());
context.put("searchHeight", searchHeight);
context.put("leftModelAttrs", leftModelAttrs);
context.put("rightModelAttrs", rightModelAttrs);
context.put("searchableAttrs", searchableAttrs);
context.put("leftSearchableAttrs", leftSearchableAttrs);
context.put("rightSearchableAttrs", rightSearchableAttrs);
context.put("model", model.getClass().getSimpleName());
context.put("title", model.getMetaData());
context.put("icon", module);
try {
Template template = freemarkerConfiguration.getTemplate(templateName, ENCODING);