@@ -26,6 +26,10 @@ | |||||
<artifactId>spring-boot-starter-web</artifactId> | <artifactId>spring-boot-starter-web</artifactId> | ||||
</dependency> | </dependency> | ||||
<dependency> | <dependency> | ||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-starter-freemarker</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>cc.smtweb</groupId> | <groupId>cc.smtweb</groupId> | ||||
<artifactId>sw-framework-auth</artifactId> | <artifactId>sw-framework-auth</artifactId> | ||||
<version>2.2.0-SNAPSHOT</version> | <version>2.2.0-SNAPSHOT</version> | ||||
@@ -0,0 +1,145 @@ | |||||
package cc.smtweb.system.bpm.resolver; | |||||
import cc.smtweb.framework.core.common.SwException; | |||||
import cc.smtweb.framework.core.common.SwMap; | |||||
import cc.smtweb.framework.core.db.DbEngine; | |||||
import freemarker.template.Configuration; | |||||
import freemarker.template.Template; | |||||
import freemarker.template.TemplateMethodModelEx; | |||||
import freemarker.template.TemplateModelException; | |||||
import java.io.*; | |||||
import java.nio.charset.StandardCharsets; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
/** | |||||
* | |||||
*/ | |||||
public class CodeResolver { | |||||
private static CodeResolver instance = null; | |||||
private Configuration configuration = null; | |||||
private final String encode = org.apache.commons.codec.CharEncoding.UTF_8; | |||||
private String templatesDir; | |||||
protected CodeResolver() { | |||||
templatesDir = this.getClass().getResource("/static/template").getPath(); | |||||
configuration = new Configuration(Configuration.VERSION_2_3_31); | |||||
try { | |||||
configuration.setDirectoryForTemplateLoading(new File(templatesDir)); | |||||
configuration.setClassicCompatible(true); | |||||
configuration.setDefaultEncoding(encode); | |||||
configuration.setOutputEncoding(encode); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
throw new SwException(e); | |||||
} | |||||
} | |||||
public void create(Map<String, Object> model, String templateName, Writer writer) { | |||||
try { | |||||
Template template = configuration.getTemplate(templateName, encode); | |||||
template.setOutputEncoding(encode); | |||||
template.process(model, writer); | |||||
writer.close(); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
throw new SwException(e); | |||||
} | |||||
} | |||||
public void create(Map<String, Object> model, String templateName, OutputStream out) { | |||||
try { | |||||
Template template = configuration.getTemplate(templateName, StandardCharsets.UTF_8.toString()); | |||||
template.setOutputEncoding(encode); | |||||
template.process(model, new OutputStreamWriter(out, encode)); | |||||
out.close(); | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
throw new SwException(e); | |||||
} | |||||
} | |||||
/** | |||||
* 获取单实例 | |||||
* | |||||
* @return | |||||
*/ | |||||
public static CodeResolver getInstance() { | |||||
if (instance == null) { | |||||
synchronized (CodeResolver.class) { | |||||
instance = new CodeResolver(); | |||||
} | |||||
} | |||||
return instance; | |||||
} | |||||
static class PKGenerator implements TemplateMethodModelEx { | |||||
@Override | |||||
public Object exec(List list) throws TemplateModelException { | |||||
return "asd"; | |||||
// return DbEngine.getInstance().nextId(); | |||||
} | |||||
} | |||||
/* | |||||
{param:{pa:"aaa"}, | |||||
layout:{ | |||||
c1:[{type:"list", dataset:"ds123", fields:[{field:"", dataset:""}], cfilters:[{}]}] | |||||
} | |||||
*/ | |||||
public static void main(String[] args) { | |||||
StringWriter out = new StringWriter(); | |||||
SwMap map = new SwMap(); | |||||
SwMap param = new SwMap(); | |||||
param.put("pa", "aaaaa"); | |||||
map.put("param", param); | |||||
SwMap layout = new SwMap(); | |||||
map.put("layout", layout); | |||||
List<SwMap> groups = new ArrayList<>(); | |||||
layout.put("c1", groups); | |||||
SwMap area = new SwMap(); | |||||
groups.add(area); | |||||
area.put("type", "list"); | |||||
area.put("dataset", "ds123"); | |||||
List<SwMap> fields = new ArrayList<>(); | |||||
area.put("fields", fields); | |||||
SwMap field = new SwMap(); | |||||
field.put("field", "f123"); | |||||
field.put("dataset", "ds123"); | |||||
field.put("label", "字段123"); | |||||
fields.add(field); | |||||
field = new SwMap(); | |||||
field.put("field", "f121"); | |||||
field.put("label", "字段121"); | |||||
field.put("dataset", "ds123"); | |||||
fields.add(field); | |||||
field = new SwMap(); | |||||
field.put("field", "f122"); | |||||
field.put("label", "字段122"); | |||||
field.put("dataset", "ds123"); | |||||
fields.add(field); | |||||
List<SwMap> filters = new ArrayList<>(); | |||||
area.put("cfilters", filters); | |||||
field = new SwMap(); | |||||
field.put("field", "f122"); | |||||
field.put("dataset", "ds123"); | |||||
field.put("label", "字段122"); | |||||
field.put("maxlength", 20); | |||||
filters.add(field); | |||||
map.put("title", "thisIsATest!"); | |||||
map.put("newId", new PKGenerator()); | |||||
CodeResolver.getInstance().create(map, "simple.ftl", out); | |||||
System.out.println(out.getBuffer().toString()); | |||||
} | |||||
} |
@@ -234,6 +234,9 @@ public class ModelFormHelper { | |||||
* @return | * @return | ||||
*/ | */ | ||||
public static String buildEngineModel(ModelForm form, SwMap params, UserSession us) { | public static String buildEngineModel(ModelForm form, SwMap params, UserSession us) { | ||||
return buildEngineModel(form, params, us, true); | |||||
} | |||||
public static String buildEngineModel(ModelForm form, SwMap params, UserSession us, boolean incExtra) { | |||||
PageDatasets datasets = parsePageDataset(form.getDataset()); | PageDatasets datasets = parsePageDataset(form.getDataset()); | ||||
if (datasets == null || datasets.list == null) return ""; | if (datasets == null || datasets.list == null) return ""; | ||||
@@ -257,7 +260,9 @@ public class ModelFormHelper { | |||||
listModel.add(buildEngineModelMap(dataSet, model)); | listModel.add(buildEngineModelMap(dataSet, model)); | ||||
} | } | ||||
ret.put("extra", buildEngineExtra(pageInfo.option, params, us)); | |||||
if (incExtra) { | |||||
ret.put("extra", buildEngineExtra(pageInfo.option, params, us)); | |||||
} | |||||
return JsonUtil.encodeString(ret); | return JsonUtil.encodeString(ret); | ||||
} | } | ||||
@@ -307,7 +312,7 @@ public class ModelFormHelper { | |||||
SwMap widgetOpts = parseFormOption(widgetForm.getOption()); | SwMap widgetOpts = parseFormOption(widgetForm.getOption()); | ||||
w.put("service", widgetForm.getService()); | w.put("service", widgetForm.getService()); | ||||
if (widgetOpts != null) w.putAll(widgetOpts); | if (widgetOpts != null) w.putAll(widgetOpts); | ||||
w.put("define", widgetForm.getContent()); | |||||
w.put("define", buildEngineModel(widgetForm, params, us, false)); | |||||
} | } | ||||
//构建变量 | //构建变量 | ||||
SwMap mapVar = new SwMap(); | SwMap mapVar = new SwMap(); | ||||
@@ -0,0 +1,74 @@ | |||||
<#assign fields = group.cfilters> | |||||
<#list fields as filter> | |||||
{ | |||||
"id": "${newId()}", | |||||
"type": "fx-form-panel", | |||||
"shape": "panel", | |||||
"props": { | |||||
"paddingY": 5, | |||||
"paddingX": 10, | |||||
"size": "35", | |||||
"colNum": 2 | |||||
}, | |||||
"children": [ | |||||
{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-text", | |||||
"props": { | |||||
"label": "${filter.label}", | |||||
"type": "text", | |||||
"maxlength": ${filter.maxlength}, | |||||
"placeholder": "请输入查询内容", | |||||
"labelWidth": 100, | |||||
"dataset": "${filter.dataset}", | |||||
"field": "${filter.field}", | |||||
"name": "${filter.name}" | |||||
}, | |||||
"events": {} | |||||
} | |||||
</#list>, | |||||
{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-button-group", | |||||
"props": { | |||||
"menus": [] | |||||
}, | |||||
"slots": { | |||||
"default": [ | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "查询", | |||||
"leftIcon": "history-query", | |||||
"type": "primary", | |||||
"action": "button:search", | |||||
"dataset": "${group.dataset}" | |||||
}, | |||||
"id": "id${newId()}" | |||||
}, | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "重置", | |||||
"type": "danger", | |||||
"action": "button:reset", | |||||
"leftIcon": "figma-reset-instance" | |||||
}, | |||||
"id": "id${newId()}" | |||||
}, | |||||
{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "新增", | |||||
"type": "success", | |||||
"leftIcon": "shield-add", | |||||
"action": "button:add", | |||||
"dataset": "${group.dataset}" | |||||
} | |||||
} | |||||
] | |||||
} | |||||
} | |||||
] | |||||
}, |
@@ -0,0 +1,74 @@ | |||||
<#assign fields = group.cfilters> | |||||
<#list fields as filter> | |||||
{ | |||||
"shape": "panel", | |||||
"id": "form_panel", | |||||
"type": "fx-form-panel", | |||||
"props": { | |||||
"colNum": 2, | |||||
"paddingX": 5, | |||||
"paddingY": 5, | |||||
"size": "0" | |||||
}, | |||||
"children": [ | |||||
{ | |||||
"id": "id1813718bf71", | |||||
"type": "fx-text", | |||||
"props": { | |||||
"label": "编码", | |||||
"type": "text", | |||||
"maxlength": 50, | |||||
"placeholder": "请输入内容", | |||||
"labelWidth": 100, | |||||
"dataset": "ds_1813718bf61", | |||||
"field": "id_1813718bf67", | |||||
"name": "pt_code" | |||||
}, | |||||
"events": {} | |||||
}, | |||||
{ | |||||
"id": "id1813718bf74", | |||||
"type": "fx-label", | |||||
"props": { | |||||
"label": "标签", | |||||
"labelWidth": 100 | |||||
} | |||||
}, | |||||
{ | |||||
"id": "id1813718bf77", | |||||
"type": "fx-text", | |||||
"props": { | |||||
"label": "名称", | |||||
"type": "text", | |||||
"maxlength": 50, | |||||
"placeholder": "请输入内容", | |||||
"labelWidth": 100, | |||||
"dataset": "ds_1813718bf61", | |||||
"field": "id_1813718bf68", | |||||
"name": "pt_name" | |||||
}, | |||||
"events": {} | |||||
}, | |||||
{ | |||||
"id": "id1813718bf7a", | |||||
"type": "fx-label", | |||||
"props": { | |||||
"label": "标签", | |||||
"labelWidth": 100 | |||||
} | |||||
}, | |||||
{ | |||||
"id": "id1813718bf9b", | |||||
"type": "fx-select", | |||||
"props": { | |||||
"label": "行政区划", | |||||
"clearable": true, | |||||
"labelWidth": 100, | |||||
"dataset": "ds_1813718bf61", | |||||
"field": "id_1813718bf66", | |||||
"name": "pt_area_id" | |||||
}, | |||||
"events": {} | |||||
} | |||||
] | |||||
} |
@@ -0,0 +1,67 @@ | |||||
{ | |||||
"shape": "panel", | |||||
"id": "form_panel", | |||||
"type": "fx-form-panel", | |||||
"props": { | |||||
"colNum": 0, | |||||
"paddingX": 5, | |||||
"paddingY": 5, | |||||
"align": "full" | |||||
}, | |||||
"children": [ | |||||
{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-table", | |||||
"props": { | |||||
"label": "表格", | |||||
"border": true, | |||||
"stripe": true, | |||||
"showHeader": true, | |||||
"fit": true, | |||||
"dataset": "${group.dataset}", | |||||
"actionWidth": 120 | |||||
}, | |||||
"slots": { | |||||
<#assign fields = group.fields> | |||||
"default": [ | |||||
<#list fields as col> | |||||
{ | |||||
"id": "id${newId()}", | |||||
"type": "fx-table-column", | |||||
"props": { | |||||
"field": "${col.field}", | |||||
"label": "${col.label}" | |||||
} | |||||
} | |||||
</#list> | |||||
], | |||||
"button": [ | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "编", | |||||
"type": "text", | |||||
"leftIcon": "edit", | |||||
"action": "button:edit", | |||||
"linkType": "dialog", | |||||
"dataset": "${group.dataset}" | |||||
}, | |||||
"id": "id1813718bf36" | |||||
}, | |||||
{ | |||||
"type": "fx-button", | |||||
"props": { | |||||
"label": "删", | |||||
"type": "text", | |||||
"leftIcon": "delete", | |||||
"action": "button:del", | |||||
"dataset": "${group.dataset}" | |||||
}, | |||||
"id": "id${newId()}" | |||||
} | |||||
] | |||||
}, | |||||
"events": {} | |||||
} | |||||
] | |||||
} |
@@ -0,0 +1,14 @@ | |||||
simple: | |||||
label: 简单页面 | |||||
type: list/scard/ccard | |||||
# 布局 | |||||
layout: | |||||
c1: | |||||
name: '客户区' | |||||
type: 'list' | |||||
hasGroup: false | |||||
# 变量 | |||||
param: | |||||
p1: | |||||
name: '' | |||||
type: 'ds/...' |
@@ -0,0 +1,107 @@ | |||||
{ | |||||
"form": [ | |||||
{ | |||||
"page": { | |||||
"id": "p${newId()}", | |||||
"type": "fx-page", | |||||
"props": { | |||||
"title": "${title}", | |||||
"key": "${newId()}" | |||||
} | |||||
}, | |||||
"graph": { | |||||
"shape": "panel", | |||||
"id": "root_panel", | |||||
"type": "fx-split-panel", | |||||
"props": { | |||||
"horizontal": false, | |||||
"shadow": "never" | |||||
}, | |||||
"children": [ | |||||
<#list layout.c1 as group> | |||||
<#if (group.cfilters?size>0)> | |||||
<#include "inc_filter.ftl"/> | |||||
</#if> | |||||
<#include "inc_grid_opt.ftl"/> | |||||
</#list> | |||||
] | |||||
} | |||||
} | |||||
], | |||||
"model": [ | |||||
{ | |||||
"dataset": "ds_1813718bf0c", | |||||
"label": "机构列表", | |||||
"fields": [ | |||||
{ | |||||
"id": "id_1813718bf0e", | |||||
"field": "pt_id" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf0f", | |||||
"field": "pt_parent_id" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf10", | |||||
"field": "pt_level_code" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf11", | |||||
"field": "pt_area_id" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf12", | |||||
"field": "pt_code" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf13", | |||||
"field": "pt_name" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf14", | |||||
"field": "pt_type" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf15", | |||||
"field": "pt_statu" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf16", | |||||
"field": "pt_linker" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf17", | |||||
"field": "pt_tel" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf18", | |||||
"field": "pt_addr" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf19", | |||||
"field": "pt_lon" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf1a", | |||||
"field": "pt_lat" | |||||
}, | |||||
{ | |||||
"id": "id_1813718bf1b", | |||||
"field": "pt_remark" | |||||
} | |||||
], | |||||
"filters": [ | |||||
{ | |||||
"id": "id_1813718bf21", | |||||
"field": "pt_code", | |||||
"required": false, | |||||
"type": "input" | |||||
} | |||||
] | |||||
} | |||||
], | |||||
"option": { | |||||
"widgetRef": [], | |||||
"vars": [] | |||||
} | |||||
} |