ludc
2024-04-09 85c231f769f0167114d01e2588422a5dbc7353bb
Merge remote-tracking branch 'origin/master'
已添加2个文件
56 ■■■■■ 文件已修改
Source/ProjectWeb/src/actions/AddAction.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/actions/BaseAction.js 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/ProjectWeb/src/actions/AddAction.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,4 @@
/**
 * æŒ‰é’®å¤„理 ä¸šåŠ¡ç±»åž‹æ–°å¢ž
 */
import BaseAction from './BaseAction';
Source/ProjectWeb/src/actions/BaseAction.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,52 @@
import {validatenull} from "@/util/validate";
import {findArray} from "@/util/util";
/**
 * æŒ‰é’®çš„基础服务
 */
/**
 * æ›¿æ¢æ–‡æœ¬ä¸­çš„${xxx}
 * @param text æ–‡æœ¬
 * @param dataStore é€‰æ‹©çš„æ•°æ®
 * @param sourceData æ¥æºæ•°æ®
 * @returns æ›¿æ¢åŽçš„值,字符串
 */
export const replaceFreeMarker = (text,dataStore,sourceData) => {
  //替换表达式
  if (!sourceData) {
    sourceData = {};
  }
  if (!dataStore) {
    dataStore = [];
  }
  let replaceData = dataStore.length > 0 ? dataStore[0] : {};
  if (text && text.indexOf("${") > -1 && text.indexOf("}")) {
    //js只能使用${xxx}这种的方式
    let reg = "root.${";
    while (text.indexOf(reg) > -1) {
      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] || '';
      text = temp + field + end;
    }
    reg = "sourceData.${";
    while (text.indexOf(reg) > -1) {
      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] || '';
      text = temp + field + end;
    }
    reg = "${";
    while (text.indexOf(reg) > -1) {
      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] || '';
      text = temp + field + end;
    }
  }
  return text;
};