wangting
2024-04-30 f5f8aaedd1d488fb20a293182dd7a40e2e82096e
Source/ProjectWeb/src/actions/base/BaseAction.js
@@ -8,14 +8,50 @@
/**
 * 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(':', '=');
        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'){
    //有配置action路径,使用路径对应的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 +60,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 +154,14 @@
 * @param preEventName 前置事件名称,默认beforeevent
 */
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) {
@@ -153,7 +189,7 @@
      fnTarget(buttonParse,callback);
    }else{
      try {
        import("../"+buttonParse.jsPath).then(module => {
        import("../"+buttonParse.jsPath+".js").then(module => {
          module[buttonParse.methodName](options,callback);
        })
      } catch (error) {
@@ -173,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("?"));
@@ -212,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
  };
};