From f5f8aaedd1d488fb20a293182dd7a40e2e82096e Mon Sep 17 00:00:00 2001 From: wangting <675591594@qq.com> Date: 星期二, 30 四月 2024 12:20:44 +0800 Subject: [PATCH] 添加action --- Source/ProjectWeb/src/actions/base/AddAction.js | 1 Source/ProjectWeb/src/components/dynamic-components/dynamic-button.vue | 69 ++-------- Source/ProjectWeb/src/actions/base/BaseAction.js | 54 ++++++++ Source/ProjectWeb/src/components/actions/AddEditDialog.vue | 117 +++++++++++++----- Source/ProjectWeb/src/api/base/ui.js | 2 Source/ProjectWeb/src/components/dynamic-components/dynamic-form.vue | 6 Source/ProjectWeb/src/components/PLT-basic-component/basicForm.vue | 52 +++++++- Source/ProjectWeb/src/actions/base/EditAction.js | 1 8 files changed, 200 insertions(+), 102 deletions(-) diff --git a/Source/ProjectWeb/src/actions/base/AddAction.js b/Source/ProjectWeb/src/actions/base/AddAction.js index 5ac9b70..965a7e2 100644 --- a/Source/ProjectWeb/src/actions/base/AddAction.js +++ b/Source/ProjectWeb/src/actions/base/AddAction.js @@ -7,7 +7,6 @@ import AddEditDialog from "@/components/actions/AddEditDialog" export const doAction = (options,callback) => { - options.paramVOS = paramLow(options.paramVOS) const paramVOS = Object.assign({ url: '/api/uiDataController/addSave', method: 'post', diff --git a/Source/ProjectWeb/src/actions/base/BaseAction.js b/Source/ProjectWeb/src/actions/base/BaseAction.js index c4cec61..2482fde 100644 --- a/Source/ProjectWeb/src/actions/base/BaseAction.js +++ b/Source/ProjectWeb/src/actions/base/BaseAction.js @@ -9,7 +9,44 @@ * action閫氱敤鍏ュ彛 */ export const doAction = (button,options,callback) => { + options.paramVOS = paramLow(options.paramVOS) options.paramVOS['title']=replaceFreeMarker(options.paramVOS.title,options.dataStore,options.sourceData); + let isShow = true; + if (options.paramVOS['initvalue'] && typeof(options.paramVOS.initvalue)=='string') { + let values = options.paramVOS['initvalue'].split(';'); + let initValues = {} + values.forEach((item,i) => { + if(isShow){ + item = item.replace(':', '='); + if (item.indexOf('${') > -1) { + if (item.split('=')[1].indexOf('.') > -1) { + if (options.sourceData.length < 1 || !options.sourceData.oid) { + isShow = false; + Vue.prototype.$message.error("璇峰厛閫夋嫨涓�鏉℃潵婧愭暟鎹�") + return false; + } + let name = item.split('=')[1].split('.')[1].replace('${', '').replace('}', ''); + initValues[item.split('=')[0]] = options.sourceData[name] + } else { + if (options.dataStore.length < 1) { + isShow = false; + Vue.prototype.$message.error("璇峰厛閫夋嫨涓�鏉℃暟鎹�"); + return false; + } + let name = item.split('=')[1].replace('${', '').replace('}', ''); + initValues[item.split('=')[0]] = options.dataStore[0][name]; + + } + } + } + }) + if(isShow){ + options.paramVOS['initvalue'] = initValues + } + } + if(!isShow){ + return; + } if(button.url && button.url!='null'){ //鏈夐厤缃產ction璺緞锛屼娇鐢ㄨ矾寰勫搴旂殑js @@ -117,7 +154,7 @@ * @param preEventName 鍓嶇疆浜嬩欢鍚嶇О锛岄粯璁eforeevent */ export const callPreEvent = (options,fnTarget,callback,preEventName) => { - let beforeEvent = options.paramVOS[preEventName || 'beforeevent']; + let beforeEvent = options.paramVOS[preEventName || 'prepvent']; if(beforeEvent) { let buttonParse = parseEventByUrl(beforeEvent,options,true); if(validatenull(buttonParse.jsPath)){ @@ -172,10 +209,10 @@ * @param isBefore 鏄惁涓哄墠缃簨浠讹紝鍚﹀垯涓哄悗缃� * @returns {{jsPath: js鐨勮矾寰�, options: 鎸夐挳鐨勯厤缃俊鎭�, methodName: (string)鏂规硶鐨勫悕瀛梷} */ -export const parseEventByUrl = (url,options,isBefore) => { +export const parseEventByUrl = (url,options,isBefore,defalutmethodName) => { //鏍规嵁閰嶇疆鏍煎紡鍖栦簨浠� let jsPath = url; - let methodName = isBefore?"doBefore":"doAfter"; + let methodName = defalutmethodName || (isBefore?"doBefore":"doAfter"); let params = {}; if (url.indexOf("?")) { let temp = url.substring(0, url.indexOf("?")); @@ -211,12 +248,21 @@ jsPath = url; } } + if(!options){ + options={ + paramVOS:{} + } + }else if(!options.paramVOS){ + options.paramVOS={} + } + for (var key in params) { options.paramVOS[key.toLowerCase()] = params[key]; } return { jsPath:jsPath, methodName:methodName, - options:options + options:options, + params:params }; }; diff --git a/Source/ProjectWeb/src/actions/base/EditAction.js b/Source/ProjectWeb/src/actions/base/EditAction.js index d79c171..6dbadff 100644 --- a/Source/ProjectWeb/src/actions/base/EditAction.js +++ b/Source/ProjectWeb/src/actions/base/EditAction.js @@ -7,7 +7,6 @@ import AddEditDialog from "@/components/actions/AddEditDialog"; export const doAction = (options) => { - options.paramVOS = paramLow(options.paramVOS) const paramVOS = Object.assign({ getdataurl: '/api/uiDataController/dataFormQuery', getdatamethod: 'post', diff --git a/Source/ProjectWeb/src/api/base/ui.js b/Source/ProjectWeb/src/api/base/ui.js index cf56537..7c451a8 100644 --- a/Source/ProjectWeb/src/api/base/ui.js +++ b/Source/ProjectWeb/src/api/base/ui.js @@ -70,7 +70,7 @@ //鏌ヨ琛ㄥ崟椤� export const getFormDefineById = (btmType,formId) => { return request({ - url: '/api/uiDataController/getFormDefineById', + url: '/api/webUIController/getFormDefineById', method: 'get', params: { btmType, diff --git a/Source/ProjectWeb/src/components/PLT-basic-component/basicForm.vue b/Source/ProjectWeb/src/components/PLT-basic-component/basicForm.vue index fd07194..c8c67c8 100644 --- a/Source/ProjectWeb/src/components/PLT-basic-component/basicForm.vue +++ b/Source/ProjectWeb/src/components/PLT-basic-component/basicForm.vue @@ -1,6 +1,6 @@ <template> <!--鍔ㄦ�佹ā鏉�--> - <avue-form ref="formRef" :option="option" v-model="form"> + <avue-form ref="form" :option="option" v-model="form"> <template v-for="item in allColumn" :slot="item.prop+ ''"> <vciWebRefer v-if="item.type === 'refer'" @@ -141,7 +141,7 @@ } } } - this.$emit("input", val); + this.$emit("getFormData", val); }, deep: true, immediate: true @@ -187,17 +187,26 @@ ? 24 : this.span, value: item.defaultValue, - dicData: type === 'select' ? item.dicData : item.dicUrl, display: !item.hidden, labelSuffix: item.suffix, suffixIcon: item.prefix, tip: item.tooltips, dictCode: item.comboxKey, - rules: this.isEdit?[{ + valueFormat: item.dateFormate || "yyyy-MM-dd HH:mm:ss", + format: item.dateFormate, + rules: this.isEdit?(type=="select" || type=="refer" || type=="date" || type=="datetime"?[{ + required: item.required, + message: `璇烽�夋嫨${item.text}!`, + trigger: "change" + },{ + required: item.required, + message: `璇烽�夋嫨${item.text}!`, + trigger: "submit" + }]:[{ required: item.required, message: `璇疯緭鍏�${item.text}!`, trigger: "blur" - }]:[] + }]):[] }; if(!this.isEdit){ col.placeholder=col.label; @@ -208,8 +217,16 @@ console.log('col',col) } if (col.type === "select") { - // console.log('col',col) - if(!validatenull(col.dictCode)) { + if(col.data && col.data.length>0){ + col.dicData = col.data.map((d) => { + return { + label: d.value, + key: d.key, + value: d.key, + attributes:d.attributes + }; + }); + }else if(!validatenull(col.dictCode)) { getDicts(col.dictCode).then((res) => { if (res.data.success){ if(res.data.data && res.data.obj == null){ @@ -283,6 +300,27 @@ } } } + }, + // 琛ㄥ崟鏍¢獙 + validate(done) { + return new Promise((resolve) => { + this.$refs.form.validate((valid,fields) => { + done(valid,fields); + if (valid) { + resolve(true); + this.ValidataValue = true; + } else { + resolve(false); + return false; + } + }); + }); + }, + resetFields(){ + this.$refs.form.resetFields() + }, + clearValidate(props){ + this.$refs.form.clearValidate(props) } }, }; diff --git a/Source/ProjectWeb/src/components/actions/AddEditDialog.vue b/Source/ProjectWeb/src/components/actions/AddEditDialog.vue index 3d288d5..11347ab 100644 --- a/Source/ProjectWeb/src/components/actions/AddEditDialog.vue +++ b/Source/ProjectWeb/src/components/actions/AddEditDialog.vue @@ -15,7 +15,8 @@ :style="fullscreen?'':'height:'+height" :isEdit="true" :formItems="formItems" - :formData="form"> + :formData="form" + @getFormData="getFormData"> </basic-form> <ui-view ref="uiViewRef" v-else-if="paramVOS.context" :key="'AddEditDialog-'+type" @@ -27,9 +28,11 @@ :sourceData="sourceData" :dataStore="dataStore" :paramVOS="paramVOS" + @getFormData="getFormData" ></ui-view> <div v-if="showSave" class="dialog-footer avue-dialog__footer"> - <el-button type="primary" plain size="small" @click="saveHandler">淇� 瀛�</el-button> + <el-button type="primary" plain size="small" @click="formSave" v-if="paramVOS.form">淇� 瀛�</el-button> + <el-button type="primary" plain size="small" @click="contextSave" v-else>淇� 瀛�</el-button> <el-button size="small" @click="dialogClose">鍙� 娑�</el-button> <el-button size="small" @click="resetValue" v-if="paramVOS.form">閲� 缃�</el-button> </div> @@ -38,6 +41,7 @@ <script> import uiView from "@/views/base/UIContentViewerInDialog" +import {parseEventByUrl} from "@/actions/base/BaseAction" import {getFormDefineById,dataForm} from "@/api/base/ui"; import {addSave,editSave} from "@/api/base/actions" import {validatenull} from "@/util/validate" @@ -68,7 +72,10 @@ showSave:this.paramVOS.customBtn || true, span:12, formItems:[], - form:{} + form:{}, + btmDefaultKeys : ['oid', 'id', 'name', 'description', 'revisionoid', 'nameoid', 'btmname', 'lastr', 'firstr', 'lastv', 'firstv', 'creator', 'createtime', 'lastModifier', 'lastmodifytime', 'revisionrule', 'revisionseq', 'revisionvalue', 'versionrule', 'versionseq', 'versionvalue', 'lcstatus', 'ts', 'owner', 'checkinby', 'checkintime', 'checkoutby', 'checkouttime', 'copyfromversion', 'secretgrade'], + linkDefaultKeys :['oid','creator','createtime','lastmodifier','lastmodifytime','f_oid','foid','f_revisionoid','frevisionoid','f_nameoid','fnameoid','f_btmname','fbtmname','t_oid','toid','t_revisionoid','trevisionoid','t_nameoid','tnameoid','t_btmname','tbtmname','ts'] + } }, computed:{ @@ -160,57 +167,97 @@ } }, - saveHandler() { - if(this.paramVOS.form){ - this.$refs.formRef.validate((valid, done) => { - if (valid) { - this.saveValue(this.form) - } else { - - } - }); - }else{ - //this.$refs.uiViewRef. - debugger; - if(this.saveCallback){ - this.saveCallback({}); - } + contextSave(){ + debugger; + if(this.saveCallback){ + this.saveCallback({}); } - }, - saveValue(savedata){ - if(this.type=="add"){ - addSave(savedata,this.paramVOS.url,this.paramVOS.method).then(() => { - this.$message({ + formSave() { + let that=this; + this.$refs.formRef.validate((valid, done) => { + if (valid) { + if (this.paramVOS.savebeforeevent) { + var urlobj = parseEventByUrl(this.paramVOS.savebeforeevent,null,null,'doAction'); + import("../"+urlobj.jsPath+".js").then(module => { + module[urlobj.methodName]({ + paramVOS: this.paramVOS, + dataStore: this.dataStore, + sourceData:this.sourceData + },that.formSaveHandle); + }) + } else { + that.formSaveHandle(); + } + } else { + return false; + } + }); + }, + formSaveHandle(){ + let that=this; + let formValues = this.getValues(); + if(formValues.otherValue.releaseFileOids){ + formValues.otherValue.releaseFileOids=formValues.otherValue.releaseFileOids.split(','); + } + if (!formValues.defaultValues.btmname) { + formValues.defaultValues.btmname = this.paramVOS.type; + } + let datas = { + formDefineId: this.paramVOS.form, + preEvent: this.paramVOS.preevent, + afterEvent: this.paramVOS.afterevent, + beforeServerEvent: this.paramVOS.beforeserverevent, + afterServerEvent: this.paramVOS.afterserverevent, + releaseFileOids: formValues.otherValue.releaseFileOids||[], + data: formValues.otherValue + } + Object.assign(datas, formValues.defaultValues); + if(that.type=="add"){ + addSave(datas,that.paramVOS.url,that.paramVOS.method).then(() => { + that.$message({ type: "success", message: "淇濆瓨鎴愬姛!" }); - if(this.saveCallback){ - this.saveCallback(savedata); + if(that.saveCallback){ + that.saveCallback(that.form); } - this.dialogClose(); - }).error((e) => { - this.$message.error(e||"淇濆瓨澶辫触") + that.dialogClose(); }); }else{ - editSave(savedata,this.paramVOS.url,this.paramVOS.method).then(() => { - this.$message({ + editSave(that.form,that.paramVOS.url,that.paramVOS.method).then(() => { + that.$message({ type: "success", message: "淇敼鎴愬姛!" }); - if(this.saveCallback){ - this.saveCallback(savedata); + if(that.saveCallback){ + that.saveCallback(that.form); } - this.dialogClose(); - }).error((e) => { - this.$message.error(e||"淇敼澶辫触") + that.dialogClose(); }); + } + }, + getValues(){ + let defaultValues = {}, otherValue = {}; + for (var key in this.form) { + if (this.btmDefaultKeys.indexOf(key.toLowerCase()) > -1) { + defaultValues[key] = this.form[key]; + } else { + otherValue[key] = this.form[key]; + } + } + return { + defaultValues:defaultValues, + otherValue:otherValue } }, resetValue() { if (this.paramVOS.form) { this.$refs.formRef.resetFields(); } + }, + getFormData(form) { + this.form = form; } } } diff --git a/Source/ProjectWeb/src/components/dynamic-components/dynamic-button.vue b/Source/ProjectWeb/src/components/dynamic-components/dynamic-button.vue index d8fd372..1341289 100644 --- a/Source/ProjectWeb/src/components/dynamic-components/dynamic-button.vue +++ b/Source/ProjectWeb/src/components/dynamic-components/dynamic-button.vue @@ -131,7 +131,7 @@ this.$refs.dynamicForm.form = row; }, buttonClick(buttonitem) { - const paramVOS=buttonitem.paramVOS; + const paramVOS = buttonitem.paramVOS; const DefineVO = this.componentVO.treeDefineVO || this.componentVO.tableDefineVO || this.componentVO.treeTableDefineVO || this.componentVO.formDefineVO; if (!paramVOS['title']) { paramVOS['title'] = buttonitem.name + (DefineVO.title || this.componentVO.description || ''); @@ -140,59 +140,24 @@ if (!paramVOS['type']) { paramVOS['type'] = DefineVO.btmType; } - paramVOS['initvalue']=paramVOS['initvalue'] || paramVOS['initValue']; - let isShow = true; - if (paramVOS['initvalue'] && typeof(paramVOS.initvalue)=='string') { - let values = paramVOS['initvalue'].split(';'); - let initValues = {} - values.forEach((item,i) => { - if(isShow){ - item = item.replace(':', '='); - if (item.indexOf('${') > -1) { - if (item.split('=')[1].indexOf('.') > -1) { - if (this.sourceData.length < 1 || !this.sourceData.oid) { - isShow = false; - this.$message.error("璇峰厛閫夋嫨涓�鏉℃潵婧愭暟鎹�") - return false; - } - let name = item.split('=')[1].split('.')[1].replace('${', '').replace('}', ''); - initValues[item.split('=')[0]] = this.sourceData[name] - } else { - if (this.dataStore.length < 1) { - isShow = false; - this.$message.error("璇峰厛閫夋嫨涓�鏉℃暟鎹�"); - return false; - } - let name = item.split('=')[1].replace('${', '').replace('}', ''); - initValues[item.split('=')[0]] = this.dataStore[0][name]; - } - } - } - }) - if(isShow){ - paramVOS['initvalue'] = initValues + if (paramVOS['BSContent'] || paramVOS['BSContext']) { + paramVOS['context'] = paramVOS['BSContext'] || paramVOS['BSContent'] + paramVOS['content'] = paramVOS['BSContext'] || paramVOS['BSContent']; + } + + const that = this; + //paramVOS.customBtn //寮圭獥榛樿鏈変繚瀛樻寜閽�,customBtn涓簍rue鏃跺唴瀹瑰睍绀鸿嚜瀹氫箟鎸夐挳 + paramVOS.form = "editknowledgefolderall" + doAction(buttonitem, { + paramVOS: paramVOS, + dataStore: this.dataStore || [], + sourceData: this.sourceData || {} + }, function () { + if (that.$parent.handleRefresh) { + that.$parent.handleRefresh() } - } - if(paramVOS['BSContent'] || paramVOS['BSContext']){ - paramVOS['context']=paramVOS['BSContext'] || paramVOS['BSContent'] - paramVOS['content']=paramVOS['BSContext'] || paramVOS['BSContent']; - } - - const that=this; - if(isShow) { - //paramVOS.customBtn //寮圭獥榛樿鏈変繚瀛樻寜閽�,customBtn涓簍rue鏃跺唴瀹瑰睍绀鸿嚜瀹氫箟鎸夐挳 - //paramVOS.form="editknowledgefolderall" - doAction(buttonitem, { - paramVOS: paramVOS, - dataStore: this.dataStore || [], - sourceData: this.sourceData || {} - },function (){ - if (that.$parent.handleRefresh) { - that.$parent.handleRefresh() - } - }); - } + }); } }, } diff --git a/Source/ProjectWeb/src/components/dynamic-components/dynamic-form.vue b/Source/ProjectWeb/src/components/dynamic-components/dynamic-form.vue index 15fd7f1..91f77bb 100644 --- a/Source/ProjectWeb/src/components/dynamic-components/dynamic-form.vue +++ b/Source/ProjectWeb/src/components/dynamic-components/dynamic-form.vue @@ -7,7 +7,8 @@ :formItems="this.componentVO.formDefineVO && this.componentVO.formDefineVO.items" :disabled="!inDialog" :isEdit="canEdit" - :formData="form"> + :formData="form" + @getFormData="getFormData"> </basic-form> </div> </template> @@ -162,6 +163,9 @@ handleRefresh() { this.form={} this.onLoad(); + }, + getFormData(form) { + this.form = form; } } } -- Gitblit v1.9.3