瀏覽代碼

Merge branch 'master' of http://192.168.1.41:3000/SmartCost/ConstructionCost

chenshilong 5 年之前
父節點
當前提交
968b1c1b78

+ 31 - 26
modules/main/controllers/project_controller.js

@@ -209,43 +209,48 @@ module.exports = {
         }
         res.json(result);
     },
-    getDecodedStr: async function(req, res) {
-        /* const data = JSON.parse(req.body.data);
-        const unit8ArraySouces = data.unit8ArraySouces;
+    getDecodedData: async function(req, res) {
+        const responseData = {
+            err: 0,
+            msg: '',
+            data: null
+        };
         try {
-
+            const { unit8ArraySouces, encoding } = JSON.parse(req.body.data);
+            responseData.data = unit8ArraySouces.map(unit8ArraySrc => {
+                const buffer = toArrayBuffer(unit8ArraySrc);
+                return iconv.decode(Buffer.from(buffer), encoding);
+            });;
         } catch (err) {
-            
-        } */
+            responseData.err = 1;
+            responseData.msg = typeof error === 'object' ? '解码失败' : error;
+        } finally {
+            res.json(responseData);
+        }
+
         function toArrayBuffer(src) {
-            var ab = new ArrayBuffer(src.length);
-            var view = new Uint8Array(ab);
-            for (var i = 0; i < src.length; ++i) {
+            const ab = new ArrayBuffer(src.length);
+            const view = new Uint8Array(ab);
+            for (let i = 0; i < src.length; i++) {
                 view[i] = +src[i];
             }
             return ab;
         }
+    },
+    getEncodedData: async function(req, res) {
         const responseData = {
             err: 0,
             msg: '',
             data: null
         };
-
-        const form = new multiparty.Form();
-        form.parse(req, async function(err, fields, files) {
-            try{
-                const unit8ArrayList = JSON.parse(fields.blobList[0]);
-                unit8ArrayList.forEach(unit8ArrayNumbers => {
-                    const buffer = toArrayBuffer(unit8ArrayNumbers);
-                    const str = iconv.decode(Buffer.from(buffer), 'gbk');
-                });
-            }
-            catch (error){
-                responseData.err = 1;
-                responseData.msg = typeof error === 'object' ? '文件名编码失败' : error;
-                res.json(responseData);
-            }
-
-        });
+        try {
+            const { str, encoding } = JSON.parse(req.body.data);
+            responseData.data = iconv.encode(str, encoding);
+        } catch (err) {
+            responseData.err = 1;
+            responseData.msg = typeof error === 'object' ? '编码失败' : error;
+        } finally {
+            res.json(responseData);
+        }
     }
 };

+ 2 - 1
modules/main/routes/project_route.js

@@ -19,7 +19,8 @@ module.exports = function (app) {
     projectRouter.post('/getDefaultColSetting', projectController.getDefaultColSetting);
     projectRouter.post('/getSEIProjects', projectController.getSEIProjects);
     projectRouter.post('/loadSEIProjectData', projectController.loadSEIProjectData);
-    projectRouter.post('/getDecodedStr', projectController.getDecodedStr);
+    projectRouter.post('/getDecodedData', projectController.getDecodedData);
+    projectRouter.post('/getEncodedData', projectController.getEncodedData);
     app.use('/project',projectRouter);
 };
 

+ 11 - 1
web/building_saas/main/js/models/exportStdInterfaceBase.js

@@ -854,6 +854,15 @@ const XML_EXPORT_BASE = (() => {
         return infos;
     }
 
+    /**
+     * 根据编码方式获取编码数据
+     * @param {String} str - 字符串数组数据源
+     * @param {String} encoding - 编码方式
+     */
+    async function getEncodedData(str, encoding) {
+        return await ajaxPost('/project/getEncodedData', { str, encoding });
+    }
+
     const UTIL = Object.freeze({
         deWeightHints,
         isDef,
@@ -883,7 +892,8 @@ const XML_EXPORT_BASE = (() => {
         getParsedData,
         setupCode,
         propertyCheck,
-        softCheck
+        softCheck,
+        getEncodedData,
     });
 
     // 开始标签

+ 9 - 24
web/building_saas/main/js/models/importStdInterfaceBase.js

@@ -289,29 +289,14 @@ const importXMLBase = (() => {
             { templateLibID });
     }
 
-    // 解码文件名
-    function getDecodedNames(bufferList) {
-        //const blobs = bufferList.map(buffer => new Blob([buffer]));
-        const formData = new FormData();
-        formData.append('blobList', JSON.stringify(bufferList));
-        return new Promise((resolve, reject) => {
-            $.ajax({
-                url: '/project/getDecodedStr',
-                type: 'POST',
-                data: formData,
-                cache: false,
-                contentType: false,
-                processData: false,
-                success: function(response){
-                    if (response.err === 0) {
-                        resolve(response.data);
-                    } else {
-                        reject(response.msg);
-                    }
-                },
-                error: reject
-            });
-        });
+    /**
+     * 根据编码内容解码数据
+     * @param {Array} unit8ArraySouces - unit8array的数据源
+     * @param {String} encoding - 编码方式
+     * @return {Promise Array}
+     */
+    async function getDecodedData(unit8ArraySouces, encoding) {
+        return await ajaxPost('/project/getDecodedData', { unit8ArraySouces, encoding });
     }
 
     const UTIL = Object.freeze({
@@ -329,7 +314,7 @@ const importXMLBase = (() => {
         getItemsRecur,
         extractItemsRecur,
         readAsTextSync,
-        getDecodedNames,
+        getDecodedData,
     });
 
     // 获取接受上传的文件类型正则表达式

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

@@ -360,7 +360,7 @@ const projTreeObj = {
                 return !selectedItem;
             },
             callback: function (key, opt) {
-                let selected = projTreeObj.tree.selected;
+                const selected = projTreeObj.tree.selected;
                 if (selected && selected.data.ID) {
                     SHARE_TO.initModal(selected.data.ID);
                 }

+ 1 - 1
web/common/components/share/index.js

@@ -180,7 +180,7 @@ const SHARE_TO = (() => {
                                                 <label class="custom-control-label" for="allow-copy">允许拷贝</label>
                                             </div>
                                             <div class="custom-control custom-checkbox">
-                                                <input type="checkbox" class="custom-control-input" id="allow-edit" checked="">
+                                                <input type="checkbox" class="custom-control-input" id="allow-edit">
                                                 <label class="custom-control-label" for="allow-edit">允许编辑</label>
                                             </div>
                                         </div>

+ 20 - 6
web/over_write/js/guangdong_2018_export.js

@@ -619,7 +619,7 @@ const XMLStandard = (function () {
                 },
                 // 招标单位编制时间
                 {
-                    name: 'TenderCompileDate', mustHasValue: true,
+                    name: 'TenderCompileDate', mustHasValue: true, required: true,
                     value: _util.getValueByKey(basicInformation, 'tenderCompileDate')
                 },
                 // 招标单位审核人
@@ -1580,7 +1580,7 @@ const XMLStandard = (function () {
                 // 工料机编码
                 { name: 'Number', value: glj.code },
                 // 消耗量
-                { name: 'Quantity', type: _type.DECIMAL, value: quantity },
+                { name: 'Quantity', type: _type.DECIMAL, value: (+quantity).toFixed(Decimal.GLJ) },
                 // 不计价材料
                 { name: 'NOCost', typ: _type.BOOL, value: noCost },
                 // 备注
@@ -1966,8 +1966,8 @@ const XMLStandard = (function () {
                 { name: 'Specification', value: glj.specs },
                 // 单位
                 { name: 'Unit', dName: '单位', required: true, value: glj.unit },
-                // 数量(总消耗量)
-                { name: 'Quantity', type: _type.DECIMAL, value: glj.quantity },
+                // 数量(总消耗量) 用toFixed来补零没问题,因为补的位数是大于计算取舍位数,不会有toFixed的精度问题(2.35.toFixed(2) = 2.3)
+                { name: 'Quantity', type: _type.DECIMAL, value: (+glj.quantity).toFixed(Decimal.GLJ) },
                 // 风险系数 从承包人主要材料设备-造价信息差额调整法读取,取不到则输出"0"
                 { name: 'ProviderRate', type: _type.DECIMAL, value: glj.riskCoe },
                 // 基准单价 从承包人主要材料设备-造价信息差额调整法读取,取不到则输出"0"
@@ -2135,7 +2135,7 @@ const XMLStandard = (function () {
             const systemInfo = new SystemInfo({
                 // 软件相关信息进行base64编码
                 ID1: Base64.encode(projectData.softInfo),
-                ID2: _util.generateHardwareId(),
+                ID2: Base64.encode(_util.generateHardwareId()),
                 makeDate: moment(Date.now()).format('YYYY-MM-DDTHH:mm:ss'),
             });
             // 工程信息
@@ -2376,7 +2376,7 @@ const XMLStandard = (function () {
                 .map(node => new UnitWorksSummaryItem(node));
             otherGroup.children.push(...otherChildren);
             // 除固定类别为“分部分项工程”、“措施项目”、“其他项目”以外的大项费用,通常无子项,所以显示到Item中。(即使造价书有子项,也显示到Item中,不再列出其子项数据)
-            const flags = [fixedFlag.SUB_ENGINERRING, fixedFlag.MEASURE, fixedFlag.OTEHER];
+            const flags = [fixedFlag.SUB_ENGINERRING, fixedFlag.MEASURE, fixedFlag.OTHER];
             const otherRoots = tenderDetail.mainTree.roots
                 .filter(node => !flags.includes(node.getFlag()))
                 .map(node => new UnitWorksSummaryItem(node));
@@ -2859,6 +2859,20 @@ const XMLStandard = (function () {
                 zip.file(file.fileName, file.blob, { binary: true });
             }
             const zipFile = await zip.generateAsync({ type: 'blob' });
+            // TODO
+            // 导出的文件名需要用gbk编码,否则广联达导入不了
+            /* debugger;
+            const zipFile = await zip.generateAsync({
+                type: 'uint8array',
+                encodeFileName: async function (string) {
+                    if (!string) {
+                        return string;
+                    }
+                    await _util.setTimeoutSync(() => { }, 300);
+                    const encodedStr = await _util.getEncodedData(string, 'gbk');
+                    return encodedStr;
+                }
+            }); */
             const exportKindName = _config.EXPORT_KIND_NAME[exportKind];
             saveAs(zipFile, `广东标准交换数据(${exportKindName}).COS`);
         }

+ 11 - 4
web/over_write/js/guangdong_2018_import.js

@@ -1541,9 +1541,8 @@ const importXML = (() => {
      */
     async function unzipFile(file) {
         const jsZip = new JSZip();
-        const zip = await jsZip.loadAsync(file);
-        // TODO
-        /* const fileNameByteList = [];
+        // 广联达导出的cos文件,内部文件的文件名是gbk编码,如果不处理的话无法导入
+        const fileNameByteList = [];
         let index = 0;
         const zip = await jsZip.loadAsync(file, {
             // zip文件中有一个标志,用于说明文件名和注释是否使用UTF-8编码。 
@@ -1558,7 +1557,15 @@ const importXML = (() => {
                 }
             }
         });
-        const decodedNames = await util.getDecodedNames(fileNameByteList); */
+        const decodedNames = await util.getDecodedData(fileNameByteList, 'gbk');
+        // 将zip里的文件名替换成gbk解码后的名称
+        decodedNames.forEach((name, index) => {
+            if (zip.files[index]) {
+                zip.files[index].name = name;
+                zip.files[name] = zip.files[index];
+                delete zip.files[index];
+            }
+        })
         const map = {};
         for (const fileName in zip.files) {
             // 将二进制数据转换成字符串