print.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import luckysheetConfigsetting from './luckysheetConfigsetting';
  2. import {zoomChange} from './zoom';
  3. import sheetmanage from './sheetmanage';
  4. import server from './server';
  5. import {rowLocationByIndex, colLocationByIndex,mouseposition,rowLocation,colLocation} from '../global/location';
  6. import Store from '../store';
  7. let ExcelPlaceholder = {
  8. "[tabName]":"&A",
  9. "[CurrentDate]":"&D",
  10. "[fileName]":"&F",
  11. "[background]":"&G",
  12. "[Shadow]":"&H",
  13. "[TotalPages]":"&N",
  14. "[pageNumber]":"&P",
  15. "[CurrentTime]":"&T",
  16. "[filePath]":"&Z",
  17. }
  18. // Get the pixel value per millimeter
  19. function getOneMmsPx (){
  20. let div = document.createElement("div");
  21. div.style.width = "1mm";
  22. document.querySelector("body").appendChild(div);
  23. let mm1 = div.getBoundingClientRect();
  24. let w = mm1.width;
  25. $(div).remove();
  26. return mm1.width;
  27. }
  28. export function viewChange(curType, preType){
  29. let currentSheet = sheetmanage.getSheetByIndex();
  30. if(currentSheet.config==null){
  31. currentSheet.config = {};
  32. }
  33. if(currentSheet.config.sheetViewZoom==null){
  34. currentSheet.config.sheetViewZoom = {};
  35. }
  36. let defaultZoom = 1, type="zoomScaleNormal";
  37. printLineAndNumberDelete(currentSheet);
  38. if(curType=="viewNormal"){
  39. type = "viewNormalZoomScale";
  40. }
  41. else if(curType=="viewLayout"){
  42. type = "viewLayoutZoomScale";
  43. }
  44. else if(curType=="viewPage"){
  45. type = "viewPageZoomScale";
  46. defaultZoom = 0.6;
  47. printLineAndNumberCreate(currentSheet);
  48. }
  49. let curZoom = currentSheet.config.sheetViewZoom[type];
  50. if(curZoom==null){
  51. curZoom = defaultZoom;
  52. }
  53. currentSheet.config.curentsheetView = curType;
  54. if (Store.clearjfundo) {
  55. Store.jfredo.push({
  56. "type": "viewChange",
  57. "curType": curType,
  58. "preType": preType,
  59. "sheetIndex": Store.currentSheetIndex,
  60. });
  61. }
  62. // Store.zoomRatio = curZoom;
  63. // server.saveParam("all", Store.currentSheetIndex, curZoom, { "k": "zoomRatio" });
  64. server.saveParam("cg", Store.currentSheetIndex, curType, { "k": "curentsheetView" });
  65. Store.currentSheetView = curType;
  66. zoomChange(curZoom);
  67. }
  68. function printLineAndNumberDelete(sheet){
  69. }
  70. function printLineAndNumberCreate(sheet){
  71. }
  72. function switchViewBtn($t){
  73. let $viewList = $t.parent(), preType=$viewList.find("luckysheet-print-viewBtn-active").attr("type");
  74. if($t.attr("type") == preType){
  75. return;
  76. }
  77. let curType = $t.attr("type");
  78. if(curType!=null){
  79. viewChange(curType, preType);
  80. }
  81. else{
  82. return;
  83. }
  84. $t.parent().find(".luckysheet-print-viewBtn").removeClass("luckysheet-print-viewBtn-active");
  85. $t.addClass("luckysheet-print-viewBtn-active");
  86. }
  87. export function printInitial(){
  88. let container = luckysheetConfigsetting.container;
  89. let _this = this;
  90. $("#"+container).find(".luckysheet-print-viewBtn").click(function(){
  91. switchViewBtn($(this));
  92. });
  93. }