TonyKang 6 лет назад
Родитель
Сommit
64a8eef9a9

+ 94 - 0
modules/reports/rpt_component/jpc_flow_tab.js

@@ -819,6 +819,87 @@ JpcFlowTabSrv.prototype.createNew = function(){
         }
         return rst;
     };
+    JpcFlowTabResult.combinePageCells = function (rstPageCells, verticalCombinePos, horizonCombinePos) {
+        // let me = this;
+        if (verticalCombinePos.length > 0 || horizonCombinePos.length > 1) {
+            let cacheObj = {vCache:{}, hCache: {}, hCacheStr: []};
+            let removeCellIds = [];
+            for (let vPosArr of verticalCombinePos) {
+                let pStr = "_" + vPosArr[0] + "_" + vPosArr[1];
+                cacheObj.vCache[pStr] = [];
+            }
+            //horizonCombinePos不需要预记
+            for (let idx = 0; idx < rstPageCells.length; idx++) {
+                let cell = rstPageCells[idx];
+                for (let vPosArr of verticalCombinePos) {
+                    if (cell[JV.PROP_AREA][JV.PROP_LEFT] === vPosArr[0] && cell[JV.PROP_AREA][JV.PROP_RIGHT] === vPosArr[1]) {
+                        cacheObj.vCache["_" + vPosArr[0] + "_" + vPosArr[1]].push(idx);
+                    }
+                }
+                for (let hPosArr of horizonCombinePos) {
+                    if (cell[JV.PROP_AREA][JV.PROP_LEFT] === hPosArr[0] && cell[JV.PROP_AREA][JV.PROP_RIGHT] === hPosArr[1]) {
+                        let hpStr = "_" + cell[JV.PROP_AREA][JV.PROP_TOP] + "_" + cell[JV.PROP_AREA][JV.PROP_BOTTOM];
+                        if (cacheObj.hCacheStr.indexOf(hpStr) < 0) {
+                            cacheObj.hCache[hpStr] = [];
+                            cacheObj.hCacheStr.push(hpStr);
+                        }
+                        cacheObj.hCache[hpStr].push(idx);
+                    }
+                }
+            }
+            if (verticalCombinePos.length > 0) {
+                for (let vPosArr of verticalCombinePos) {
+                    let pStr = "_" + vPosArr[0] + "_" + vPosArr[1];
+                    //rstPageCells的结果已经是按顺序排列了,这里不用再排序
+                    if (cacheObj.vCache[pStr] && cacheObj.vCache[pStr].length > 0) {
+                        let preCell = rstPageCells[cacheObj.vCache[pStr][0]];
+                        for (let cIdx = 1; cIdx < cacheObj.vCache[pStr].length; cIdx++) {
+                            if (preCell.Value === "") {
+                                preCell = rstPageCells[cacheObj.vCache[pStr][cIdx]];
+                            } else {
+                                if (preCell.Value === rstPageCells[cacheObj.vCache[pStr][cIdx]].Value) {
+                                    preCell[JV.PROP_AREA][JV.PROP_BOTTOM] = rstPageCells[cacheObj.vCache[pStr][cIdx]][JV.PROP_AREA][JV.PROP_BOTTOM];
+                                    removeCellIds.push(cacheObj.vCache[pStr][cIdx]);
+                                } else {
+                                    preCell = rstPageCells[cacheObj.vCache[pStr][cIdx]];
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if (horizonCombinePos.length > 1) {
+                if (cacheObj.hCacheStr.length > 0) {
+                    for (let hStr of cacheObj.hCacheStr) {
+                        let preCell = rstPageCells[cacheObj.hCache[hStr][0]];
+                        for (let cIdx = 1; cIdx < cacheObj.hCache[hStr].length; cIdx++) {
+                            if (preCell.Value === "") {
+                                preCell = rstPageCells[cacheObj.hCache[hStr][cIdx]];
+                            } else {
+                                if (preCell.Value === rstPageCells[cacheObj.hCache[hStr][cIdx]].Value) {
+                                    if (preCell[JV.PROP_AREA][JV.PROP_RIGHT] < rstPageCells[cacheObj.hCache[hStr][cIdx]][JV.PROP_AREA][JV.PROP_RIGHT]) {
+                                        preCell[JV.PROP_AREA][JV.PROP_RIGHT] = rstPageCells[cacheObj.hCache[hStr][cIdx]][JV.PROP_AREA][JV.PROP_RIGHT];
+                                    } else {
+                                        preCell[JV.PROP_AREA][JV.PROP_LEFT] = rstPageCells[cacheObj.hCache[hStr][cIdx]][JV.PROP_AREA][JV.PROP_LEFT];
+                                    }
+                                    removeCellIds.push(cacheObj.hCache[hStr][cIdx]);
+                                } else {
+                                    preCell = rstPageCells[cacheObj.hCache[hStr][cIdx]];
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if (removeCellIds.length > 0) {
+                //这次真的要排序了
+                removeCellIds.sort(); //默认方式即可
+                for (let idx = removeCellIds.length - 1; idx >= 0; idx--) {
+                    rstPageCells.splice(removeCellIds[idx], 1);
+                }
+            }
+        }
+    };
     JpcFlowTabResult.outputPreviewContent = function(rptTpl, bands, unitFactor, controls, pageStatus, maxRec) {
         let me = this, rst = [];
         let tab = rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT];
@@ -843,6 +924,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
         let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
         let tab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_CONTENT];
         let tabEx = (rptTpl[JV.NODE_FLOW_INFO_EX])?rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_CONTENT]:null;
+        let verticalCombinePos = [], horizonCombinePos = []; //合并特性用
         let band = bands[tab[JV.PROP_BAND_NAME]];
         if (band) {
             let pageStatus = me.pageStatusLst[page - 1];
@@ -919,6 +1001,17 @@ JpcFlowTabSrv.prototype.createNew = function(){
                                 }
                             }
                         }
+                        if (rowIdx === 0 && tab_field[JV.PROP_COMBINE_TYPE] !== undefined && tab_field[JV.PROP_COMBINE_TYPE] !== null) {
+                            let rstCellItem = rst[rst.length - 1];
+                            let cbfPos = [];
+                            cbfPos.push(rstCellItem[JV.PROP_AREA][JV.PROP_LEFT]);
+                            cbfPos.push(rstCellItem[JV.PROP_AREA][JV.PROP_RIGHT]);
+                            if (tab_field[JV.PROP_COMBINE_TYPE] === 'vertical') {
+                                verticalCombinePos.push(cbfPos);
+                            } else if (tab_field[JV.PROP_COMBINE_TYPE] === 'horizon') {
+                                horizonCombinePos.push(cbfPos);
+                            }
+                        }
                     }
                     if (contentValuesIdx[rowIdx][0] === JV.TYPE_FOLLOW_MODE) {
                         for (let idx_ex = 0; idx_ex < tab_fields_ex.length; idx_ex++) {
@@ -1006,6 +1099,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
         for (let idIdx = eliminateCells.length - 1; idIdx >= 0; idIdx--) {
             rst.splice(eliminateCells[idIdx], 1);
         }
+        me.combinePageCells(rst, verticalCombinePos, horizonCombinePos);
         return rst;
     };
     JpcFlowTabResult.outputColumn = function (rptTpl, dataObj, page, segIdx, bands, unitFactor, multiColIdx) {

+ 15 - 4
modules/reports/util/rpt_excel_util.js

@@ -275,24 +275,35 @@ function writeStyles(stylesObj){
 }
 function writeSharedString(sharedStrList){
     let rst = [];
+    let pri_func_write = function(cellVal) {
+        if (cellVal !== null) {
+            if ((typeof cellVal === 'string') && cellVal.indexOf(' ') === 0) {
+                rst.push('<si><t xml:space="preserve">' + cellVal + '</t></si>');
+            } else {
+                rst.push('<si><t>' + cellVal + '</t></si>');
+            }
+        }
+    };
     if (sharedStrList && sharedStrList.length > 0) {
         rst.push(dftHeadXml + '\r\n');
         rst.push('<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="' + sharedStrList.length + '" uniqueCount="' + sharedStrList.length + '">');
         let regExp = new RegExp("<", "gm");
         for (let i = 0; i < sharedStrList.length; i++) {
-            //rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
             if (typeof sharedStrList[i] === 'string') {
                 //转换特殊字符,如 < , 则需要转义一下
                 sharedStrList[i] = sharedStrList[i].replace(regExp, "&lt;");
                 if (sharedStrList[i].indexOf('|') >= 0) {
                     //rst.push('<si><t>' + sharedStrList[i].split('|').join('\r\n') + '</t></si>');
-                    rst.push('<si><t>' + sharedStrList[i].split('|').join('\n') + '</t></si>');
+                    // rst.push('<si><t>' + sharedStrList[i].split('|').join('\n') + '</t></si>');
+                    pri_func_write(sharedStrList[i].split('|').join('\n'));
                 } else {
-                    rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
+                    // rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
+                    pri_func_write(sharedStrList[i]);
                 }
                 // rst.push('<si><t>' + sharedStrList[i].replace('|','\r\n') + '</t></si>');
             } else {
-                rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
+                // rst.push('<si><t>' + sharedStrList[i] + '</t></si>');
+                pri_func_write(sharedStrList[i]);
             }
         }
         rst.push('</sst>');

+ 1 - 0
public/web/rpt_value_define.js

@@ -120,6 +120,7 @@ const JV = {
     PROP_POSITION: "Position",
     PROP_HIDDEN: "Hidden",
     PROP_IS_SERIAL: "isSerial",
+    PROP_COMBINE_TYPE: "combineType",
     PROP_IS_AUTO_HEIGHT: "isAutoHeight",
     PROP_FONT: "font",
     PROP_CONTROL: "control",