Quellcode durchsuchen

累进接口更改

vian vor 5 Jahren
Ursprung
Commit
2630c40424
1 geänderte Dateien mit 20 neuen und 6 gelöschten Zeilen
  1. 20 6
      public/calculate_util.js

+ 20 - 6
public/calculate_util.js

@@ -114,25 +114,39 @@
     }
 
     /**
-     * 判断该基数是否包含累进基数
+     * 该基数包含累进基数
      * @param {String} calcBase - 计算基数
      * @param {Array} progression - 累进基数名称数组
-     * @return {Boolean}
+     * @return {Array}
      */
-    function isProgressive(calcBase, progression) {
+    function getProgressive(calcBase, progression) {
         if (typeof calcBase !== 'string' || !progression) {
-            return false;
+            return [];
         }
         const reg = /{[^}]+}/g;
         const matched = calcBase.match(reg);
         if (!matched) {
-            return false;
+            return [];
         }
-        return matched.some(mStr => progression.some(pStr => `{${pStr}}` === mStr));
+        return matched
+            .filter(mStr => progression.some(pStr => `{${pStr}}` === mStr))
+            .map(mStr => mStr.replace(/[{}]/g, ''));
+    }
+
+    /**
+     * 该基数是否含有累进基数
+     * @param {String} calcBase - 计算基数
+     * @param {Array} progression - 累进基数名称数组
+     * @return {Boolean}
+     */
+    function isProgressive(calcBase, progression) {
+        const progressiveBase = getProgressive(calcBase, progression);
+        return !!progressiveBase.length;
     }
 
     return {
         getProgressiveFee,
         isProgressive,
+        getProgressive,
     };
 });