From 46c673f0bf4a22ae108e90cfcf1bdeb4f0b6a45c Mon Sep 17 00:00:00 2001
From: wangting <675591594@qq.com>
Date: 星期二, 07 五月 2024 17:48:19 +0800
Subject: [PATCH] 添加action,数据联动

---
 Source/ProjectWeb/src/actions/base/BaseAction.js |   88 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 71 insertions(+), 17 deletions(-)

diff --git a/Source/ProjectWeb/src/actions/base/BaseAction.js b/Source/ProjectWeb/src/actions/base/BaseAction.js
index 0e9b377..6fbbc0b 100644
--- a/Source/ProjectWeb/src/actions/base/BaseAction.js
+++ b/Source/ProjectWeb/src/actions/base/BaseAction.js
@@ -8,14 +8,59 @@
 /**
  * action閫氱敤鍏ュ彛
  */
-export const doAction = (button,options) => {
+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(':', '=');
+        debugger;
+        if (item.indexOf('${') > -1) {
+          if (item.split('=')[1].indexOf('.') > -1) {
+            //initvaluenull=true鍏佽鍒濆鍊间负绌�
+            if ((options.sourceData.length < 1 || !options.sourceData.oid) && options.paramVOS['initvaluenull']!=true && options.paramVOS['initvaluenull']!="true") {
+              isShow = false;
+              Vue.prototype.$message.error("璇峰厛閫夋嫨涓�鏉℃潵婧愭暟鎹�")
+              return false;
+            }
+            let name = item.split('=')[1].split('.')[1].replace('${', '').replace('}', '');
+            if(options.sourceData){
+              initValues[item.split('=')[0]] = options.sourceData[name]
+            }else {
+              initValues[item.split('=')[0]]=""
+            }
+          } else {
+            if (options.dataStore.length < 1 && options.paramVOS['initvaluenull'] != true && options.paramVOS['initvaluenull'] != "true") {
+              isShow = false;
+              Vue.prototype.$message.error("璇峰厛閫夋嫨涓�鏉℃暟鎹�");
+              return false;
+            }
+            let name = item.split('=')[1].replace('${', '').replace('}', '');
+            if (options.dataStore[0]) {
+              initValues[item.split('=')[0]] = options.dataStore[0][name];
+            } else {
+              initValues[item.split('=')[0]] = "";
+            }
+          }
+        }
+      }
+    })
+    if(isShow){
+      options.paramVOS['initvalue'] = initValues
+    }
+  }
+  if(!isShow){
+    return;
+  }
 
   if(button.url && button.url!='null'){
     //鏈夐厤缃產ction璺緞锛屼娇鐢ㄨ矾寰勫搴旂殑js
-    let buttonParse = parseEventByUrl(button.url,options,false);
-    import("../"+buttonParse.jsPath+".js").then(module => {
-      module.doAction(options);
+    import("../"+button.url+".js").then(module => {
+      module.doAction(options,callback);
     })
   }else {
     //閫氱敤action
@@ -24,15 +69,15 @@
       view: () => {},
       //鍒涘缓
       add: () => {import("@/actions/base/AddAction").then(module => {
-        module.doAction(options);
+        module.doAction(options,callback);
       })},
       //淇敼
       edit: () =>  {import("@/actions/base/EditAction").then(module => {
-        module.doAction(options);
+        module.doAction(options,callback);
       })},
       //鍒犻櫎
       delete: () =>  {import("@/actions/base/DeleteAction").then(module => {
-        module.doAction(options);
+        module.doAction(options,callback);
       })},
     };
     if(validatenull(options.paramVOS.context)) {
@@ -118,14 +163,14 @@
  * @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)){
       fnTarget(buttonParse,callback);
     }else{
       try {
-        import("../"+buttonParse.jsPath).then(module => {
+        import("../"+buttonParse.jsPath+".js").then(module => {
           module[buttonParse.methodName](options,callback);
         })
       } catch (error) {
@@ -145,16 +190,16 @@
  * @param callback 鍥炶皟锛屽鏋滃瓨鍦ㄥ悗缃簨浠讹紝浼氬湪鎵ц瀹屾垚鍚庢墽琛屽洖璋冿紝鍚﹀垯鐩存帴鍥炶皟
  * @param preEventName 鍚庣疆浜嬩欢鍚嶇О锛岄粯璁� afterevent
  */
-export const callPostEvent = (options,fnTarget,callback,postEventName)=>{
+export const callPostEvent = (options,fnTarget,callback,actionType,postEventName)=>{
   let afterEvent = options.paramVOS[postEventName || 'afterevent'];
   if(afterEvent) {
     let buttonParse = parseEventByUrl(afterEvent,options,false);
     if(validatenull(buttonParse.jsPath)){
-      fnTarget(buttonParse,callback);
+      fnTarget(buttonParse,callback,actionType);
     }else{
       try {
-        import("../"+buttonParse.jsPath).then(module => {
-          module[buttonParse.methodName](options,callback);
+        import("../"+buttonParse.jsPath+".js").then(module => {
+          module[buttonParse.methodName](options,callback,actionType);
         })
       } catch (error) {
         Vue.prototype.$message.error('鏈壘鍒板悗缃簨浠舵墽琛宩s');
@@ -162,7 +207,7 @@
     }
   }else{
     if(callback){
-      callback(options);
+      callback(actionType);
     }
   }
 };
@@ -173,10 +218,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("?"));
@@ -212,12 +257,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
   };
 };

--
Gitblit v1.9.3