1 |
- var validForm,inputFormVm=new Vue({el:"#inputForm",data:function(){return{editType:GetQueryString("viewType"),entity:{id:getQueryString("id"),name:"",comments:"",dataLogicType:"",tableAlias:"",genDatasource:{dsName:"",dbType:""},className:"",primaryKey:"",pkField:"",idGenName:"",columnList:[],pkFieldType:""},pageDictMap:{}}},computed:{dataLogicTypeDict:function(){return this.pageDictMap.data_logic_type},javaTypeDict:function(){return this.pageDictMap.gen_java_type},queryTypeDict:function(){return this.pageDictMap.gen_query_type},showTypeDict:function(){return this.pageDictMap.gen_show_type},urlPrefix:function(){var e=window.__CODEGEN_CONFIG__;return e.gatewayRoute+e.direwolfAdmin+"/codegen"},saveUrl:function(){var e=window.__CODEGEN_CONFIG__;return(new ProjectConfig).proxyPath+e.gatewayRoute+e.direwolfAdmin+"/codegen/genTableForm/save"},needSequence:function(){return"Long"===this.entity.pkFieldType&&("01"===this.entity.genDatasource.dbType||"03"===this.entity.genDatasource.dbType)}},methods:{initFormData:function(){var e,n,r=this,t=this.entity.id;t&&(e=this.urlPrefix+"/getRecord?id="+t,n="获取表单信息",axios.get(e).then(function(e){var t=getDataFromAxiosResponse(e,n);if(t.id){for(var a=t.columnList.map(function(e){return e.name}),i=["create_time","create_user_id","modify_time","modify_user_id","locak_version"];0<i.length;i++)if(-1===a.indexOf(i[0])){direwolfCommonTips("error","表单未包含必须的字段"+i[0]+",生成的代码可能无法正常运行!");break}r.entity=t,r.$nextTick(function(){$.each($("#pageTable>tbody tr"),function(e,t){var a=$(t).find("select[name*=showType]")[0],i=$(t).find("input[name*=javaField]")[0];disableCustomObjFields(a.value,i.value,e)})})}}).catch(function(e){axiosErrorTips(e,n+"异常")}))},isCustomJavaType:function(e){return-1!==e.javaType.indexOf(".")||-1!==e.javaField.indexOf("|")},getClassName:function(e){var t=e.split(".");return t[t.length-1]}},created:function(){var t=this;checkPagePermission(t.urlPrefix+"/checkGenTableFormPermission");var a="获取字典信息";axios.get(dictUrl+"data_logic_type,gen_java_type,gen_query_type,gen_show_type").then(function(e){t.pageDictMap=getDataFromAxiosResponse(e,a).data,t.initFormData()}).catch(function(e){axiosErrorTips(e,a+"异常")})},mounted:function(){var o,s;validForm=$("#inputForm").validate({submitHandler:function(e){loading("正在提交,请稍等...")},errorPlacement:function(e,t){t.is(":checkbox")||t.is(":radio")||t.parent().is(".input-append")?e.appendTo(t.parent()):e.insertAfter(t)}}),resetColumnNo(),$("#dataProTable").tableDnD({onDragClass:"myDragClass",onDrop:function(e,t){s=$(t).index();var a=$("#pageProperty #pageTable tbody tr:eq("+s+")"),i=$("#pageProperty #pageTable tbody tr:eq("+o+")"),n=$("#gridProperty #gridTable tbody tr:eq("+s+")"),r=$("#gridProperty #gridTable tbody tr:eq("+o+")");o<s?(i.insertAfter(a),r.insertAfter(n)):(i.insertBefore(a),r.insertBefore(n)),resetColumnNo()},onDragStart:function(e,t){o=$(t).index()}})}});function doSubmit(e){if(!validForm.form())return!1;for(var t=$("#advancedProperty>tbody input[name*=Sort]"),a=0;a<t.length;a++)if(!t[a].value)return toastr.error("高级属性排序字段不能为空,请填写后再保存!","校验失败"),$(r).focus(),$(t[a]).focus(),!1;for(var i=$("#pageTable>tbody"),n=i.find("select[name*=showType]"),a=0;a<n.length;a++){if("orgselect"===(m=n[a]).value||"userselect"===m.value||"gridselect"===m.value||"treeselect"===m.value){var r=i.find("input[name*=javaField]")[a];if(-1===r.value.indexOf("|"))return toastr.error("java属性名称格式不正确,请修正后再保存!","校验失败"),$(r).focus(),!1}else if("select"===m.value||"multipleselect"===m.value||"radiobox"===m.value||"checkbox"===m.value){var o=i.find("input[name*=dictType]")[a];if(!o.value)return toastr.error("字典类型不能为空,请填写后再保存!","校验失败"),$(o).focus(),!1}var s=$("#gridTable>tbody");if("gridselect"===m.value||"treeselect"===m.value){if(!(f=s.find("input[name*=tableName]")[a]).value)return toastr.error("自定义Java对象来源表未定义,请添加后再保存!","校验失败"),$(f).focus(),!1;var l=s.find("input[name*=fieldKeys]")[a];if(!l.value)return toastr.error("自定义Java对象字段未指定,请添加后再保存!","校验失败"),$(l).focus(),!1;if("gridselect"===m.value){var u=s.find("input[name*=fieldLabels]")[a];if(!u.value)return toastr.error("自定义Java对象字段说明未填写,请添加后再保存!","校验失败"),$(u).focus(),!1;var d=s.find("input[name*=searchLabel]")[a];if(!d.value)return toastr.error("自定义Java对象查询字段说明未填写,请添加后再保存!","校验失败"),$(d).focus(),!1;var c=s.find("input[name*=searchKey]")[a];if(!c.value)return toastr.error("自定义Java对象查询字段未填写,请添加后再保存!","校验失败"),$(c).focus(),!1}}}for(var p=i.find("select[name*=javaField]"),a=0;a<p.length;a++){var f,m=p[a],v=i.find("select[name*=showType]")[a];if(-1!=m.value.indexOf("|")&&"orgselect"!=v&&"userselect"!=v)if(!(f=s.find("input[name*=tableName]")[a]).value)return toastr.error("自定义Java对象来源表未定义,请添加后再保存!","校验失败"),$(f).focus(),!1}var y=$("form#inputForm select#primaryKey"),g=y[0].selectedOptions[0].text;if(!y.val())return toastr.error("主键字段不能为空!","校验失败"),y.focus(),!1;for(var b=i.find("input[type=checkbox][name*=isPk]"),a=0;a<b.length;a++){i.find("input[name*=name]")[a].value===g?b[a].checked=!0:b[a].checked=!1}$("input[type=checkbox]").each(function(){$(this).prop("checked")?$(this).attr("value","1"):$(this).after('<input type="hidden" name="'+$(this).attr("name")+"\" value='0'>")}),formAjaxSubmit($("#inputForm"),e,inputFormVm.entity)}function resetColumnNo(){$("#dataProperty #dataProTable tbody tr").each(function(n,e){$(this).find("span[name*=columnList],select[name*=columnList],input[name*=columnList]").each(function(){var e=$(this).attr("name"),t=e.split("."),a=t[1];2<t.length&&(a=a+"."+t[2]);var i="columnList["+n+"]."+a;$(this).attr("name",i),0<=e.indexOf(".sort")&&($(this).val(n+1),$(this).next().text(n+1))})})}function javaTypeChanged(a){var i;"Custom"===a.value&&(i=null,top.layer.open({title:"请输入自定义的类全名",btn:["确定"],content:'<input type="text" class="layui-layer-input" value="">',skin:"layui-layer-prompt layer-ext-moon layer-ext-moon-prompt",success:function(e){(i=e.find(".layui-layer-input")).focus()},yes:function(e){var t=i.val();""===t?i.focus():500<t.length?layer.tips("类全名长度不得超过500字符",i,{tips:1}):($customClass=$("<option value='' selected></option>"),$customClass.val(t),$customClass.text(t.substr(t.lastIndexOf(".")+1,t.length)),$($(a)[0]).append($customClass),top.layer.close(e))},cancel:function(e){a.selectedIndex=getOptionIndex(a,"String"),top.layer.close(e)}}))}function showTypeChanged(e){var t,a=e.name.split("[")[1].split("]")[0],i=inputFormVm.entity.columnList[a],n=$(e.parentElement.parentElement),r=n.find("select[name*=javaType]")[0],o=n.find("input[name*=javaField]")[0];"orgselect"===e.value?(i.javaType="com.set.direwolf.sys.entity.Org",i.javaField="org.id|orgName"):"userselect"===e.value?(i.javaType="com.set.direwolf.sys.entity.User",i.javaField="user.id|userName"):(-1!==i.javaField.indexOf("|")&&(i.javaField=""),"webuploader"===e.value?(i.genTableColumnUi.isList="0",i.genTableColumnUi.isQuery="0",i.javaType="String"):"textarea"===e.value?(i.javaType="String",i.genTableColumnUi.isList="0"):"dateselect"===e.value?i.javaType="java.util.Date":"gridselect"===e.value||"treeselect"===e.value?(t=getOptionIndex(r,"Custom"),r.selectedIndex<t&&(i.javaType="Custom",$(r).trigger("change"))):i.javaType="String"),disableCustomObjFields(e.value,o.value,a)}function disableCustomObjFields(e,t,a){var i=$("#gridTable>tbody"),n=i.find("input[name*=tableName]")[a],r=i.find("input[name*=fieldLabels]")[a],o=i.find("input[name*=fieldKeys]")[a],s=i.find("input[name*=searchLabel]")[a],l=i.find("input[name*=searchKey]")[a];"treeselect"===e?(n.disabled="",r.disabled="disabled",o.disabled="",s.disabled="disabled",l.disabled="disabled"):"gridselect"===e?(n.disabled="",r.disabled="",o.disabled="",s.disabled="",l.disabled=""):(-1!==t.indexOf("|")&&"orgselect"!==e&&"userselect"!==e?n.disabled="":n.disabled="disabled",r.disabled="disabled",o.disabled="disabled",s.disabled="disabled",l.disabled="disabled")}function getOptionIndex(e,a){var i=-1;return $.each(e.options,function(e,t){t.text===a&&(i=t.index)}),i}
|