Browse Source

refactor(print develop): develop

master
wbfsa 5 years ago
parent
commit
1bf436a6e7
  1. 6
      src/controllers/constant.js
  2. 83
      src/controllers/print.js
  3. 19
      src/controllers/zoom.js
  4. 3
      src/core.js
  5. 12
      src/index.html

6
src/controllers/constant.js

@ -230,9 +230,9 @@ const gridHTML = function(){
<div class="luckysheet-zoom-ratioText" id="luckysheet-zoom-ratioText">100%</div>
</div>
<div class="luckysheet-print-viewList">
<div class="luckysheet-print-viewBtn luckysheet-print-viewNormal luckysheet-print-viewBtn-active" title="${locale_print.normalBtn}"><i class="icon iconfont icon-caidan1"></i></div>
<div class="luckysheet-print-viewBtn luckysheet-print-viewLayout" title="${locale_print.layoutBtn}"><i class="icon iconfont icon-caidan1"></i></div>
<div class="luckysheet-print-viewBtn luckysheet-print-viewPage" title="${locale_print.pageBtn}"><i class="icon iconfont icon-caidan1"></i></div>
<div type="viewNormal" class="luckysheet-print-viewBtn luckysheet-print-viewNormal luckysheet-print-viewBtn-active" title="${locale_print.normalBtn}"><i class="icon iconfont icon-caidan1"></i></div>
<div type="viewLayout" class="luckysheet-print-viewBtn luckysheet-print-viewLayout" title="${locale_print.layoutBtn}"><i class="icon iconfont icon-caidan1"></i></div>
<div type="viewPage" class="luckysheet-print-viewBtn luckysheet-print-viewPage" title="${locale_print.pageBtn}"><i class="icon iconfont icon-caidan1"></i></div>
</div>
<div class="luckysheet-sta-content" id="luckysheet-sta-content"></div>
<div class="luckysheet-bottom-content" id="luckysheet-bottom-content-show"></div>

83
src/controllers/print.js

@ -1,4 +1,9 @@
import { jsPDF } from "jspdf";
import luckysheetConfigsetting from './luckysheetConfigsetting';
import {zoomChange} from './zoom';
import sheetmanage from './sheetmanage';
import server from './server';
import Store from '../store';
// import { jsPDF } from "jspdf";
let ExcelPlaceholder = {
"[tabName]":"&A",
@ -20,4 +25,78 @@ function getOneMmsPx (){
document.querySelector("body").appendChild(div);
let mm1 = document.getElementById("mm").getBoundingClientRect();
return mm1.width;
}
}
export function viewChange(curType, preType){
let currentSheet = sheetmanage.getSheetByIndex();
if(currentSheet.config==null){
currentSheet.config = {};
}
if(currentSheet.config.sheetViewZoom==null){
currentSheet.config.sheetViewZoom = {};
}
let defaultZoom = 1, type="zoomScaleNormal";
if(curType=="viewNormal"){
type = "viewNormalZoomScale";
}
else if(curType=="viewLayout"){
type = "viewLayoutZoomScale";
}
else if(curType=="viewPage"){
type = "viewPageZoomScale";
defaultZoom = 0.6;
}
let curZoom = currentSheet.config.sheetViewZoom[type];
if(curZoom==null){
curZoom = defaultZoom;
}
currentSheet.config.curentsheetView = curType;
if (Store.clearjfundo) {
Store.jfredo.push({
"type": "viewChange",
"curType": curType,
"preType": preType,
"sheetIndex": Store.currentSheetIndex,
});
}
// Store.zoomRatio = curZoom;
// server.saveParam("all", Store.currentSheetIndex, curZoom, { "k": "zoomRatio" });
server.saveParam("cg", Store.currentSheetIndex, curType, { "k": "curentsheetView" });
zoomChange(curZoom);
}
function switchViewBtn($t){
let $viewList = $t.parent(), preType=$viewList.find("luckysheet-print-viewBtn-active").attr("type");
if($t.attr("type") == preType){
return;
}
let curType = $t.attr("type");
if(curType!=null){
viewChange(curType, preType);
}
else{
return;
}
$t.parent().find(".luckysheet-print-viewBtn").removeClass("luckysheet-print-viewBtn-active");
$t.addClass("luckysheet-print-viewBtn-active");
}
export function printInitial(){
let container = luckysheetConfigsetting.container;
let _this = this;
$("#"+container).find(".luckysheet-print-viewBtn").click(function(){
switchViewBtn($(this));
});
}

19
src/controllers/zoom.js

@ -1,6 +1,7 @@
import Store from '../store';
import locale from '../locale/locale';
import { replaceHtml } from '../utils/util';
import sheetmanage from './sheetmanage';
import {changeSheetContainerSize} from './resize';
import { jfrefreshgrid_rhcw } from '../global/refresh';
import server from './server';
@ -26,9 +27,25 @@ export function zoomChange(ratio){
}
Store.zoomRatio = ratio;
let currentSheet = sheetmanage.getSheetByIndex();
if(currentSheet.config==null){
currentSheet.config = {};
}
if(currentSheet.config.sheetViewZoom==null){
currentSheet.config.sheetViewZoom = {};
}
let type = currentSheet.config.curentsheetView;
if(type==null){
type = "viewNormal";
}
currentSheet.config.sheetViewZoom[type+"ZoomScale"] = ratio;
server.saveParam("all", Store.currentSheetIndex, Store.zoomRatio, { "k": "zoomRatio" });
server.saveParam("cg", Store.currentSheetIndex, currentSheet.config["sheetViewZoom"], { "k": "sheetViewZoom" });
zoomRefreshView();
}, 100);

3
src/core.js

@ -30,6 +30,7 @@ import { getcellvalue, getdatabyselection } from './global/getdata';
import { setcellvalue } from './global/setdata';
import { selectHightlightShow } from './controllers/select';
import {zoomInitial} from './controllers/zoom';
import {printInitial} from './controllers/print';
import method from './global/method';
import * as api from './global/api';
@ -109,6 +110,7 @@ luckysheet.create = function (setting) {
luckysheetConfigsetting.defaultRowHeight = extendsetting.defaultRowHeight;
luckysheetConfigsetting.title = extendsetting.title;
luckysheetConfigsetting.container = extendsetting.container;
// Register plugins
initPlugins(extendsetting.plugins , extendsetting.data);
@ -158,6 +160,7 @@ function initialWorkBook(){
keyboardInitial();//Keyboard operate initialization
orderByInitial();//menu bar orderby function initialization
zoomInitial();//zoom method initialization
printInitial();//print initialization
}
//获取所有表格数据

12
src/index.html

@ -54,7 +54,7 @@
}
],
data:
[sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart,sheetPicture,sheetDataVerification]
// [sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart,sheetPicture,sheetDataVerification]
/*[{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[
{"r":0,"c":0,
"v":{
@ -96,10 +96,16 @@
{"r":17,"c":2,"v":{"v":"Luckysheet","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,"m":"Luckysheet"}}
],"calcChain":[]}]*/
/*
[{
"name": "Cell",
"config": {
"curentsheetView":"viewNormal",//viewNormal, viewLayout, viewPage
"sheetViewZoom":{
"viewNormalZoomScale": 1 ,
"viewLayoutZoomScale":1 ,
"viewPageZoomScale":0.6,
},
"printoptions":{
unit:"mm",//mm(default), in, pt, cm, m,
PrintArea:"$A$1:$S$31",//print range
@ -1776,7 +1782,7 @@
],
"scrollLeft": 0,
"scrollTop": 0
}]*/
}]
})
})

Loading…
Cancel
Save