Просмотр исходного кода

fix(report): 报表代码新增紧凑显示逻辑

lishihao 4 лет назад
Родитель
Сommit
d383030e3f

+ 4 - 2
report/src/core/helper/jpc_helper_common.ts

@@ -144,7 +144,8 @@ export const JpcCommonHelper = {
                 //大于127为中文字
                 currentW = (strVal.charCodeAt(sIdx) > 127) ? chnW : otherW;
                 txtWidth += currentW;
-                if (txtWidth > areaWidth) {
+                if (txtWidth > (areaWidth - 4)) {
+                    //减4个像素是考虑到导出excel的情况
                     rst++;
                     txtWidth = currentW;
                 }
@@ -165,7 +166,8 @@ export const JpcCommonHelper = {
             for (let sIdx = 0; sIdx < strVal.length; sIdx++) {
                 currentW = (strVal.charCodeAt(sIdx) > 127) ? chnW : otherW;
                 txtWidth += currentW;
-                if (txtWidth > areaWidth) {
+                if (txtWidth > (areaWidth - 4)) {
+                    //减4个像素是考虑到导出excel的情况
                     if (preSIdx < sIdx) {
                         rst.push(strVal.substr(preSIdx, sIdx - preSIdx));
                         preSIdx = sIdx;

+ 17 - 0
report/src/core/helper/jpc_helper_flow_tab.ts

@@ -5,6 +5,23 @@ import { JV } from '../jpc_value_define';
 import { JpcCommonHelper } from './jpc_helper_common';
 
 export let JpcFlowTabHelper = {
+    getRowHeight: function(bands:IBands, rptTpl:IRptTpl, isEx:boolean) {
+        let rst = 0;
+        let FLOW_INFO_STR = (!isEx)?JV.NODE_FLOW_INFO:JV.NODE_FLOW_INFO_EX;
+        let tab = rptTpl.流水式表_信息.流水式表_数据;
+        let band = bands[tab.BandName];
+        if (band) {
+            let maxFieldMeasure = 1.0;
+            if (JV.CAL_TYPE_ABSTRACT === JpcCommonHelper.getPosCalculationType(tab.CalculationType)) {
+                let unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);
+                maxFieldMeasure = 1.0 * rptTpl.流水式表_信息.流水式表_数据.CommonHeight * unitFactor;
+            } else {
+                maxFieldMeasure = (band.Bottom - band.Top) * rptTpl.流水式表_信息.流水式表_数据.CommonHeight / JV.HUNDRED_PERCENT;
+            }
+            rst = maxFieldMeasure;
+        }
+        return rst;
+    },
     getMaxRowsPerPage: function (bands: IBands, rptTpl: IRptTpl, isEx: boolean) {
         let rst = 1;
         let tab;

+ 61 - 3
report/src/core/jpc_flow_tab.ts

@@ -318,7 +318,7 @@ export class JpcFlowTabClass {
                         let chkFontHeight = 12;
                         if (font) {
                             chkFontName = font[JV.FONT_PROPS[0]];
-                            chkFontHeight = font[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]];
+                            chkFontHeight = parseFloat(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]]);
                         }
                         let hasSplitStr = false, splitStrArr = [];
                         let accAmt = 0;
@@ -333,6 +333,20 @@ export class JpcFlowTabClass {
                             }
                         }
                         if (accAmt > rst) rst = accAmt;
+                        if (rst > 3) {
+                            // 新优化,计算实际能显示完的真正行数
+                            const rowHeight = JpcFlowTabHelper.getRowHeight(bands, rptTpl, me.isEx);
+                            let tmpFV = ((chkFontHeight + JV.CLOSE_OUTPUT_ROW_BUFFER) * rst) / rowHeight;
+                            let tmpAmt = Math.floor(tmpFV);
+                            // tmpAmt += Math.ceil((tmpFV - tmpAmt) / 0.5);
+                            // if (tmpFV - tmpAmt >= 0.5 && rst > 6) {
+                            //     tmpAmt++;
+                            // }
+                            if (Math.ceil(tmpFV) > tmpAmt) {
+                                tmpAmt++;
+                            }
+                            rst = tmpAmt;
+                        }
                         if (hasSplitStr) {
                             let newValArr: any = [];
                             for (let i = 0; i < values.length; i++) {
@@ -598,7 +612,10 @@ export class JpcFlowTabClass {
                                         //纯 followTabEx 数据啦
                                         private_addPage(segIdx, null, true, false, -1);
                                     } else {
-                                        private_addPage(segIdx, grpSeqInfo, false, true, ttlSegRecAmtNormal);
+                                        // private_addPage(segIdx, grpSeqInfo, false, true, ttlSegRecAmtNormal);
+                                        //在这里要考虑如果有多页正常的流水数据情况,那么就得考虑这页有多少条普通流水记录,不应该一刀切地用ttlSegRecAmtNormal
+                                        let splitPoint = ttlSegRecAmtNormal - handledRowAmt ;
+                                        private_addPage(segIdx, grpSeqInfo, false, true, splitPoint);
                                     }
                                 } else {
                                     //在这里要考虑如果有多页正常的流水数据情况,那么就得考虑这页有多少条普通流水记录,不应该一刀切地用ttlSegRecAmtNormal
@@ -1238,11 +1255,52 @@ export class JpcFlowTabClass {
             if (showText) {
                 textArr = textArr.concat(showText.split('|'));
             }
+                        /*
             if (contentValInfo[3] < textArr.length && contentValInfo[3] >= 0) {
                 showText = textArr[contentValInfo[3]];
-            } else {
+            }
+            else {
                 showText = '';
             }
+ /*/
+            // 因新逻辑要优化自动行高,不再是一个折行占用1row,而是: 
+            // a. 根据实际情况,设置了一个实际的行数值(比如共有10行,根据行高情况,可能只设置了6行的高度,在setupAutoHeightData方法里处理)
+            // b. 这里最大的难题在于跨页分配(预估会有来回调整,目前采用按比例分配原则)
+            // c. 还有个问题就是多个自动行高指标的问题
+            const ACT_ROWS = contentValInfo[4]; //经实际计算,能容纳所有数据的实际行数
+            const CURRENT_ROW = contentValInfo[3]; //从0开始
+            const QUOTA_Rate = textArr.length / ACT_ROWS; //每行显示的加权系数(超过2的话,表示给的行高太多了,需要另外一些特殊处理,后期有需要再加)
+            if (textArr.length <= 3 || ACT_ROWS > textArr.length) {
+                //表示这个一定是附属的autoheight指标,或者数据就只有3行(假如数据3行精简成2行,但刚好处于分页状态,那么无论是前一页或后一页,显示上都很纠结(多出来的一行放哪好?),所以新逻辑的起点要3行以上,少了就不折腾了,老老实实地一个萝卜一个坑)
+                if (CURRENT_ROW < textArr.length && CURRENT_ROW >= 0) {
+                    showText = textArr[CURRENT_ROW];
+                } else {
+                    showText = '';
+                }
+            } else {
+                //这里不管是不是附属autoheight指标,有足够的条件单独处理
+                if (QUOTA_Rate >= 2) {
+                    //压缩超过一半空间的话,说明给的行高度太高了,需要另外一些特殊处理,后期有需要再加
+                } else {
+                    //正常的压缩比例
+                    let startIdx = 0, endIdx = 0;
+                    if (CURRENT_ROW > 0) {
+                        endIdx = Math.round((CURRENT_ROW + 1) * QUOTA_Rate) - 1;
+                        let preEndIdx = 0;
+                        if (CURRENT_ROW > 1) {
+                            //重定位 preEndIdx
+                            preEndIdx = Math.round(CURRENT_ROW * QUOTA_Rate) - 1;
+                        }
+                        startIdx = preEndIdx + 1;
+                    }
+                    //按比例分配
+                    showText = textArr[startIdx];
+                    for (let idx = startIdx + 1; idx <= endIdx; idx++) {
+                        showText += `|${textArr[idx]}`;
+                    }
+                }
+            }
+            //*/
             let rst = JpcCommonOutputHelper.createCommonOutput(tab_field, showText, controls);
             rst.area = JpcAreaHelper.outputArea(tab_field.area, band, unitFactor, rows, rowIdx, cols, colIdx, me.multiCols, multiColIdx, true, false);
             rst.isAutoHeight = true;

+ 27 - 1
report/src/core/jpc_rte.ts

@@ -181,5 +181,31 @@ export const JE = {
                 dataObj[field.DataNodeName][field.DataSeq][dataObj[field.DataNodeName][field.DataSeq].length] = newValue;
             }
         }
-    }
+    },
+    alignFieldDecimal: function(sourceID:number, destID:number,$CURRENT_RPT:ICurrent_RPT) {
+        // 把source指标的精度align到dest
+        const me = JE;
+        let sourceField = null;
+        if (isNaN(sourceID)) {
+            sourceField = sourceID;
+        } else {
+            sourceField = me.F(sourceID,$CURRENT_RPT);
+        }
+        let destField :any;
+        if (isNaN(destID)) {
+            destField = destID;
+        } else {
+            destField = me.F(destID,$CURRENT_RPT);
+        }
+        if ( sourceField instanceof Object && sourceField && sourceField.Precision) {
+            destField.Precision = sourceField.Precision;
+            destField.fixedPrecisionNum = sourceField.fixedPrecisionNum;
+        }
+    },
+    batchIniFields: function(IDArr:any[],$CURRENT_RPT:ICurrent_RPT) {
+        // 批处理查找指标
+        const me = JE;
+        for (let idxF = 0; idxF < IDArr.length; idxF++) {
+            IDArr[idxF] = me.F(IDArr[idxF],$CURRENT_RPT);
+        }}
 };

+ 2 - 1
report/src/core/jpc_value_define.ts

@@ -239,6 +239,7 @@ export const JV = {
     CONTROL_PROP_IDX_VERTICAL_EXCEL: 5,
     CONTROL_PROP_IDX_SHRINK_FIRST: 6,
     CONTROL_PROP_IDX_CLOSE_OUTPUT: 7,
+    CLOSE_OUTPUT_ROW_BUFFER: 4,
     BORDER_STYLE_PROPS: ['LineWeight', 'DashStyle', 'Color'],
     PROP_LINE_WEIGHT: 'LineWeight',
     PROP_DASH_STYLE: 'DashStyle',
@@ -313,7 +314,7 @@ export const JV = {
     SIZE_16K: [7.75, 10.75],
     SIZE_EXECUTIVE: [7.25, 10.5],
 
-    OUTPUT_OFFSET: [2, 2, 1, 3],
+    OUTPUT_OFFSET: [1,1,1,1],
     OFFSET_IDX_LEFT: 0,
     OFFSET_IDX_RIGHT: 1,
     OFFSET_IDX_TOP: 2,