Pārlūkot izejas kodu

加取指标值新方法(split)

TonyKang 5 gadi atpakaļ
vecāks
revīzija
5b935ce504
1 mainītis faili ar 16 papildinājumiem un 0 dzēšanām
  1. 16 0
      app/reports/util/rpt_calculation_data_util.js

+ 16 - 0
app/reports/util/rpt_calculation_data_util.js

@@ -666,6 +666,7 @@ function setupFunc(obj, ownRawObj, baseDir) {
     obj.myOwnRawDataObj = ownRawObj;
     obj.baseDir = baseDir;
     obj.getProperty = ext_getProperty;
+    obj.getSplitProperty = ext_getSplitProperty;
     obj.getPicProperty = ext_getPicProperty;
     // obj.getPropertyByForeignId = ext_getPropertyByForeignId;
     obj.getArrayProperty = ext_getArrayValues;
@@ -769,6 +770,21 @@ function ext_getProperty(dataKey, propKey) {
     return rst;
 }
 
+function ext_getSplitProperty(dataKey, propKey, splitChar, index, dftValue) {
+    const rst = ext_getProperty(dataKey, propKey);
+    for (let idx = 0; idx < rst.length; idx++) {
+        if (typeof rst[idx] === 'string') {
+            const splitArr = rst[idx].split(splitChar);
+            if (splitArr.length > index) {
+                rst[idx] = splitArr[index];
+            } else {
+                rst[idx] = dftValue;
+            }
+        }
+    }
+    return rst;
+}
+
 async function ext_getPicProperty(dataKey, propKey, isPath) {
     const rst = [];
     const parentObj = this;