Browse Source

bugfix: 关闭任意一个toolbar的功能时,界面无法加载

原因: 关闭功能时,由于界面没有渲染该节点,在resize.js 的445行中,无法找到该节点获取offset导致错误
bugfix: undoRedo 配置在toolbar.js中判断后直接删除,由于是引用对象,配置被全局删除,在resize.js中也使用该配置,却无法获取该配置参数,导致出错
master
dava 4 years ago
parent
commit
a626118f64
  1. 87
      src/controllers/resize.js
  2. 1
      src/controllers/toolbar.js

87
src/controllers/resize.js

@ -8,7 +8,7 @@ import tooltip from '../global/tooltip'
import { $$, getObjType, camel2split } from "../utils/util"; import { $$, getObjType, camel2split } from "../utils/util";
import { defaultToolbar, toolbarIdMap } from './toolbar'; import { defaultToolbar, toolbarIdMap } from './toolbar';
let gridW = 0, let gridW = 0,
gridH = 0; gridH = 0;
export default function luckysheetsizeauto(isRefreshCanvas=true) { export default function luckysheetsizeauto(isRefreshCanvas=true) {
@ -41,7 +41,7 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
// Store.sheetBarHeight = 31; // Store.sheetBarHeight = 31;
// } // }
customSheetbarConfig(); customSheetbarConfig();
// if (!luckysheetConfigsetting.showstatisticBar) { // if (!luckysheetConfigsetting.showstatisticBar) {
@ -73,7 +73,7 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
if(luckysheetConfigsetting.showConfigWindowResize){//数据透视表 图表 交替颜色 Protection if(luckysheetConfigsetting.showConfigWindowResize){//数据透视表 图表 交替颜色 Protection
if($("#luckysheet-modal-dialog-slider-pivot").is(":visible")){ if($("#luckysheet-modal-dialog-slider-pivot").is(":visible")){
gridW -= $("#luckysheet-modal-dialog-slider-pivot").outerWidth(); gridW -= $("#luckysheet-modal-dialog-slider-pivot").outerWidth();
} }
else if($(".chartSetting").is(":visible")){ else if($(".chartSetting").is(":visible")){
gridW -= $(".chartSetting").outerWidth(); gridW -= $(".chartSetting").outerWidth();
} }
@ -82,12 +82,12 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
} }
if($("#luckysheet-modal-dialog-slider-protection").is(":visible")){ if($("#luckysheet-modal-dialog-slider-protection").is(":visible")){
gridW -= $("#luckysheet-modal-dialog-slider-protection").outerWidth(); gridW -= $("#luckysheet-modal-dialog-slider-protection").outerWidth();
} }
} }
const _locale = locale(); const _locale = locale();
const locale_toolbar = _locale.toolbar; const locale_toolbar = _locale.toolbar;
let ismore = false, let ismore = false,
toolbarW = 0, toolbarW = 0,
morebtn = `<div class="luckysheet-toolbar-button luckysheet-inline-block" data-tips="${locale_toolbar.toolMoreTip}" id="luckysheet-icon-morebtn" role="button" style="user-select: none;"> morebtn = `<div class="luckysheet-toolbar-button luckysheet-inline-block" data-tips="${locale_toolbar.toolMoreTip}" id="luckysheet-icon-morebtn" role="button" style="user-select: none;">
<div class="luckysheet-toolbar-button-outer-box luckysheet-inline-block" style="user-select: none;"> <div class="luckysheet-toolbar-button-outer-box luckysheet-inline-block" style="user-select: none;">
@ -104,7 +104,7 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
</div>`, </div>`,
// Add style left:$$('.luckysheet') left, when the worksheet does not fill the full screen // Add style left:$$('.luckysheet') left, when the worksheet does not fill the full screen
morediv = '<div id="luckysheet-icon-morebtn-div" class="luckysheet-wa-editor" style="position:absolute;top:'+ (Store.infobarHeight + Store.toolbarHeight + $("#" + Store.container).offset().top + $("body").scrollTop()) +'px;right:0px;z-index:1003;padding:5.5px;visibility:hidden;height:auto;white-space:initial;"></div>'; morediv = '<div id="luckysheet-icon-morebtn-div" class="luckysheet-wa-editor" style="position:absolute;top:'+ (Store.infobarHeight + Store.toolbarHeight + $("#" + Store.container).offset().top + $("body").scrollTop()) +'px;right:0px;z-index:1003;padding:5.5px;visibility:hidden;height:auto;white-space:initial;"></div>';
if($("#luckysheet-icon-morebtn-div").length == 0){ if($("#luckysheet-icon-morebtn-div").length == 0){
$("body").append(morediv); $("body").append(morediv);
} }
@ -116,7 +116,7 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
$("#luckysheet-icon-morebtn-div > div").each(function(){ $("#luckysheet-icon-morebtn-div > div").each(function(){
const $t = $(this)[0]; const $t = $(this)[0];
const $container = $("#luckysheet-wa-editor")[0]; const $container = $("#luckysheet-wa-editor")[0];
$container.appendChild(document.createTextNode(" ")); $container.appendChild(document.createTextNode(" "));
$container.appendChild($t); $container.appendChild($t);
}); });
@ -155,11 +155,11 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
}else{ }else{
$("#luckysheet-icon-morebtn-div").append($(`${element}`)); $("#luckysheet-icon-morebtn-div").append($(`${element}`));
} }
} }
if(ismore){ if(ismore){
$("#luckysheet-wa-editor").append(morebtn); $("#luckysheet-wa-editor").append(morebtn);
$("#luckysheet-icon-morebtn").click(function(){ $("#luckysheet-icon-morebtn").click(function(){
@ -174,10 +174,10 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
} }
let right = $(window).width() - $("#luckysheet-icon-morebtn").offset().left - $("#luckysheet-icon-morebtn").width()+ $("body").scrollLeft(); let right = $(window).width() - $("#luckysheet-icon-morebtn").offset().left - $("#luckysheet-icon-morebtn").width()+ $("body").scrollLeft();
// $("#luckysheet-icon-morebtn-div").toggle().css("right", right < 0 ? 0 : right); // $("#luckysheet-icon-morebtn-div").toggle().css("right", right < 0 ? 0 : right);
// use native js operation // use native js operation
$$('#luckysheet-icon-morebtn-div').style.right = right < 0 ? 0 : right + 'px'; $$('#luckysheet-icon-morebtn-div').style.right = right < 0 ? 0 : right + 'px';
@ -212,10 +212,10 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
$(this).find(".luckysheet-toolbar-button-inner-box").html(toolMoreHTML); $(this).find(".luckysheet-toolbar-button-inner-box").html(toolMoreHTML);
} }
}); });
//$("#luckysheet-wa-editor div").trigger("create"); //$("#luckysheet-wa-editor div").trigger("create");
// $("#luckysheet-icon-morebtn-div .luckysheet-toolbar-menu-button").css("margin-right", -1); // $("#luckysheet-icon-morebtn-div .luckysheet-toolbar-menu-button").css("margin-right", -1);
// $("#luckysheet-icon-morebtn-div .luckysheet-toolbar-button-split-left").css("margin-right", -3); // $("#luckysheet-icon-morebtn-div .luckysheet-toolbar-button-split-left").css("margin-right", -3);
@ -235,7 +235,7 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
// tooltip // tooltip
tooltip.createHoverTip("#luckysheet-icon-morebtn-div" ,".luckysheet-toolbar-menu-button, .luckysheet-toolbar-button, .luckysheet-toolbar-combo-button"); tooltip.createHoverTip("#luckysheet-icon-morebtn-div" ,".luckysheet-toolbar-menu-button, .luckysheet-toolbar-button, .luckysheet-toolbar-combo-button");
} }
$("#"+ Store.container + " .luckysheet-wa-editor .luckysheet-toolbar-button-split-left").off("hover").hover(function(){ $("#"+ Store.container + " .luckysheet-wa-editor .luckysheet-toolbar-button-split-left").off("hover").hover(function(){
$(this).next(".luckysheet-toolbar-button-split-right").addClass("luckysheet-toolbar-button-split-right-hover"); $(this).next(".luckysheet-toolbar-button-split-right").addClass("luckysheet-toolbar-button-split-right-hover");
}, function(){ }, function(){
@ -254,7 +254,7 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
$("#" + Store.container).find(".luckysheet").height(gridH - 2).width(gridW - 2); $("#" + Store.container).find(".luckysheet").height(gridH - 2).width(gridW - 2);
changeSheetContainerSize(gridW, gridH) changeSheetContainerSize(gridW, gridH)
if(isRefreshCanvas){ if(isRefreshCanvas){
luckysheetrefreshgrid($("#luckysheet-cell-main").scrollLeft(), $("#luckysheet-cell-main").scrollTop()); luckysheetrefreshgrid($("#luckysheet-cell-main").scrollLeft(), $("#luckysheet-cell-main").scrollTop());
} }
@ -274,7 +274,7 @@ export function changeSheetContainerSize(gridW, gridH){
} }
Store.cellmainHeight = gridH - (Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columnHeaderHeight + Store.sheetBarHeight + Store.statisticBarHeight); Store.cellmainHeight = gridH - (Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columnHeaderHeight + Store.sheetBarHeight + Store.statisticBarHeight);
Store.cellmainWidth = gridW - Store.rowHeaderWidth; Store.cellmainWidth = gridW - Store.rowHeaderWidth;
$("#luckysheet-cols-h-c, #luckysheet-cell-main").width(Store.cellmainWidth); $("#luckysheet-cols-h-c, #luckysheet-cell-main").width(Store.cellmainWidth);
$("#luckysheet-cell-main").height(Store.cellmainHeight); $("#luckysheet-cell-main").height(Store.cellmainHeight);
$("#luckysheet-rows-h").height(Store.cellmainHeight - Store.cellMainSrollBarSize); $("#luckysheet-rows-h").height(Store.cellmainHeight - Store.cellMainSrollBarSize);
@ -286,13 +286,13 @@ export function changeSheetContainerSize(gridW, gridH){
$("#luckysheet-scrollbar-x").width(Store.cellmainWidth).css("left", Store.rowHeaderWidth - 2); $("#luckysheet-scrollbar-x").width(Store.cellmainWidth).css("left", Store.rowHeaderWidth - 2);
Store.luckysheetTableContentHW = [ Store.luckysheetTableContentHW = [
Store.cellmainWidth + Store.rowHeaderWidth - Store.cellMainSrollBarSize, Store.cellmainWidth + Store.rowHeaderWidth - Store.cellMainSrollBarSize,
Store.cellmainHeight + Store.columnHeaderHeight - Store.cellMainSrollBarSize Store.cellmainHeight + Store.columnHeaderHeight - Store.cellMainSrollBarSize
]; ];
$("#luckysheetTableContent, #luckysheetTableContentF").attr({ $("#luckysheetTableContent, #luckysheetTableContentF").attr({
width: Math.ceil(Store.luckysheetTableContentHW[0] * Store.devicePixelRatio), width: Math.ceil(Store.luckysheetTableContentHW[0] * Store.devicePixelRatio),
height: Math.ceil(Store.luckysheetTableContentHW[1] * Store.devicePixelRatio) height: Math.ceil(Store.luckysheetTableContentHW[1] * Store.devicePixelRatio)
}) })
.css({ width: Store.luckysheetTableContentHW[0], height: Store.luckysheetTableContentHW[1] }); .css({ width: Store.luckysheetTableContentHW[0], height: Store.luckysheetTableContentHW[1] });
@ -313,15 +313,15 @@ export function changeSheetContainerSize(gridW, gridH){
.end() .end()
.find(".luckysheet-freezebar-vertical-drop") .find(".luckysheet-freezebar-vertical-drop")
.css({ "height": gridheight - 10 }); .css({ "height": gridheight - 10 });
luckysheetFreezen.createAssistCanvas(); luckysheetFreezen.createAssistCanvas();
} }
/** /**
* *
* *
* Toolbar judgment rules: First set the display and hide of all tool buttons according to showtoolbar, and then override the judgment of showtoolbar according to showtoolbarConfig rules * Toolbar judgment rules: First set the display and hide of all tool buttons according to showtoolbar, and then override the judgment of showtoolbar according to showtoolbarConfig rules
* *
* The width value of each button in the statistics toolbar is used to calculate which needs to be placed in more buttons * The width value of each button in the statistics toolbar is used to calculate which needs to be placed in more buttons
*/ */
export function menuToolBarWidth() { export function menuToolBarWidth() {
@ -331,10 +331,10 @@ export function menuToolBarWidth() {
const toobarWidths = Store.toobarObject.toobarWidths = []; const toobarWidths = Store.toobarObject.toobarWidths = [];
const toobarElements = Store.toobarObject.toobarElements = []; const toobarElements = Store.toobarObject.toobarElements = [];
const toolbarConfig = Store.toobarObject.toolbarConfig = buildBoolBarConfig(); const toolbarConfig = Store.toobarObject.toolbarConfig = buildBoolBarConfig();
/** /**
* 基于 showtoolbarConfig 配置 动态生成 toolbarConfig * 基于 showtoolbarConfig 配置 动态生成 toolbarConfig
* @returns {object} * @returns {object}
* @input showtoolbarConfig = ['undo', 'redo', '|' , 'font' , 'moreFormats', '|'] * @input showtoolbarConfig = ['undo', 'redo', '|' , 'font' , 'moreFormats', '|']
* { * {
* undo: {ele: '#luckysheet-icon-undo', index: 0}, * undo: {ele: '#luckysheet-icon-undo', index: 0},
@ -388,20 +388,19 @@ export function menuToolBarWidth() {
config[s] = false; config[s] = false;
} }
} }
if (JSON.stringify(showtoolbarConfig) !== '{}') { if (JSON.stringify(showtoolbarConfig) !== '{}') {
if(showtoolbarConfig.hasOwnProperty('undoRedo')){ if(showtoolbarConfig.hasOwnProperty('undoRedo')){
config.undo = config.redo = showtoolbarConfig.undoRedo; config.undo = config.redo = showtoolbarConfig.undoRedo;
delete showtoolbarConfig.undoRedo;
} }
Object.assign(config, showtoolbarConfig); Object.assign(config, showtoolbarConfig);
let current,next; let current,next;
let index = 0; let index = 0;
for (let i = 0; i<defaultToolbar.length; i++) { for (let i = 0; i<defaultToolbar.length; i++) {
current = defaultToolbar[i]; current = defaultToolbar[i];
next = defaultToolbar[i + 1]; next = defaultToolbar[i + 1];
if (current !== '|') { if (current !== '|' && config[current]) {
obj[current] = { obj[current] = {
ele: toolbarIdMap[current], ele: toolbarIdMap[current],
index: index++ index: index++
@ -464,7 +463,7 @@ export function menuToolBarWidth() {
toobarWidths.forEach((item,i)=>{ toobarWidths.forEach((item,i)=>{
toobarWidths[i] -= containerLeft; toobarWidths[i] -= containerLeft;
}) })
} }
/** /**
@ -481,18 +480,18 @@ function customSheetbarConfig() {
menu: true, //Worksheet management menu menu: true, //Worksheet management menu
sheet: true //Worksheet display sheet: true //Worksheet display
} }
if(!luckysheetConfigsetting.showsheetbar){ if(!luckysheetConfigsetting.showsheetbar){
for(let s in config){ for(let s in config){
config[s] = false; config[s] = false;
} }
} }
// showsheetbarConfig determines the final result // showsheetbarConfig determines the final result
if(JSON.stringify(luckysheetConfigsetting.showsheetbarConfig) !== '{}'){ if(JSON.stringify(luckysheetConfigsetting.showsheetbarConfig) !== '{}'){
Object.assign(config,luckysheetConfigsetting.showsheetbarConfig); Object.assign(config,luckysheetConfigsetting.showsheetbarConfig);
} }
luckysheetConfigsetting.showsheetbarConfig = config; luckysheetConfigsetting.showsheetbarConfig = config;
} }
@ -508,19 +507,19 @@ function customSheetbarConfig() {
$('#luckysheet-sheets-add').hide(); $('#luckysheet-sheets-add').hide();
isHide++; isHide++;
break; break;
case 'menu': case 'menu':
$('#luckysheet-sheets-m').hide(); $('#luckysheet-sheets-m').hide();
isHide++; isHide++;
break; break;
case 'sheet': case 'sheet':
$('#luckysheet-sheet-container').hide(); $('#luckysheet-sheet-container').hide();
$('#luckysheet-sheets-leftscroll').hide(); $('#luckysheet-sheets-leftscroll').hide();
$('#luckysheet-sheets-rightscroll').hide(); $('#luckysheet-sheets-rightscroll').hide();
isHide++; isHide++;
break; break;
default: default:
break; break;
} }
@ -551,18 +550,18 @@ function customStatisticBarConfig() {
view: true, // print view view: true, // print view
zoom: true // Zoom zoom: true // Zoom
} }
if(!luckysheetConfigsetting.showstatisticBar){ if(!luckysheetConfigsetting.showstatisticBar){
for(let s in config){ for(let s in config){
config[s] = false; config[s] = false;
} }
} }
// showstatisticBarConfig determines the final result // showstatisticBarConfig determines the final result
if(JSON.stringify(luckysheetConfigsetting.showstatisticBarConfig) !== '{}'){ if(JSON.stringify(luckysheetConfigsetting.showstatisticBarConfig) !== '{}'){
Object.assign(config,luckysheetConfigsetting.showstatisticBarConfig); Object.assign(config,luckysheetConfigsetting.showstatisticBarConfig);
} }
luckysheetConfigsetting.showstatisticBarConfig = config; luckysheetConfigsetting.showstatisticBarConfig = config;
} }
@ -578,7 +577,7 @@ function customStatisticBarConfig() {
$('#luckysheet-sta-content').hide(); $('#luckysheet-sta-content').hide();
isHide++; isHide++;
break; break;
case 'view': case 'view':
$('.luckysheet-print-viewList').hide(); $('.luckysheet-print-viewList').hide();
isHide++; isHide++;
@ -588,7 +587,7 @@ function customStatisticBarConfig() {
$('#luckysheet-zoom-content').hide(); $('#luckysheet-zoom-content').hide();
isHide++; isHide++;
break; break;
default: default:
break; break;
} }
@ -603,4 +602,4 @@ function customStatisticBarConfig() {
$("#" + Store.container).find(".luckysheet-stat-area").show(); $("#" + Store.container).find(".luckysheet-stat-area").show();
Store.statisticBarHeight = 23; Store.statisticBarHeight = 23;
} }
} }

1
src/controllers/toolbar.js

@ -873,7 +873,6 @@ export function createToolbarHtml() {
if (JSON.stringify(showtoolbarConfig) !== '{}') { if (JSON.stringify(showtoolbarConfig) !== '{}') {
if(showtoolbarConfig.hasOwnProperty('undoRedo')){ if(showtoolbarConfig.hasOwnProperty('undoRedo')){
config.undo = config.redo = showtoolbarConfig.undoRedo; config.undo = config.redo = showtoolbarConfig.undoRedo;
delete showtoolbarConfig.undoRedo;
} }
Object.assign(config, showtoolbarConfig); Object.assign(config, showtoolbarConfig);
} }

Loading…
Cancel
Save