diff --git a/skyeye-web/src/main/webapp/assets/lib/layui/custom.js b/skyeye-web/src/main/webapp/assets/lib/layui/custom.js index 645683b1869bb78cf598bebf6174f17db48aec6e..d7718095edeaf6def601162a23c0c3857bff9432 100644 --- a/skyeye-web/src/main/webapp/assets/lib/layui/custom.js +++ b/skyeye-web/src/main/webapp/assets/lib/layui/custom.js @@ -1115,6 +1115,15 @@ function showDataUseHandlebars(id, source, data){ layui.$("#" + id).html(html); } +function getDataUseHandlebars(source, data){ + //预编译模板 + var template = Handlebars.compile(source); + //匹配json内容 + var html = template(data); + //输入模板 + return html; +} + diff --git a/skyeye-web/src/main/webapp/js/codemodelgroup/addcontenttohtmlorjs.js b/skyeye-web/src/main/webapp/js/codemodelgroup/addcontenttohtmlorjs.js index 0d50e907220151391e01855ef06ad0391f093320..8cf2224faba352f28c9dc16b561e81fc33a80bfb 100644 --- a/skyeye-web/src/main/webapp/js/codemodelgroup/addcontenttohtmlorjs.js +++ b/skyeye-web/src/main/webapp/js/codemodelgroup/addcontenttohtmlorjs.js @@ -1,4 +1,6 @@ +var params = ''; + layui.config({ base: basePath, version: skyeyeVersion @@ -16,7 +18,7 @@ layui.config({ form.render('select'); form.on('select(tableColumn)', function(data){ - console.log(1); + returnResult(); }); form.on('select(showModel)', function(data){ @@ -35,7 +37,7 @@ layui.config({ jsSuccessEditor.setOption('mode', mode); } jsModelEditor.setValue(json.bean.jsContent); - + returnResult(); }else{ top.winui.window.msg(json.returnMessage, {icon: 2,time: 2000}); } @@ -43,7 +45,7 @@ layui.config({ }); form.on('checkbox(checkboxLimit)', function(data){ - console.log(2); + returnResult(); }); //展现形式 @@ -127,16 +129,80 @@ layui.config({ form.on('submit(formAddBean)', function (data) { //表单验证 if (winui.verifyForm(data.elem)) { - + var result = { + formermation: params.require, + aftermation: params.aftermation, + htmlContent: htmlSuccessEditor.getValue(), + jsContent: jsSuccessEditor.getValue(), + }; + parent.result = result; + parent.layer.close(index); + parent.refreshCode = '0'; } return false; }); + $("body").on("keyup", "#placeholderName", function(e){ + returnResult(); + }); + + $("body").on("keyup", "#valueName", function(e){ + returnResult(); + }) + + function returnResult(){ + var tableColumn = $("#tableColumn").val(); + var labelName = "", id = "", name = "", formermation = "", aftermation = ""; + if(!isNull(tableColumn)){ + labelName = tableColumn.split('--')[0]; + id = replaceUnderLineAndUpperCase(tableColumn.split('--')[1]); + name = replaceUnderLineAndUpperCase(tableColumn.split('--')[1]); + } + + if(!isNull(htmlModelEditor.getValue())){ + $.each($('input:checkbox:checked'),function(){ + formermation = formermation + $(this).attr("formermation") + "|"; + aftermation = aftermation + $(this).attr("aftermation") + ","; + }); + params = { + labelContent: labelName, + id: id, + name: name, + require: formermation, + aftermation: aftermation, + value: $("#valueName").val(), + placeholder: $("#placeholderName").val(), + }; + htmlSuccessEditor.setValue(getDataUseHandlebars(htmlModelEditor.getValue(), params)); + if(!isNull(jsModelEditor.getValue())){ + jsSuccessEditor.setValue(getDataUseHandlebars(jsModelEditor.getValue(), params)); + } + } + } + //取消 $("body").on("click", "#cancle", function(){ parent.layer.close(index); }); + /** + * 将字段转为Java经常使用的名字,如code_model转codeModel + */ + function replaceUnderLineAndUpperCase(str){ + str = str.split(""); + var count = str.indexOf("_"); + while (count != 0) { + var num = str.indexOf("_", count); + count = num + 1; + if (num != -1) { + var ss = str[count]; + var ia = ss.toUpperCase(); + str.splice(count, 1, ia); + } + } + return str.join("").replace(/[_]/g, ""); + } + }); }); \ No newline at end of file diff --git a/skyeye-web/src/main/webapp/js/codemodelgroup/usemodelgroup.js b/skyeye-web/src/main/webapp/js/codemodelgroup/usemodelgroup.js index 4575a4318737272ee01bd274ed74ca12cfda55dc..604a694198b91e83da5ed4b8eeab5bad694ea24c 100644 --- a/skyeye-web/src/main/webapp/js/codemodelgroup/usemodelgroup.js +++ b/skyeye-web/src/main/webapp/js/codemodelgroup/usemodelgroup.js @@ -1,6 +1,8 @@ var tableColumn = '';//数据库表中的列 +var result = '';//html/xml/js添加的内容项 + layui.config({ base: basePath, version: skyeyeVersion @@ -195,7 +197,7 @@ layui.config({ pageId: "addcontenttohtmlorjs", callBack: function(refreshCode){ if (refreshCode == '0') { - + console.log(result); } else if (refreshCode == '-9999') { top.winui.window.msg("操作失败", {icon: 2,time: 2000}); } diff --git a/skyeye-web/src/main/webapp/tpl/codemodelgroup/addcontenttohtmlorjs.html b/skyeye-web/src/main/webapp/tpl/codemodelgroup/addcontenttohtmlorjs.html index 8b01bfdb84fb1b635edea914d159acf86152abdb..c22956b8bf2e4863594baae1372725718b5a181c 100644 --- a/skyeye-web/src/main/webapp/tpl/codemodelgroup/addcontenttohtmlorjs.html +++ b/skyeye-web/src/main/webapp/tpl/codemodelgroup/addcontenttohtmlorjs.html @@ -32,6 +32,18 @@
+
+ +
+ +
+
+
+ +
+ +
+
@@ -59,7 +71,7 @@
- +