Explorar o código

台账分解,导入Excel数据,过滤回车换行符

MaiXinRong %!s(int64=6) %!d(string=hai) anos
pai
achega
ee5a38cfa3
Modificáronse 2 ficheiros con 31 adicións e 12 borrados
  1. 19 0
      app/extend/helper.js
  2. 12 12
      app/lib/analysis_excel.js

+ 19 - 0
app/extend/helper.js

@@ -660,4 +660,23 @@ module.exports = {
         }
         return result;
     },
+
+    /**
+     * 使用正则替换字符
+     * @param str
+     * @param reg
+     * @param subStr
+     * @returns {*}
+     */
+    replaceStr(str, reg, subStr) {
+        return str ? str.replace(reg, subStr) : str;
+    },
+    /**
+     * 替换字符串中的 换行符回车符
+     * @param str
+     * @returns {*}
+     */
+    replaceReturn(str) {
+        return str ? str.replace(/[\r\n]/g, '') : str;
+    }
 };

+ 12 - 12
app/lib/analysis_excel.js

@@ -270,16 +270,16 @@ class AnalysisExcelTree {
      */
     _loadXmjNode(row) {
         const node = {};
-        node.code = row[this.colsDef.code];
-        node.name = row[this.colsDef.name];
-        node.unit = row[this.colsDef.unit];
+        node.code = this.ctx.helper.replaceReturn(row[this.colsDef.code]);
+        node.name = this.ctx.helper.replaceReturn(row[this.colsDef.name]);
+        node.unit = this.ctx.helper.replaceReturn(row[this.colsDef.unit]);
         const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, node.unit);
         node.sgfh_qty = this.ctx.helper.round(this.toNumber(row[this.colsDef.sgfh_qty]), precision.value);
         node.dgn_qty1 = this.toNumber(row[this.colsDef.dgn_qty1]);
         node.dgn_qty2 = this.toNumber(row[this.colsDef.dgn_qty2]);
         node.unit_price = this.toNumber(row[this.colsDef.unit_price]);
-        node.drawing_code = row[this.colsDef.drawing_code];
-        node.memo = row[this.colsDef.memo];
+        node.drawing_code = this.ctx.helper.replaceReturn(row[this.colsDef.drawing_code]);
+        node.memo = this.ctx.helper.replaceReturn(row[this.colsDef.memo]);
         // if (node.sgfh_qty && node.unit_price) {
         //     node.sgfh_tp = this.ctx.helper.round(this.ctx.helper.mul(node.sgfh_qty, node.unit_price), this.ctx.tender.info.decimal.tp);
         // } else {
@@ -308,14 +308,14 @@ class AnalysisExcelTree {
      */
     _loadGclNode(row) {
         const node = {};
-        node.b_code = row[this.colsDef.b_code];
-        node.name = row[this.colsDef.name];
-        node.unit = row[this.colsDef.unit];
+        node.b_code = this.ctx.helper.replaceReturn(row[this.colsDef.b_code]);
+        node.name = this.ctx.helper.replaceReturn(row[this.colsDef.name]);
+        node.unit = this.ctx.helper.replaceReturn(row[this.colsDef.unit]);
         const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, node.unit);
         node.sgfh_qty = this.ctx.helper.round(this.toNumber(row[this.colsDef.sgfh_qty]), precision.value);
         node.unit_price = this.toNumber(row[this.colsDef.unit_price]);
-        node.drawing_code = row[this.colsDef.drawing_code];
-        node.memo = row[this.colsDef.memo];
+        node.drawing_code = this.ctx.helper.replaceReturn(row[this.colsDef.drawing_code]);
+        node.memo = this.ctx.helper.replaceReturn(row[this.colsDef.memo]);
         // if (node.sgfh_qty && node.unit_price) {
         //     node.sgfh_tp = this.ctx.helper.round(this.ctx.helper.mul(node.sgfh_qty, node.unit_price), this.ctx.tender.info.decimal.tp);
         // } else {
@@ -344,9 +344,9 @@ class AnalysisExcelTree {
      */
     _loadPos(row) {
         const pos = {};
-        pos.name = row[this.colsDef.name];
+        pos.name = this.ctx.helper.replaceReturn(row[this.colsDef.name]);
         pos.sgfh_qty = this.toNumber(row[this.colsDef.sgfh_qty]);
-        pos.drawing_code = row[this.colsDef.drawing_code];
+        pos.drawing_code = this.ctx.helper.replaceReturn(row[this.colsDef.drawing_code]);
         return this.cacheTree.addPos(pos);
     }