wangting
2024-04-11 bf00347a300c9b0d3c212ef3a41c2977a6b62193
action处理
已修改4个文件
173 ■■■■ 文件已修改
Source/ProjectWeb/src/actions/base/AddAction.js 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/actions/base/BaseAction.js 98 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/components/dynamic-components/dynamic-button.vue 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/views/base/UIContentArea.vue 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/actions/base/AddAction.js
@@ -1,4 +1,54 @@
/**
 * 按钮处理 业务类型新增
 */
import BaseAction from './BaseAction';
import {callPreEvent,callPostEvent} from './BaseAction';
import {validatenull} from "@/util/validate";
export const doAction = (options) => {
  let paramVOS = Object.assign({
    url: 'uiDataController/addSave',
    method: 'post',
    uploadFileUrl: 'vciFileUploadController/uploadFile'
  }, options.paramVOS)
  options.paramVOS = paramVOS;
  callPreEvent(options, doBefore,function (options) {
    doAdd(options, function () {
      callPostEvent(options,doAfter, options.callback);
    });
  });
};
/**
 * 执行
 * @param options 按钮的配置信息
 * @param callback 回调
 */
export const doAdd = (options,callback)=> {
  this.$message.success('执行增加');
  if(callback){
    callback(options);
  }
}
/**
 * 前置事件
 * @param options 按钮的配置信息
 * @param callback 回调
 */
export const doBefore = (options,callback)=> {
  this.$message.success('执行前置事件');
  if(callback){
    callback(options);
  }
}
/**
 * 后置事件
 * @param options 按钮的配置信息
 * @param callback 回调
 */
export const doAfter = (options,callback)=> {
  this.$message.success('执行后置事件');
  if(callback){
    callback(options);
  }
}
Source/ProjectWeb/src/actions/base/BaseAction.js
@@ -1,9 +1,36 @@
import {validatenull} from "@/util/validate";
import {findArray} from "@/util/util";
/**
 * 按钮的基础服务
 */
/**
 * action通用入口
 */
export const doAction = (button,options) => {
  debugger;
  if(button.url && button.url!='null'){
    let buttonParse = parseEventByUrl(button.url,options,false);
    import("../"+buttonParse.jsPath).then(module => {
      module.doAction(options);
    })
  }else {
    const handlers = {
      add: () => {import("@/actions/base/AddAction").then(module => {
        module.doAction(options);
      })},
      edit: () => {},
      delete: () => {},
    };
    if(handlers[button.actionVO.id]){
      handlers[button.actionVO.id]()
    }else{
      this.$message.error('未找到对应action,请重新配置按钮!');
    }
  }
};
/**
 * 替换文本中的${xxx}
@@ -28,7 +55,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 +63,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 +71,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 +97,26 @@
/**
 * 执行前置事件
 * @param options 按钮的配置信息,前置事件里配置的参数会替换这个里的参数的信息
 * @param buttonTarget 按钮js所在的对象
 * @param fnTarget 执行方法
 * @param callback 回调,如果存在前置事件,会在执行完成后执行回调,否则直接回调
 * @param preEventName 前置事件名称,默认beforeevent
 */
export const callPreEvent = (options,buttonTarget,callback,preEventName) => {
export const callPreEvent = (options,fnTarget,callback,preEventName) => {
  const params = paramLow(options.paramVOS);
  options.paramVOS = params;
  let beforeEvent = params[preEventName || 'beforeevent'];
  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).then(module => {
          module[buttonParse.methodName](options,callback);
        })
      } catch (error) {
        this.$message.error('未找到前置事件执行js');
      }
    }
  }else{
    if(callback){
@@ -95,22 +125,28 @@
  }
};
/**
 * 执行后置时间
 * 执行后置事件
 * @param options 按钮的配置信息,后置事件里配置的参数会替换这个里的参数的信息
 * @param buttonTarget 按钮Js所在的对象
 * @param fnTarget 执行方法
 * @param callback 回调,如果存在后置事件,会在执行完成后执行回调,否则直接回调
 * @param preEventName 后置事件名称,默认 afterevent
 */
export const callPostEvent = (options,buttonTarget,callback,postEventName)=>{
export const callPostEvent = (options,fnTarget,callback,postEventName)=>{
  const params = paramLow(options.paramVOS);
  options.paramVOS = params;
  var afterEvent = params[postEventName || 'afterevent'];
  let afterEvent = params[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).then(module => {
          module[buttonParse.methodName](options,callback);
        })
      } catch (error) {
        this.$message.error('未找到后置事件执行js');
      }
    }
  }else{
    if(callback){
@@ -127,13 +163,13 @@
 */
export const parseEventByUrl = (url,options,isBefore) => {
  //根据配置格式化事件
  var jsPath = url;
  var methodName = isBefore?"doBefore":"doAfter";
  var params = {};
  let jsPath = url;
  let methodName = 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 +179,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的方式");
        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{
Source/ProjectWeb/src/components/dynamic-components/dynamic-button.vue
@@ -56,6 +56,7 @@
<script>
import func from "@/util/func";
import {validatenull} from "@/util/validate";
import {doAction} from '@/actions/base/BaseAction';
export default {
  name: "dynamic-button",
@@ -278,18 +279,14 @@
      this.$refs.dynamicForm.form = row;
    },
    buttonClick(item) {
      // 根据 type 条件动态引入不同的JS文件,并传递 item this 参数
      if (this.type === 'table') {
        import('@/views/base/buttonTable').then(module => {
          const buttonClickTable = module.default;
          buttonClickTable.buttonClick(item,this);
        })
      } else if (this.type === 'form') {
        import('@/views/base/buttonForm').then(module => {
          const buttonClickForm = module.default;
          buttonClickForm.buttonClick(item,this);
        })
      }
      doAction(item,{
        paramVOS: item.paramVOS,
        dataStore: [],
        sourceData: {},
        callback: function (){
        }
      });
    }
  },
}
Source/ProjectWeb/src/views/base/UIContentArea.vue
@@ -179,6 +179,8 @@
      let newDisplayExpressionStr=displayExpressionStr.replace(/"\s*and\s*"/g,'" && "').replace(/"\s*AND\s*"/g,'" && "').replace(/"\s*or\s*"/g,'" || "').replace(/"\s*OR\s*"/g,'" || "');
      newDisplayExpressionStr=newDisplayExpressionStr.replace(/"\s*<>\s*"/g,'" != "').replace(/"\s*=\s*"/g,'" == "');
      newDisplayExpressionStr=newDisplayExpressionStr.replace(/"\$\{/g,'this.newSourceData.').replace(/\}"/g,'')
      const sandbox = {};
      if(eval('('+newDisplayExpressionStr+')')){
        checkdisplay=true;
      }