From 7a625e0dae187cc7af8e10e3449abf666fd332eb Mon Sep 17 00:00:00 2001 From: wbfsa Date: Sun, 2 Aug 2020 04:06:40 +0800 Subject: [PATCH] fix(change sheet bug): multiple refresh canvas bug --- src/controllers/pivotTable.js | 8 ++++---- src/controllers/resize.js | 6 ++++-- src/controllers/sheetmanage.js | 10 +++++----- src/core.js | 4 ++-- src/global/refresh.js | 33 +++++++++++++++++++++------------ 5 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/controllers/pivotTable.js b/src/controllers/pivotTable.js index 80ab3c31f..e5cd16445 100644 --- a/src/controllers/pivotTable.js +++ b/src/controllers/pivotTable.js @@ -669,7 +669,7 @@ const pivotTable = { _this.getCellData(index); _this.initialPivotManage(true); }, - refreshPivotTable: function () { + refreshPivotTable: function (isRefreshCanvas=true) { let _this = this; let redo = {}; @@ -730,10 +730,10 @@ const pivotTable = { Store.clearjfundo = false; if (addr > 0 || addc > 0) { - jfrefreshgridall(data[0].length, data.length, data, null, Store.luckysheet_select_save, "datachangeAll"); + jfrefreshgridall(data[0].length, data.length, data, null, Store.luckysheet_select_save, "datachangeAll", undefined, undefined,isRefreshCanvas); } else { - jfrefreshgrid(data, Store.luckysheet_select_save); + jfrefreshgrid(data, Store.luckysheet_select_save, isRefreshCanvas, undefined, undefined, undefined, false); selectHightlightShow(); } @@ -2345,7 +2345,7 @@ const pivotTable = { $("#luckysheet-dialog-pivotTable-range").html(getRangetxt(_this.pivotDataSheetIndex, _this.pivot_select_save)); $("#luckysheet-modal-dialog-slider-pivot").show(); - luckysheetsizeauto(); + luckysheetsizeauto(false); }, getComposeArray: function (data) { if (data.length == 0) { diff --git a/src/controllers/resize.js b/src/controllers/resize.js index 456183c6e..913db84bc 100644 --- a/src/controllers/resize.js +++ b/src/controllers/resize.js @@ -8,7 +8,7 @@ import sheetmanage from './sheetmanage'; let gridW = 0, gridH = 0; -export default function luckysheetsizeauto() { +export default function luckysheetsizeauto(isRefreshCanvas=true) { if (!luckysheetConfigsetting.showinfobar) { Store.infobarHeight = 0; $("#luckysheet_info_detail").hide(); @@ -104,7 +104,9 @@ export default function luckysheetsizeauto() { .css({ "height": gridheight - 10 }); luckysheetFreezen.createAssistCanvas(); - luckysheetrefreshgrid($("#luckysheet-cell-main").scrollLeft(), $("#luckysheet-cell-main").scrollTop()); + if(isRefreshCanvas){ + luckysheetrefreshgrid($("#luckysheet-cell-main").scrollLeft(), $("#luckysheet-cell-main").scrollTop()); + } const _locale = locale(); const locale_toolbar = _locale.toolbar; let ismore = false, diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js index 44aa191aa..ee1d4c528 100644 --- a/src/controllers/sheetmanage.js +++ b/src/controllers/sheetmanage.js @@ -674,7 +674,7 @@ const sheetmanage = { formula.execFunctionGroup(); _this.restoreSheetAll(Store.currentSheetIndex); - luckysheetrefreshgrid(0, 0); + // luckysheetrefreshgrid(0, 0); $("#luckysheet_info_detail_save").html(locale_info.detailSave); if (!!file.isPivotTable) { @@ -787,7 +787,7 @@ const sheetmanage = { createFilterOptions(file["filter_select"], file["filter"]); - jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); + jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length,false); }, restoreselect: function() { let index = this.getSheetIndex(Store.currentSheetIndex); @@ -1210,7 +1210,7 @@ const sheetmanage = { file.config.rowhidden = {}; Store.config = file.config; - jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); + jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length,false); } return; @@ -1265,7 +1265,7 @@ const sheetmanage = { file.config["rowhidden"] = rowhidden; Store.config = file.config; - jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); + jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length,false); }, restorePivot: function(sheetIndex) { let index = this.getSheetIndex(sheetIndex); @@ -1277,7 +1277,7 @@ const sheetmanage = { pivotTable.getCellData(sheetIndex); pivotTable.initialPivotManage(true); - pivotTable.refreshPivotTable(); + pivotTable.refreshPivotTable(false); }, restoreSheetAll: function(sheetIndex) { let _this= this; diff --git a/src/core.js b/src/core.js index 8bcb51dab..0f89b0bb0 100644 --- a/src/core.js +++ b/src/core.js @@ -106,7 +106,7 @@ luckysheet.create = function (setting) { let data = []; if (loadurl == "") { sheetmanage.initialjfFile(menu, title); - luckysheetsizeauto(); + // luckysheetsizeauto(); initialWorkBook(); } else { @@ -115,7 +115,7 @@ luckysheet.create = function (setting) { Store.luckysheetfile = data; sheetmanage.initialjfFile(menu, title); - luckysheetsizeauto(); + // luckysheetsizeauto(); initialWorkBook(); //需要更新数据给后台时,建立WebSocket连接 diff --git a/src/global/refresh.js b/src/global/refresh.js index 619d88f6f..eab983e56 100644 --- a/src/global/refresh.js +++ b/src/global/refresh.js @@ -18,7 +18,7 @@ import { createFilterOptions } from '../controllers/filter'; import { getSheetIndex } from '../methods/get'; import Store from '../store'; -function jfrefreshgrid(data, range, cfg, cdformat, RowlChange, isRunExecFunction=true) { +function jfrefreshgrid(data, range, cfg, cdformat, RowlChange, isRunExecFunction=true, isRefreshCanvas=true) { if(data == null){ data = Store.flowdata; } @@ -122,14 +122,17 @@ function jfrefreshgrid(data, range, cfg, cdformat, RowlChange, isRunExecFunction } //刷新表格 - setTimeout(function () { - luckysheetrefreshgrid(); - }, 1); + if(isRefreshCanvas){ + setTimeout(function () { + luckysheetrefreshgrid(); + }, 1); + } + window.luckysheet_getcelldata_cache = null; } -function jfrefreshgridall(colwidth, rowheight, data, cfg, range, ctrlType, ctrlValue, cdformat, changeSize) { +function jfrefreshgridall(colwidth, rowheight, data, cfg, range, ctrlType, ctrlValue, cdformat, isRefreshCanvas=true) { let redo = {}; if (ctrlType == "cellRowChange") { @@ -246,9 +249,12 @@ function jfrefreshgridall(colwidth, rowheight, data, cfg, range, ctrlType, ctrlV //行高、列宽 刷新 jfrefreshgrid_rhcw(rowheight, colwidth); - setTimeout(function () { - luckysheetrefreshgrid(); - }, 1); + if(isRefreshCanvas){ + setTimeout(function () { + luckysheetrefreshgrid(); + }, 1); + } + sheetmanage.storeSheetParamALL(); @@ -633,7 +639,7 @@ function jfrefreshgrid_pastcut(source, target, RowlChange){ } //行高、列宽改变 刷新表格 -function jfrefreshgrid_rhcw(rowheight, colwidth){ +function jfrefreshgrid_rhcw(rowheight, colwidth, isRefreshCanvas=true){ rhchInit(rowheight, colwidth); sheetmanage.storeSheetParam(); @@ -786,9 +792,12 @@ function jfrefreshgrid_rhcw(rowheight, colwidth){ sheetmanage.showSheet(); - setTimeout(function () { - luckysheetrefreshgrid(); - }, 1); + if(isRefreshCanvas){ + setTimeout(function () { + luckysheetrefreshgrid(); + }, 1); + } + } //Refresh the canvas display data according to scrollHeight and scrollWidth