From a9bbbe822377536e6f3374b05e2b64b12b2f188c Mon Sep 17 00:00:00 2001
From: wangting <675591594@qq.com>
Date: 星期一, 27 五月 2024 10:25:43 +0800
Subject: [PATCH] action文档

---
 Source/ProjectWeb/src/components/actions/AddEditDialog.vue |  276 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 245 insertions(+), 31 deletions(-)

diff --git a/Source/ProjectWeb/src/components/actions/AddEditDialog.vue b/Source/ProjectWeb/src/components/actions/AddEditDialog.vue
index cebbd0c..0ddfd45 100644
--- a/Source/ProjectWeb/src/components/actions/AddEditDialog.vue
+++ b/Source/ProjectWeb/src/components/actions/AddEditDialog.vue
@@ -1,26 +1,53 @@
 <template>
   <el-dialog v-dialogDrag
-             :title="paramVOS.title"
+             :title="title"
              :visible.sync="visible"
              :width="width"
-             :style="'height:'+height || 'auto'"
+             :fullscreen="fullscreen"
              :append-to-body="true"
-             class="avue-dialog avue-dialog--top"
+             top="0"
+             class="avue-dialog"
+             :destroy-on-close="true"
              @close="dialogClose">
-    dialog
-    <basic-form ref="formRef" v-if="paramVOS.form"></basic-form>
-    <ui-view ref="uiViewRef" v-else-if="paramVOS.content || paramVOS.context"></ui-view>
-    <div v-if="paramVOS.form" class="avue-dialog__footer">
-      <el-button type="primary" @click="saveHandler">淇� 瀛�</el-button>
-      <el-button @click="escHandler">鍙� 娑�</el-button>
-      <el-button @click="resetValue">閲� 缃�</el-button>
+    <basic-form ref="formRef" v-if="paramVOS.form"
+                :key="'dialog-'+paramVOS.form"
+                :span="span"
+                :style="fullscreen?'':'height:'+height"
+                :isEdit="true"
+                :formItems="formItems"
+                :formData="form"
+                :initValue="paramVOS.initvalue"
+                :uploadattachment="paramVOS.uploadattachment || false"
+                @getFormData="getFormData">
+    </basic-form>
+    <ui-view ref="uiViewRef" v-else-if="paramVOS.context"
+             :key="'AddEditDialog-'+type"
+             :style="fullscreen?'':'height:'+height"
+             :btmType="paramVOS.type"
+             :context="paramVOS.context"
+             :inDialog="true"
+             :canEdit="true"
+             :actionType="type"
+             :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="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>
   </el-dialog>
 </template>
 
 <script>
 import uiView from "@/views/base/UIContentViewerInDialog"
-import {dataForm} from "@/api/base/ui";
+import {parseEventByUrl} from "@/components/actions/base/BaseAction"
+import {getFormDefineById,dataForm} from "@/api/base/ui";
+import {addSave,editSave} from "@/api/base/actions"
+import {validatenull} from "@/util/validate"
 
 export default {
   name: "AddEditDialog",
@@ -39,50 +66,237 @@
     paramVOS: {
       type: Object,
       default: {}
-    },
-    width: {
-      type: String,
-      default:'70%'
-    },
-    height: {
-      type: String,
-      default:'500px'
-    },
+    }
   },
   data(){
     return {
-      visible:false
+      type:"add",
+      visible:false,
+      showSave:this.paramVOS.customBtn || true,
+      span:12,
+      formItems:[],
+      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:{
+    title(){
+      return this.paramVOS.title || (this.type=='add'?'娣诲姞':'淇敼')
+    },
+    width() {
+      if (!validatenull(this.paramVOS.width)) {
+        if (this.paramVOS.width.includes("px") || this.paramVOS.width.includes("%")) {
+          return this.paramVOS.width;
+        } else {
+          return this.paramVOS.width + "px";
+        }
+      } else {
+        return "60%";
+      }
+    },
+    height(){
+      if (!validatenull(this.paramVOS.height)) {
+        if (this.paramVOS.height.includes("px") || this.paramVOS.height.includes("%")) {
+          return this.paramVOS.height;
+        } else {
+          return this.paramVOS.height + "px";
+        }
+      } else {
+        return "auto"
+      }
+    },
+    fullscreen(){
+      if(this.paramVOS.width || this.paramVOS.height){
+        return false;
+      }else if(this.paramVOS.form){
+        return false;
+      }
+      return true;
+    }
   },
   created() {
-
+  },
+  watch: {
+    paramVOS: {
+      handler(val) {
+        if (this.paramVOS.form) {
+          this.onLoad();
+        }
+      },
+      deep: true,
+      immediate: true
+    },
   },
   methods: {
     dialogClose() {
       this.visible = false;
     },
     onLoad: function () {
-      if (Object.keys(this.sourceData).length > 0 && this.isShow) {
+      if (Object.keys(this.sourceData).length > 0) {
         this.loading = true;
-        dataForm(this.params).then(res => {
-          this.form = res.data.obj;
-          this.loading = false;
+        getFormDefineById(this.paramVOS.type,this.paramVOS.form).then(result => {
+          this.formItems=result.data.obj.items;
+          this.span=result.data.obj.columnOneRow?(24/result.data.obj.columnOneRow) : 12;
+          if (this.paramVOS.initvalue) {
+            this.form=this.paramVOS.initvalue;
+          }
+          if(this.type=="edit") {
+            //鍔犺浇琛ㄥ崟鏁版嵁
+            let sourceDataMap = {};
+            for (let i in this.sourceData) {
+              const item = this.sourceData[i]
+              if (item.constructor === Object) return;
+              sourceDataMap['sourceData["' + i + '"]'] = item;
+            }
+            dataForm(Object.assign({
+              btmname: this.paramVOS.type,
+              formDefineId: this.paramVOS.form,
+              oid: this.dataStore[0].oid
+            }, sourceDataMap), this.paramVOS.getdataurl, this.paramVOS.getdatamethod).then(res => {
+              this.form=res.data.obj;
+              this.loading = false;
+            }).catch(error => {
+              this.$message.error(error);
+              this.loading = false;
+            })
+          }
         }).catch(error => {
           this.$message.error(error);
           this.loading = false;
         });
+
       }
     },
-    saveHandler() {
-      this.dialogClose();
+    contextSave(){
+      const useDataType=this.paramVOS["useDataType"] || "form";//浣跨敤ui涓婁笅鏂囦腑鐨勫摢涓被鍨嬫暟鎹紝榛樿form銆傚�硷細form銆乼ree銆乼able銆乀reeTable
+      for(let key in this.$refs.uiViewRef.data){
+        if(this.$refs.uiViewRef.data[key].type== useDataType){
+          this.form=this.$refs.uiViewRef.data[key].data;
+          this.formDefineId=this.$refs.uiViewRef.data[key].DefineVO.id;
+          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
+              },this.formSaveHandle);
+            })
+          } else {
+            this.formSaveHandle();
+          }
+          return;
+        }
+      }
     },
-    escHandler() {
-      this.dialogClose();
+    formSave() {
+      let that=this;
+      this.$refs.formRef.validate((valid, done) => {
+        if (valid) {
+          this.formDefineId=this.paramVOS.form;
+          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.formDefineId,
+        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: that.paramVOS.successmsg||"淇濆瓨鎴愬姛!"
+          });
+          if(that.saveCallback){
+            that.saveCallback(that.type,that.form);
+          }
+          if (this.paramVOS.saveafterevent) {
+            let urlobj = parseEventByUrl(this.paramVOS.saveafterevent,null,null,'doAction');
+            import(`./${urlobj.jsPath}.js`).then(module => {
+              module[urlobj.methodName]({
+                paramVOS: this.paramVOS,
+                dataStore: this.dataStore,
+                sourceData:this.sourceData
+              });
+            })
+          }
+          that.dialogClose();
+        });
+      }else{
+        editSave(datas,that.paramVOS.url,that.paramVOS.method).then(() => {
+          that.$message({
+            type: "success",
+            message: that.paramVOS.successmsg||"淇敼鎴愬姛!"
+          });
+          if(that.saveCallback){
+            that.saveCallback(that.type,that.form);
+          }
+          if (this.paramVOS.saveafterevent) {
+            let urlobj = parseEventByUrl(this.paramVOS.saveafterevent,null,null,'doAction');
+            import(`./${urlobj.jsPath}.js`).then(module => {
+              module[urlobj.methodName]({
+                paramVOS: this.paramVOS,
+                dataStore: this.dataStore,
+                sourceData:this.sourceData
+              });
+            })
+          }
+          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() {
-      this.$refs.formRef.resetValue();
+      if (this.paramVOS.form) {
+        this.$refs.formRef.resetFields();
+      }
+    },
+    getFormData(form) {
+      this.form = form;
     }
   }
 }

--
Gitblit v1.9.3