Przeglądaj źródła

导入转义字符相关处理

zhongzewei 6 lat temu
rodzic
commit
aac72a907c

+ 1 - 1
web/building_saas/main/js/models/exportStandardInterface.js

@@ -1757,7 +1757,7 @@ const XMLStandard = (function () {
                             code: node.data.code,
                             code: node.data.code,
                             name: node.data.name,
                             name: node.data.name,
                             serviceContent: node.data.serviceContent,
                             serviceContent: node.data.serviceContent,
-                            calcBaseValue: node.data.calcBaseValue,
+                            calcBaseValue: node.data.calcBase,
                             feeRate: node.data.feeRate ? node.data.feeRate : 100,
                             feeRate: node.data.feeRate ? node.data.feeRate : 100,
                             fees: node.data.fees,
                             fees: node.data.fees,
                             remark: node.data.remark
                             remark: node.data.remark

+ 2 - 2
web/building_saas/main/js/models/exportStdInterfaceBase.js

@@ -129,10 +129,10 @@ const XML_EXPORT_BASE = (() => {
                 data.value = data.value.trim();
                 data.value = data.value.trim();
                 data.value = data.value.replace(/\s{1,}/g, ' ');
                 data.value = data.value.replace(/\s{1,}/g, ' ');
             }
             }
-            if (!data.value && !data.minLen && !data.enumeration) {  //值为空,且没有限制最小字符数,且没有限制值,则不需判断
+            /*if (!data.value && !data.minLen && !data.enumeration) {  //值为空,且没有限制最小字符数,且没有限制值,则不需判断
                 rst.filterAttrs.push(data);
                 rst.filterAttrs.push(data);
                 continue;
                 continue;
-            }
+            }*/
             let isFail = false,
             let isFail = false,
                 tempFail = '';
                 tempFail = '';
             if (data.minLen && data.value.length < data.minLen){
             if (data.minLen && data.value.length < data.minLen){

+ 35 - 1
web/building_saas/main/js/models/importStandardInterface.js

@@ -125,6 +125,36 @@ const ImportXML = (() => {
         info: 'priceInfo',  //造价信息差额调整法
         info: 'priceInfo',  //造价信息差额调整法
         coe: 'priceCoe'     //价格指数调整法
         coe: 'priceCoe'     //价格指数调整法
     };
     };
+    // xml转义字符
+    const XML_CHARS = {
+        '&#x0020;': 'escape{space}',
+        '&#x20;': 'escape{simpleSpace}',
+        '&#x0009;': 'escape{tab}',
+        '&#x9;': 'escape{simpleTab}',
+        '&#x000D;': 'escape{return}',
+        '&#xD;': 'escape{simpleReturn}',
+        '&#000A;': 'escape{newLine}',
+        '&#xA;': 'escape{simpleNewLine}',
+        '&lt;': 'escape{less}',
+        '&gt;': 'escape{greater}',
+        '&amp;': 'escape{and}',
+        '&quot;': 'escape{quot}',
+        '&apos;': 'escape{apos}'
+    };
+    // 避免转义字符进行转义。原文本中含有xml转义字符,转换为其他字符。
+    function escapeXMLChars(str) {
+        for (let [key, value] of Object.entries(XML_CHARS)) {
+            str = str.replace(new RegExp(key, 'g'), value);
+        }
+        return str;
+    }
+    // 还原避免字符为转义字符
+    function restoreXMLChars(str) {
+        for (let [key, value] of Object.entries(XML_CHARS)) {
+            str = str.replace(new RegExp(value, 'g'), key);
+        }
+        return str;
+    }
 
 
     //读取文件转换为utf-8编码的字符串
     //读取文件转换为utf-8编码的字符串
     function readAsTextSync(file) {
     function readAsTextSync(file) {
@@ -1307,12 +1337,16 @@ const ImportXML = (() => {
             }
             }
         }
         }
         //从xml文件中提取数据
         //从xml文件中提取数据
-        this.extractData = async (file) => {
+        this.extractData = async (file, escape) => {
             //将二进制文件转换成字符串
             //将二进制文件转换成字符串
             let xmlStr = await readAsTextSync(file);
             let xmlStr = await readAsTextSync(file);
             //将xml格式良好的字符串转换成对象
             //将xml格式良好的字符串转换成对象
             let x2js = new X2JS();
             let x2js = new X2JS();
+            if (escape) {
+                xmlStr = escapeXMLChars(xmlStr);
+            }
             let xmlObj = x2js.xml_str2json(xmlStr);
             let xmlObj = x2js.xml_str2json(xmlStr);
+            xmlObj = JSON.parse(restoreXMLChars(JSON.stringify(xmlObj)));
             if (!xmlObj) {
             if (!xmlObj) {
                 throw '无有效数据。';
                 throw '无有效数据。';
             }
             }

+ 1 - 1
web/building_saas/pm/js/pm_import.js

@@ -289,7 +289,7 @@ const importView = (() => {
                 //转换数据
                 //转换数据
                 importXML = new ImportXML();
                 importXML = new ImportXML();
                 try {
                 try {
-                    xmlObj = await importXML.extractData(file);
+                    xmlObj = await importXML.extractData(file, true);
                     $('.selFile input:eq(0)').val(xmlObj && xmlObj.name ? xmlObj.name : '');
                     $('.selFile input:eq(0)').val(xmlObj && xmlObj.name ? xmlObj.name : '');
                     $('.selFile input[name="fileKind-import"]:eq(0)').prop('checked', true);    //文件类型恢复成投标
                     $('.selFile input[name="fileKind-import"]:eq(0)').prop('checked', true);    //文件类型恢复成投标
                     $('#import-taxType').val('1');  //计税方法显示回默认的一般计税法
                     $('#import-taxType').val('1');  //计税方法显示回默认的一般计税法