From 726282fc3c3d2657fe65f8b5eb9c76e589bba644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=A3=95=E8=B4=A2?= Date: Fri, 13 Oct 2023 02:05:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/mdp/lcode/dev.js | 6 +- src/api/mdp_pub/mdp_api_base.js | 7 +- src/views/mdp/lcode/formDef/Form.vue | 101 +++++++++++++++------------ 3 files changed, 68 insertions(+), 46 deletions(-) diff --git a/src/api/mdp/lcode/dev.js b/src/api/mdp/lcode/dev.js index 87307bf..55d6a3c 100644 --- a/src/api/mdp/lcode/dev.js +++ b/src/api/mdp/lcode/dev.js @@ -5,4 +5,8 @@ import axios from '@/utils/request' let base = config.getLcodeContext(); //在线生成crud代码并下载 -export const crudCodeGen = params => { return axios.get(`${base}/mdp/dev/code/gen`, {params:params}); }; \ No newline at end of file +export const crudCodeGen = params => { return axios.get(`${base}/mdp/dev/code/gen`, {params:params}); }; + + +//查询数据源列表 +export const dataSourceList = params => { return axios.get(`${base}/mdp/dev/db/dataSource/list`, {params:params}); }; \ No newline at end of file diff --git a/src/api/mdp_pub/mdp_api_base.js b/src/api/mdp_pub/mdp_api_base.js index bd34a82..ec8bfc0 100644 --- a/src/api/mdp_pub/mdp_api_base.js +++ b/src/api/mdp_pub/mdp_api_base.js @@ -69,6 +69,7 @@ clearDictCache:function(itemCode,params){ **/ ajaxGetDictOptions:function(itemCode, params) { + debugger; var codeKey=funcs.getCodeKey(itemCode,params); return new Promise((resolve,reject)=>{ var data=funcs.getDictOptionsFromCache(codeKey,itemCode,params) @@ -108,7 +109,11 @@ ajaxGetDictOptions:function(itemCode, params) sessionStorage.setItem(lockKey,"1") funcs.getDicts(params).then(res=>{ - if(res.data.tips && res.data.tips.isOk && res.data.data && res.data.data.length>0){ + if(res.data.tips && res.data.tips.isOk){ + if(!res.data.data || res.data.data.length==0){ + resolve({tips:res.data.tips,data:{}}) + return; + } var item=res.data.data[0] if(item.options && item.options.length>0){ item.options.forEach(k=>{ diff --git a/src/views/mdp/lcode/formDef/Form.vue b/src/views/mdp/lcode/formDef/Form.vue index 636f3f5..e5096f5 100644 --- a/src/views/mdp/lcode/formDef/Form.vue +++ b/src/views/mdp/lcode/formDef/Form.vue @@ -20,7 +20,7 @@ @@ -77,6 +80,7 @@ import { mapGetters } from 'vuex' import { MdpFormMixin } from '@/components/mdp-ui/mixin/MdpFormMixin.js'; import FormField from '../formField/Index' import MdpSource from '../source/Index' +import {dataSourceList} from '@/api/mdp/lcode/dev' export default { name:'formDefForm', mixins:[MdpFormMixin], @@ -128,7 +132,7 @@ export default { ] }, editForm: { - id:'',tableName:'',tableOwner:'',isCreateTable:'0',formName:'',userid:'',deptid:'',formType:'',isTemplate:'',bizType:'',ctime:'',branchId:'',categoryId:'',tagIds:'',tagNames:'',username:'',deptName:'',groupsJson:'',pks:'',dataType:'1',dataField:'extInfos' + id:'',tableName:'',tableOwner:'',isCreateTable:'0',formName:'',userid:'',deptid:'',formType:'',isTemplate:'',bizType:'',ctime:'',branchId:'',categoryId:'',tagIds:'',tagNames:'',username:'',deptName:'',groupsJson:'',pks:'',dataType:'1',dataField:'ext_infos',ctType:'2' }, //增删改查(含批量)接口 apis:{ @@ -143,6 +147,7 @@ export default { } }, methods: { + dataSourceList, //由组件扩展添加其它的初始页面的逻辑(mounted+onOpen都会调用此函数,建议只添加公共逻辑) initCurrData(){ if(!this.formId){ @@ -206,49 +211,57 @@ export default { return true; }, saveSubmit: function () { - if(this.editForm.formName==''){ - this.$notify({position:'bottom-left',showClose:true,message: '表单名称不能为空', type: 'error' }); - return; - } - var formFields=this.$refs.formFields.getFieldList(); - if(formFields.length==0 ){ - this.$notify({position:'bottom-left',showClose:true,message: '最少需要定义一个字段', type: 'error' }); - return; - } - this.$confirm('确认提交吗?', '提示', {}).then(() => { - this.load.edit=true - let formDef = Object.assign({}, this.editForm); - if(this.currOpType=='add'){ - formDef.deptid=this.userInfo.deptid - formDef.branchId=this.userInfo.branchId + this.$refs['editFormRef'].validate(valid=>{ + if(valid==false){ + this.$notify({position:'bottom-left',showClose:true,message: '表单验证不通过', type: 'error' }); + return; } - - this.$refs.formFields.setPrimaryKeys(); - - formFields.forEach((i,index)=>{i.seq=index}); - var params={formDef:formDef,formFields:formFields}; - if(!this.preParamCheck(params)){ - this.load.edit=false + if(this.editForm.formName==''){ + this.$notify({position:'bottom-left',showClose:true,message: '表单名称不能为空', type: 'error' }); return; } - var func=this.apis.add - if(this.currOpType=='edit'){ - func=this.apis.edit + var formFields=this.$refs.formFields.getFieldList(); + if(formFields.length==0 ){ + this.$notify({position:'bottom-left',showClose:true,message: '最少需要定义一个字段', type: 'error' }); + return; } - func(params).then((res) => { - this.load.edit=false - var tips=res.data.tips; - if(tips.isOk){ - this.$mdp.removeFormFieldsCache(formDef.id) - this.currOpType='edit' - var data=res.data.data - Object.assign(this.editForm,data.formDef) - this.formFields=data.formFields - this.afterSubmit(res,tips.isOk,this.currOpType); + this.$confirm('确认提交吗?', '提示', {}).then(() => { + this.load.edit=true + let formDef = Object.assign({}, this.editForm); + if(this.currOpType=='add'){ + formDef.deptid=this.userInfo.deptid + formDef.branchId=this.userInfo.branchId } - this.$notify({ position:'bottom-left',showClose:true, message: tips.msg, type: tips.isOk?'success':'error' }); - }).catch( err =>this.load.edit=false); - }); + + this.$refs.formFields.setPrimaryKeys(); + + formFields.forEach((i,index)=>{i.seq=index}); + var params={formDef:formDef,formFields:formFields}; + if(!this.preParamCheck(params)){ + this.load.edit=false + return; + } + var func=this.apis.add + if(this.currOpType=='edit'){ + func=this.apis.edit + } + func(params).then((res) => { + this.load.edit=false + var tips=res.data.tips; + if(tips.isOk){ + this.$mdp.removeFormFieldsCache(formDef.id) + this.currOpType='edit' + var data=res.data.data + Object.assign(this.editForm,data.formDef) + this.formFields=data.formFields + this.afterSubmit(res,tips.isOk,this.currOpType); + } + this.$notify({ position:'bottom-left',showClose:true, message: tips.msg, type: tips.isOk?'success':'error' }); + }).catch( err =>this.load.edit=false); + }); + + }) + }, goToFormDefIndex(){ this.$router.push({path:'/mdp/lcode/index'})