wangting
2024-05-14 e330c3130c9eb0d7a10e1fe65885e5466263471e
Source/ProjectWeb/src/components/actions/base/BaseAction.js
@@ -1,5 +1,6 @@
import {validatenull} from "@/util/validate";
import Vue from 'vue';
import {handlers} from '../handlers';
/**
 * 按钮的基础服务
@@ -10,30 +11,30 @@
 */
export const doAction = (button,options,callback) => {
  options.paramVOS = paramLow(options.paramVOS)
  options.paramVOS['title']=replaceFreeMarker(options.paramVOS.title,options.dataStore,options.sourceData);
  options.paramVOS['title'] = replaceFreeMarker(options.paramVOS.title, options.dataStore, options.sourceData);
  let isShow = true;
  if (options.paramVOS['initvalue'] && typeof(options.paramVOS.initvalue)=='string') {
  if (options.paramVOS['initvalue'] && typeof (options.paramVOS.initvalue) == 'string') {
    let values = options.paramVOS['initvalue'].split(';');
    let initValues = {}
    values.forEach((item,i) => {
      if(isShow){
    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") {
            if ((options.sourceData.length < 1 || !options.sourceData.oid) && options.paramVOS['needselect'] != false && options.paramVOS['needselect'] != "false") {
              isShow = false;
              Vue.prototype.$message.error("请先选择一条来源数据")
              return false;
            }
            let name = item.split('=')[1].split('.')[1].replace('${', '').replace('}', '');
            if(options.sourceData){
            if (options.sourceData) {
              initValues[item.split('=')[0]] = options.sourceData[name]
            }else {
              initValues[item.split('=')[0]]=""
            } else {
              initValues[item.split('=')[0]] = ""
            }
          } else {
            if (options.dataStore.length < 1 && options.paramVOS['initvaluenull'] != true && options.paramVOS['initvaluenull'] != "true") {
            if (options.dataStore.length < 1 && options.paramVOS['needselect'] != false && options.paramVOS['needselect'] != "false") {
              isShow = false;
              Vue.prototype.$message.error("请先选择一条数据");
              return false;
@@ -48,52 +49,28 @@
        }
      }
    })
    if(isShow){
    if (isShow) {
      options.paramVOS['initvalue'] = initValues
    }
  }
  if(!isShow){
  if (!isShow) {
    return;
  }
  if(button.url && button.url!='null'){
  if (validatenull(options.paramVOS.context)) {
    options.paramVOS.context = options.paramVOS.content;
  }
  if (button.url && button.url != 'null') {
    //有配置action路径,使用路径对应的js
    import("../"+button.url+".js").then(module => {
      module.doAction(options,callback);
    import("../" + button.url + ".js").then(module => {
      module.doAction(options, callback);
    })
  }else {
    //通用action
    const handlers = {
      //查看
      view: () => {import("@/components/actions/base/TabViewAction").then(module => {
        module.doAction(options,callback);
      })},
      //创建
      add: () => {import("@/components/actions/base/AddAction").then(module => {
        module.doAction(options,callback);
      })},
      //修改
      edit: () =>  {import("@/components/actions/base/EditAction").then(module => {
        module.doAction(options,callback);
      })},
      //删除
      delete: () =>  {import("@/components/actions/base/DeleteAction").then(module => {
        module.doAction(options,callback);
      })},  //删除
      del: () =>  {import("@/components/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()]){
  } else {
    if (handlers[button.actionVO.id.toLowerCase()]) {
      handlers[button.actionVO.id.toLowerCase()]()
    }else{
    } else {
      Vue.prototype.$message.error('未找到对应action,请重新配置按钮!');
    }
  }
};