wangting
2024-04-26 c4d9e7a20dac267c5496ad3586c5053be279a17a
Source/ProjectWeb/src/actions/base/BaseAction.js
@@ -1,4 +1,5 @@
import {validatenull} from "@/util/validate";
import Vue from 'vue';
/**
 * 按钮的基础服务
@@ -7,25 +8,39 @@
/**
 * action通用入口
 */
export const doAction = (button,options) => {
  debugger;
export const doAction = (button,options,callback) => {
  options.paramVOS['title']=replaceFreeMarker(options.paramVOS.title,options.dataStore,options.sourceData);
  if(button.url && button.url!='null'){
    let buttonParse = parseEventByUrl(button.url,options,false);
    import("../"+buttonParse.jsPath).then(module => {
      module.doAction(options);
    //有配置action路径,使用路径对应的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);
        module.doAction(options,callback);
      })},
      edit: () => {},
      delete: () => {},
      //修改
      edit: () =>  {import("@/actions/base/EditAction").then(module => {
        module.doAction(options,callback);
      })},
      //删除
      delete: () =>  {import("@/actions/base/DeleteAction").then(module => {
        module.doAction(options,callback);
      })},
    };
    if(handlers[button.actionVO.id]){
      handlers[button.actionVO.id]()
    if(validatenull(options.paramVOS.context)) {
      options.paramVOS.context = options.paramVOS.content;
    }
    if(handlers[button.actionVO.id.toLowerCase()]){
      handlers[button.actionVO.id.toLowerCase()]()
    }else{
      this.$message.error('未找到对应action,请重新配置按钮!');
      Vue.prototype.$message.error('未找到对应action,请重新配置按钮!');
    }
  }
@@ -102,20 +117,18 @@
 * @param preEventName 前置事件名称,默认beforeevent
 */
export const callPreEvent = (options,fnTarget,callback,preEventName) => {
  const params = paramLow(options.paramVOS);
  options.paramVOS = params;
  let beforeEvent = params[preEventName || 'beforeevent'];
  let beforeEvent = options.paramVOS[preEventName || 'beforeevent'];
  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) {
        this.$message.error('未找到前置事件执行js');
        Vue.prototype.$message.error('未找到前置事件执行js');
      }
    }
  }else{
@@ -132,20 +145,18 @@
 * @param preEventName 后置事件名称,默认 afterevent
 */
export const callPostEvent = (options,fnTarget,callback,postEventName)=>{
  const params = paramLow(options.paramVOS);
  options.paramVOS = params;
  let afterEvent = params[postEventName || 'afterevent'];
  let afterEvent = options.paramVOS[postEventName || 'afterevent'];
  if(afterEvent) {
    let buttonParse = parseEventByUrl(afterEvent,options,false);
    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) {
        this.$message.error('未找到后置事件执行js');
        Vue.prototype.$message.error('未找到后置事件执行js');
      }
    }
  }else{
@@ -182,7 +193,7 @@
    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];