rhchInit.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import Store from '../store';
  2. import { computeRowlenByContent,computeColWidthByContent } from './getRowlen';
  3. import luckysheetConfigsetting from '../controllers/luckysheetConfigsetting';
  4. export default function rhchInit(rowheight, colwidth) {
  5. zoomSetting();//Zoom sheet on first load
  6. //行高
  7. if(rowheight != null){
  8. Store.visibledatarow = [];
  9. Store.rh_height = 0;
  10. for (let r = 0; r < rowheight; r++) {
  11. let rowlen = Store.defaultrowlen;
  12. if (Store.config["rowlen"] != null && Store.config["rowlen"][r] != null) {
  13. rowlen = Store.config["rowlen"][r];
  14. }
  15. if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) {
  16. Store.visibledatarow.push(Store.rh_height);
  17. continue;
  18. }
  19. // 自动行高计算
  20. if (rowlen === 'auto') {
  21. rowlen = computeRowlenByContent(Store.flowdata, r);
  22. }
  23. Store.rh_height += Math.round((rowlen + 1) * Store.zoomRatio);
  24. Store.visibledatarow.push(Store.rh_height); //行的临时长度分布
  25. }
  26. // 如果增加行和回到顶部按钮隐藏,则减少底部空白区域,但是预留足够空间给单元格下拉按钮
  27. if (!luckysheetConfigsetting.enableAddRow && !luckysheetConfigsetting.enableAddBackTop) {
  28. Store.rh_height += Store.allowEdit?30:Store.cellMainSrollBarSize;
  29. } else {
  30. Store.rh_height += 80; //最底部增加空白
  31. }
  32. }
  33. //列宽
  34. if(colwidth != null){
  35. Store.visibledatacolumn = [];
  36. Store.ch_width = 0;
  37. let maxColumnlen = Store.allowEdit?120:Store.cellMainSrollBarSize;
  38. for (let c = 0; c < colwidth; c++) {
  39. let firstcolumnlen = Store.defaultcollen;
  40. if (Store.config["columnlen"] != null && Store.config["columnlen"][c] != null) {
  41. firstcolumnlen = Store.config["columnlen"][c];
  42. }
  43. else {
  44. if (Store.flowdata[0] != null && Store.flowdata[0][c] != null) {
  45. if (firstcolumnlen > 300) {
  46. firstcolumnlen = 300;
  47. }
  48. else if (firstcolumnlen < Store.defaultcollen) {
  49. firstcolumnlen = Store.defaultcollen;
  50. }
  51. if (firstcolumnlen != Store.defaultcollen) {
  52. if (Store.config["columnlen"] == null) {
  53. Store.config["columnlen"] = {};
  54. }
  55. Store.config["columnlen"][c] = firstcolumnlen;
  56. }
  57. }
  58. }
  59. if(Store.config["colhidden"] != null && Store.config["colhidden"][c] != null){
  60. Store.visibledatacolumn.push(Store.ch_width);
  61. continue;
  62. }
  63. // 自动行高计算
  64. if (firstcolumnlen === 'auto') {
  65. firstcolumnlen = computeColWidthByContent(Store.flowdata, c, rowheight);
  66. }
  67. Store.ch_width += Math.round((firstcolumnlen + 1)*Store.zoomRatio);
  68. Store.visibledatacolumn.push(Store.ch_width);//列的临时长度分布
  69. // if(maxColumnlen < firstcolumnlen + 1){
  70. // maxColumnlen = firstcolumnlen + 1;
  71. // }
  72. }
  73. // Store.ch_width += 120;
  74. Store.ch_width += maxColumnlen;
  75. }
  76. }
  77. export function zoomSetting(){
  78. //zoom
  79. Store.rowHeaderWidth = luckysheetConfigsetting.rowHeaderWidth * Store.zoomRatio;
  80. Store.columnHeaderHeight = luckysheetConfigsetting.columnHeaderHeight *Store.zoomRatio;
  81. $("#luckysheet-rows-h").width((Store.rowHeaderWidth-1.5));
  82. $("#luckysheet-cols-h-c").height((Store.columnHeaderHeight-1.5));
  83. $("#luckysheet-left-top").css({width:Store.rowHeaderWidth-1.5, height:Store.columnHeaderHeight-1.5});
  84. }