From 506b5b59e3899d8dd40a61cc8b9a575bbde3caaa Mon Sep 17 00:00:00 2001 From: wangting <675591594@qq.com> Date: 星期一, 06 五月 2024 18:24:33 +0800 Subject: [PATCH] 添加action --- Source/ProjectWeb/src/actions/base/BaseAction.js | 179 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 140 insertions(+), 39 deletions(-) diff --git a/Source/ProjectWeb/src/actions/base/BaseAction.js b/Source/ProjectWeb/src/actions/base/BaseAction.js index 528dbe4..c46ad97 100644 --- a/Source/ProjectWeb/src/actions/base/BaseAction.js +++ b/Source/ProjectWeb/src/actions/base/BaseAction.js @@ -1,9 +1,96 @@ import {validatenull} from "@/util/validate"; -import {findArray} from "@/util/util"; +import Vue from 'vue'; /** * 鎸夐挳鐨勫熀纭�鏈嶅姟 */ + +/** + * 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) { + //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 + import("../"+button.url+".js").then(module => { + module.doAction(options,callback); + }) + }else { + //閫氱敤action + const handlers = { + //鏌ョ湅 + view: () => {}, + //鍒涘缓 + add: () => {import("@/actions/base/AddAction").then(module => { + module.doAction(options,callback); + })}, + //淇敼 + edit: () => {import("@/actions/base/EditAction").then(module => { + module.doAction(options,callback); + })}, + //鍒犻櫎 + delete: () => {import("@/actions/base/DeleteAction").then(module => { + module.doAction(options,callback); + })}, + }; + if(validatenull(options.paramVOS.context)) { + options.paramVOS.context = options.paramVOS.content; + } + if(handlers[button.actionVO.id.toLowerCase()]){ + handlers[button.actionVO.id.toLowerCase()]() + }else{ + Vue.prototype.$message.error('鏈壘鍒板搴攁ction锛岃閲嶆柊閰嶇疆鎸夐挳锛�'); + } + } + +}; + /** * 鏇挎崲鏂囨湰涓殑${xxx} @@ -28,7 +115,7 @@ let temp = text.substring(0, text.indexOf(reg)); let field = text.substring(text.indexOf(reg) + reg.length, text.indexOf("}")); let end = text.substring(text.indexOf("}") + 1); - field = replaceData[field] || sourceData[field] || ''; + field = sourceData[field] || ''; text = temp + field + end; } reg = "sourceData.${"; @@ -36,7 +123,7 @@ let temp = text.substring(0, text.indexOf(reg)); let field = text.substring(text.indexOf(reg) + reg.length, text.indexOf("}")); let end = text.substring(text.indexOf("}") + 1); - field = replaceData[field] || sourceData[field] || ''; + field = sourceData[field] || ''; text = temp + field + end; } reg = "${"; @@ -44,7 +131,7 @@ let temp = text.substring(0, text.indexOf(reg)); let field = text.substring(text.indexOf(reg) + reg.length, text.indexOf("}")); let end = text.substring(text.indexOf("}") + 1); - field = replaceData[field] || sourceData[field] || ''; + field = replaceData[field] || ''; text = temp + field + end; } } @@ -70,23 +157,24 @@ /** * 鎵ц鍓嶇疆浜嬩欢 * @param options 鎸夐挳鐨勯厤缃俊鎭紝鍓嶇疆浜嬩欢閲岄厤缃殑鍙傛暟浼氭浛鎹㈣繖涓噷鐨勫弬鏁扮殑淇℃伅 - * @param buttonTarget 鎸夐挳js鎵�鍦ㄧ殑瀵硅薄 + * @param fnTarget 鎵ц鏂规硶 * @param callback 鍥炶皟锛屽鏋滃瓨鍦ㄥ墠缃簨浠讹紝浼氬湪鎵ц瀹屾垚鍚庢墽琛屽洖璋冿紝鍚﹀垯鐩存帴鍥炶皟 * @param preEventName 鍓嶇疆浜嬩欢鍚嶇О锛岄粯璁eforeevent */ -export const callPreEvent = (options,buttonTarget,callback,preEventName) => { - const params = paramLow(options.paramVOS); - options.paramVOS = params; - let beforeEvent = params[preEventName || 'beforeevent']; +export const callPreEvent = (options,fnTarget,callback,preEventName) => { + let beforeEvent = options.paramVOS[preEventName || 'prepvent']; if(beforeEvent) { let buttonParse = parseEventByUrl(beforeEvent,options,true); - buttonParse.options.callback = callback; - if(validatenull(buttonParse)){ - buttonTarget[buttonParse.methodName](buttonParse); + if(validatenull(buttonParse.jsPath)){ + fnTarget(buttonParse,callback); }else{ - layui.use(buttonParse.jsPath,function () { - layui[buttonParse.jsPath][buttonParse.methodName](options); - }); + try { + import("../"+buttonParse.jsPath+".js").then(module => { + module[buttonParse.methodName](options,callback); + }) + } catch (error) { + Vue.prototype.$message.error('鏈壘鍒板墠缃簨浠舵墽琛宩s'); + } } }else{ if(callback){ @@ -95,22 +183,26 @@ } }; /** - * 鎵ц鍚庣疆鏃堕棿 + * 鎵ц鍚庣疆浜嬩欢 * @param options 鎸夐挳鐨勯厤缃俊鎭紝鍚庣疆浜嬩欢閲岄厤缃殑鍙傛暟浼氭浛鎹㈣繖涓噷鐨勫弬鏁扮殑淇℃伅 - * @param buttonTarget 鎸夐挳Js鎵�鍦ㄧ殑瀵硅薄 + * @param fnTarget 鎵ц鏂规硶 + * @param callback 鍥炶皟锛屽鏋滃瓨鍦ㄥ悗缃簨浠讹紝浼氬湪鎵ц瀹屾垚鍚庢墽琛屽洖璋冿紝鍚﹀垯鐩存帴鍥炶皟 + * @param preEventName 鍚庣疆浜嬩欢鍚嶇О锛岄粯璁� afterevent */ -export const callPostEvent = (options,buttonTarget,callback,postEventName)=>{ - const params = paramLow(options.paramVOS); - options.paramVOS = params; - var afterEvent = params[postEventName || 'afterevent']; +export const callPostEvent = (options,fnTarget,callback,postEventName)=>{ + let afterEvent = options.paramVOS[postEventName || 'afterevent']; if(afterEvent) { - var buttonParse = parseEventByUrl(afterEvent,options,false); - if(validatenull(buttonParse)){ - buttonTarget[buttonParse.methodName](buttonParse); + let buttonParse = parseEventByUrl(afterEvent,options,false); + if(validatenull(buttonParse.jsPath)){ + fnTarget(buttonParse,callback); }else{ - layui.use(buttonParse.jsPath,function () { - layui[buttonParse.jsPath][buttonParse.methodName](options); - }); + try { + import("../"+buttonParse.jsPath+".js").then(module => { + module[buttonParse.methodName](options,callback); + }) + } catch (error) { + Vue.prototype.$message.error('鏈壘鍒板悗缃簨浠舵墽琛宩s'); + } } }else{ if(callback){ @@ -125,15 +217,15 @@ * @param isBefore 鏄惁涓哄墠缃簨浠讹紝鍚﹀垯涓哄悗缃� * @returns {{jsPath: js鐨勮矾寰�, options: 鎸夐挳鐨勯厤缃俊鎭�, methodName: (string)鏂规硶鐨勫悕瀛梷} */ -export const parseEventByUrl = (url,options,isBefore) => { +export const parseEventByUrl = (url,options,isBefore,defalutmethodName) => { //鏍规嵁閰嶇疆鏍煎紡鍖栦簨浠� - var jsPath = url; - var methodName = isBefore?"doBefore":"doAfter"; - var params = {}; + let jsPath = url; + let methodName = defalutmethodName || (isBefore?"doBefore":"doAfter"); + let params = {}; if (url.indexOf("?")) { - var temp = url.substring(0, url.indexOf("?")); + let temp = url.substring(0, url.indexOf("?")); if (temp.indexOf("#") > -1) { - var array = temp.split("#"); + let array = temp.split("#"); if(array.length == 1){ jsPath = array[0]; }else{ @@ -143,17 +235,17 @@ }else{ jsPath = temp; } - var paramArray = url.substring(url.indexOf("?") + 1).split("&"); - layui.each(paramArray, function (_index, _item) { + let paramArray = url.substring(url.indexOf("?") + 1).split("&"); + paramArray.forEach(_item=>{ if (_item.indexOf("=") < 0) { - this.$message.error(isBefore?"鍓嶇疆浜嬩欢":"鍚庣疆浜嬩欢" + "鐨勫弬鏁伴厤缃敊璇紝闇�瑕佽xxx=yyy&zzz=a鐨勬柟寮�"); + Vue.prototype.$message.error(isBefore?"鍓嶇疆浜嬩欢":"鍚庣疆浜嬩欢" + "鐨勫弬鏁伴厤缃敊璇紝闇�瑕佽xxx=yyy&zzz=a鐨勬柟寮�"); return true; } params[_item.split("=")[0]] = _item.split("=")[1]; - }); + }) }else{ if (url.indexOf("#") > -1) { - var array = url.split("#"); + let array = url.split("#"); if(array.length == 1){ jsPath = array[0]; }else{ @@ -164,12 +256,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