genCodeForm.js 8.2 KB

1
  1. var validForm;function doSubmit(t){if(!validForm.form())return!1;$("#inputForm select[id*=mainTableField]").removeAttr("disabled"),$("#name").val($("#systemName").val()+"."+$("#serviceName").val()),formAjaxSubmit($("#inputForm"),function(e){localStorage.packageName=$("#packageName").val(),localStorage.functionAuthor=$("#functionAuthor").val(),t(e)})}var inputFormVm=new Vue({el:"#inputForm",data:function(){return{msConfig:{},entity:{id:getQueryString("id"),genTable:{id:getQueryString("genTable.id")},category:"single_table",style:"",packageName:"",moduleName:"",subModuleName:"",functionName:"",functionNameSimple:"",functionAuthor:"",maxQueryColumns:"3"},pageDictMap:{},styleList:[],formLoading:!0}},computed:{categoryDict:function(){return this.pageDictMap.gen_category},maxQueryColumnsDict:function(){return this.pageDictMap.query_column_num},isMSABackServer:function(){return"msa"===commonConfig.backServerType},urlPrefix:function(){return this.msConfig.gatewayRoute+this.msConfig.direwolfAdmin+"/genScheme"},saveUrl:function(){return commonConfig.proxyPath+this.msConfig.gatewayRoute+this.msConfig.direwolfAdmin+"/genScheme/genCode?needFetchRelation=F"}},methods:{getDefaultStyleList:function(){var t=this,a="获取默认样式列表";axios.get(t.urlPrefix+"/getDefaultStyleList?genTable.id="+t.entity.genTable.id).then(function(e){t.styleList=getDataFromAxiosResponse(e,a).data}).catch(function(e){axiosErrorTips(e,a+"异常")})},initFormData:function(){var n=this,i="获取信息";axios.get(n.urlPrefix+"/getRecord?genTable.id="+n.entity.genTable.id).then(function(e){var t,a=getDataFromAxiosResponse(e,i);a.id&&(n.entity=a,n.isMSABackServer&&(n.entity.name?(t=n.entity.name.split("."),n.entity.systemName=t[0],n.entity.serviceName=t[1]):(n.entity.systemName="",n.entity.serviceName=""))),n.$nextTick(function(){schemeFormReload(a.category,a.style),toggleRelationHidden()})}).catch(function(e){axiosErrorTips(e,i+"异常")})}},created:function(){var t=this;t.msConfig=window.__CODEGEN_CONFIG__,checkPagePermission(t.urlPrefix+"/checkGenCodeFormPermission"),t.getDefaultStyleList();var a="获取字典信息";axios.get(dictUrl+"gen_category,query_column_num").then(function(e){t.pageDictMap=getDataFromAxiosResponse(e,a).data,t.initFormData()}).catch(function(e){axiosErrorTips(e,a+"异常")})},mounted:function(){$("#name").focus(),validForm=$("#inputForm").validate({submitHandler:function(e){loading("正在提交,请稍等...")},errorContainer:"#messageBox",errorPlacement:function(e,t){$("#messageBox").text("输入有误,请先更正。"),t.is(":checkbox")||t.is(":radio")||t.parent().is(".input-append")?e.appendTo(t.parent().parent()):e.insertAfter(t)}}),$("#category").change(function(e){schemeFormReload($("#category").val(),null),toggleRelationHidden()}),$("#style").change(function(e){schemeFormReload($("#category").val(),$("#style").val())}),$.each($("table#relationTable>tbody>tr"),function(e,t){bindRowEvent($(t))}),$(".relationEditBtnsTd").html(renderRowBtns()),$("#id").val()||($("#packageName").val(localStorage.packageName||""),$("#functionAuthor").val(localStorage.functionAuthor||""))}});function toggleRelationHidden(){var e=$("#category").val();"host_slave_table"===e||"tree_table"===e?$("tr#relationROW").show():$("tr#relationROW").hide(),"tree_table"===e&&($("table#relationTable>thead th").last().hide(),$("table#relationTable>tbody td").last().hide()),inputFormVm.formLoading=!1}function delRelationClicked(e){var t=$(e.currentTarget.parentElement.parentElement);1!==t.parent().children().length?(t.remove(),resetRowNum()):toastr.info("当前仅存一条关联记录,不能删除。")}function addRelationClicked(e){var t=$(e.currentTarget.parentElement.parentElement).clone();$("label").remove(".error"),t.find("label").remove(".error"),bindRowEvent(t),$("table#relationTable>tbody").append(t),resetRowNum()}function resetRowNum(){$.each($("table#relationTable>tbody>tr"),function(n,e){$(e).attr("id",n),$.each($(e).children(),function(e,t){var a;e<3&&((a=t.firstChild).id="relationList"+n+a.id.substr(a.id.indexOf(".")),a.name="relationList["+n+"]"+a.name.substr(a.name.indexOf(".")))})})}function refTableChanged(e){for(var t=e.data,a=$(e.currentTarget).val(),n=$("table#relationTable>tbody>tr"),i=0;i<n.length;i++)if($(n[i]).find("select[name*=refTable\\.id]").val()===a&&$(n[i]).attr("id")!==t.attr("id"))return void toastr.info("该表关联已添加!");var o=$($(e.currentTarget).parent().next().children()[0]);o.val(""),o.empty();var r,l;a?(o.append($('<option value="">--请选择从表字段--</option>')),r=new ProjectConfig,null!=(l=$.parseJSON($.ajax({url:r.proxyPath+window.__CODEGEN_CONFIG__.gatewayRoute+window.__CODEGEN_CONFIG__.direwolfAdmin+"/codegen/getColumnList?id="+a,async:!1}).responseText))&&"undefined"!==(l.type,!1)&&"success"===l.type&&$.each(l.data,function(e,t){o.append($('<option value="'+t.name+'">'+t.name+"</option>"))})):o.append($('<option value="">--请先选择从表--</option>'))}function bindRowEvent(e){e.find("select[name*=refTable\\.id]").change(e,refTableChanged),e.find("div#addRelation").click(addRelationClicked),e.find("div#delRelation").click(delRelationClicked)}function schemeFormReload(e,t){var a=commonConfig.proxyPath+inputFormVm.urlPrefix+"/refreshSchemeForm?";$("#genTable\\.id").val()&&(a+="&genTable.id="+$("#genTable\\.id").val()),e&&(a+="&category="+e),t&&(a+="&style="+t);var n=$.parseJSON($.ajax({url:a,async:!1}).responseText);if(null!=n&&void 0!==n.type&&"success"===n.type){if(!(void 0!==n.data.styleList&&0<n.data.styleList.length))return $("#style").val(""),$("#style").empty(),void direwolfCommonTips("error","选择的代码分类无对应风格的代码模板");if($("#style").val(""),$("#style").empty(),$.each(n.data.styleList,function(e,t){$("#style").append($('<option value="'+t.style+'">'+t.label+"</option>"))}),t&&$("#style").val(t),void 0!==n.data.genScheme){var i=n.data.genScheme;$("#id").val(i.id),$("#packageName").val(i.packageName||localStorage.packageName||""),$("#moduleName").val(i.moduleName),$("#subModuleName").val(i.subModuleName),$("#functionName").val(i.functionName),$("#functionNameSimple").val(i.functionNameSimple),$("#functionAuthor").val(i.functionAuthor||localStorage.functionAuthor||""),$("#maxQueryColumns").val(i.maxQueryColumns||3),$("table#relationTable>tbody").empty();for(var l="",o=i.genTable.columnList,r=o.map(function(e){return e.name}),d=["create_time","create_user_id","modify_time","modify_user_id","locak_version"];0<d.length;d++)if(-1===r.indexOf(d[0])){direwolfCommonTips("error","表单未包含必须的字段"+d[0]+",生成的代码可能无法正常运行!");break}$.each(o,function(e,t){l+='<option value="'+t.name+'">'+t.name+"</option>"});var c="<option value=''>--请选择从表--</option>";$.each(n.data.tableList,function(e,t){c+='<option value="'+t.id+'">'+t.tableAlias+"</option>"}),$.each(i.relationList,function(e,t){var a=$('<tr id="'+e+'"></tr>'),n=$('<td><select id="relationList'+e+'.mainTableField" name="relationList['+e+'].mainTableField" class="required form-control"></select></td>'),i=$('<td><select id="relationList'+e+'.refTable.id" name="relationList['+e+'].refTable.id" class="required form-control"></select></td>'),o=$('<td><select id="relationList'+e+'.refTableField" name="relationList['+e+'].refTableField" class="required form-control"></select></td>'),r=$("<td>"+renderRowBtns()+"</td>");$(n.children()[0]).append($(l)),$(i.children()[0]).append($(c)),a.append(n).append(i).append(o).append(r),bindRowEvent(a),$("table#relationTable>tbody").append(a),t.mainTableField&&$(n.children()[0]).val(t.mainTableField),t.refTable?$(i.children()[0]).val(t.refTable.id):$(i.children()[0]).val(""),$(i.children()[0]).trigger("change"),t.refTableField?$(o.children()[0]).val(t.refTableField):$(o.children()[0]).val("")})}else toastr.error("获取计划数据失败!")}else toastr.error(n.message||"重新加载计划失败!")}function renderRowBtns(){return"<div title='新增' style='float: left; cursor: pointer;margin:10px 5px 10px 5px;' id='addRelation' class='ui-pg-div ui-inline-edit'><span class='ui-icon fa fa-plus blue' style='text-indent: initial;'></span></div><div title='删除' style='float: left; cursor: pointer;margin:10px 5px 10px 5px;' id='delRelation' class='ui-pg-div ui-inline-edit'><span class='ui-icon fa fa-trash red' style='text-indent: initial;'></span></div>"}