@@ -26,9 +26,6 @@ | |||||
<modules> | <modules> | ||||
<module>sw-framework-core</module> | <module>sw-framework-core</module> | ||||
<module>sw-framework-auth</module> | |||||
<module>sw-framework-file</module> | |||||
<module>sw-framework-web</module> | |||||
<module>../smtweb-system/sw-system-bpm</module> | <module>../smtweb-system/sw-system-bpm</module> | ||||
</modules> | </modules> | ||||
</project> | </project> |
@@ -24,6 +24,7 @@ public class CodeGenerator { | |||||
private final static String TEMPLATE_JAVA_BEAN = "java_bean"; | private final static String TEMPLATE_JAVA_BEAN = "java_bean"; | ||||
private final static String TEMPLATE_JAVA_CACHE = "java_cache"; | private final static String TEMPLATE_JAVA_CACHE = "java_cache"; | ||||
private final static String TEMPLATE_JAVA_SERVICE = "java_service"; | private final static String TEMPLATE_JAVA_SERVICE = "java_service"; | ||||
private final static String TEMPLATE_JS_EVENT = "js_event"; | |||||
private static CodeGenerator instance = null; | private static CodeGenerator instance = null; | ||||
private Configuration configuration = null; | private Configuration configuration = null; | ||||
@@ -111,6 +112,11 @@ public class CodeGenerator { | |||||
generate(model, TEMPLATE_JAVA_SERVICE, fileName); | generate(model, TEMPLATE_JAVA_SERVICE, fileName); | ||||
} | } | ||||
public void generateJsEvent(Map<String, Object> model, String fileName) { | |||||
generate(model, TEMPLATE_JS_EVENT, fileName); | |||||
} | |||||
/** | /** | ||||
* 获取单实例 | * 获取单实例 | ||||
* | * | ||||
@@ -58,6 +58,35 @@ public class CodeBuildHandler extends AbstractHandler { | |||||
return R.success(); | return R.success(); | ||||
} | } | ||||
public R buildJsCode() { | |||||
userName = String.valueOf(us.getUserId()); | |||||
//页面id | |||||
long pageId = params.readLong("pageId"); | |||||
ModelForm form = ModelFormCache.getInstance().get(pageId); | |||||
if (form == null) throw new BizException("未找到指定的页面定义(" + pageId + ")!"); | |||||
String moduleName = ModelProjectCache.getInstance().getModule(form.getPrjId()); | |||||
if (StringUtils.isEmpty(moduleName) || SwConsts.DEF_DB_NAME.equals(moduleName) || moduleName.equals("bpm")) { | |||||
moduleName = "sw-system-bpm"; | |||||
} | |||||
BpmConfigBean bpmConfigBean = SpringUtil.getBean(BpmConfigBean.class); | |||||
Map<String, String> mapIdeaModules = IdeaUtil.getModules(bpmConfigBean.getCodeJavaPath()); | |||||
if (mapIdeaModules == null || mapIdeaModules.isEmpty()) throw new BizException("没有定义idea项目的路径(smtweb.bpm.codeJavaPath)!"); | |||||
codeJavaPath = mapIdeaModules.get(moduleName); | |||||
if (StringUtils.isEmpty(codeJavaPath)) { | |||||
throw new BizException("没有找到对应项目在idea中Module的路径(" + moduleName + ")!"); | |||||
} | |||||
codeJavaPath += "/src/main/resources/"; | |||||
//加上目录 | |||||
String cn = ModelCatalogCache.getInstance().getFullName(form.getMcId()); | |||||
if (StringUtils.isNotEmpty(cn)) { | |||||
codeJavaPath += cn.replaceAll("\\.", "/"); | |||||
} | |||||
new File(codeJavaPath).mkdirs(); | |||||
return R.success(); | |||||
} | |||||
/** | /** | ||||
* 构建java代码路径 | * 构建java代码路径 | ||||
* | * | ||||
@@ -89,6 +118,12 @@ public class CodeBuildHandler extends AbstractHandler { | |||||
} | } | ||||
codeJavaPath += packageName.replaceAll("\\.", "/"); | codeJavaPath += packageName.replaceAll("\\.", "/"); | ||||
new File(codeJavaPath).mkdirs(); | new File(codeJavaPath).mkdirs(); | ||||
SwMap model = new SwMap(); | |||||
model.put("user", userName); | |||||
model.put("sysTime", DateUtil.nowDateTime()); | |||||
model.put("title", form.getTitle()); | |||||
CodeGenerator.getInstance().generateJsEvent(model, codeJavaPath + "/" + form.getName() + ".js"); | |||||
} | } | ||||
/** | /** | ||||
@@ -145,7 +145,7 @@ public class ModelFormService extends AbstractCompService { | |||||
return R.success(CodeGenerator.getInstance().getModelTemplates()); | return R.success(CodeGenerator.getInstance().getModelTemplates()); | ||||
} | } | ||||
//加载模板定义 | |||||
//生成java代码 | |||||
public R buildJavaCode(@SwBody SwMap params, UserSession us) { | public R buildJavaCode(@SwBody SwMap params, UserSession us) { | ||||
try { | try { | ||||
CodeBuildHandler handler = (CodeBuildHandler) getHandler(params, us, TYPE_CODE); | CodeBuildHandler handler = (CodeBuildHandler) getHandler(params, us, TYPE_CODE); | ||||
@@ -154,4 +154,14 @@ public class ModelFormService extends AbstractCompService { | |||||
return R.error("操作失败!", e); | return R.error("操作失败!", e); | ||||
} | } | ||||
} | } | ||||
//生成js代码 | |||||
public R buildJsCode(@SwBody SwMap params, UserSession us) { | |||||
try { | |||||
CodeBuildHandler handler = (CodeBuildHandler) getHandler(params, us, TYPE_CODE); | |||||
return handler.buildJsCode(); | |||||
} catch (Exception e) { | |||||
return R.error("操作失败!", e); | |||||
} | |||||
} | |||||
} | } |
@@ -0,0 +1,17 @@ | |||||
/** | |||||
* Created by ${user} at ${sysTime} | |||||
* 注册事件类【${title}】,参看event.defaultEvent.js | |||||
*/ | |||||
window.$swEvent.setup("defaultEvent", { | |||||
setup(page){ | |||||
const { $params,$refs, $widgets, $model, $utils, $tabRouter, $api } = page; | |||||
const { $$message, $$http } = $utils; | |||||
// 示例 | |||||
const demoFunc = () => { | |||||
}; | |||||
return { | |||||
demoFunc, | |||||
} | |||||
} | |||||
}); |