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 { defaultToolbar, toolbarIdMap } from './toolbar';
let gridW = 0,
let gridW = 0,
gridH = 0;
export default function luckysheetsizeauto(isRefreshCanvas=true) {
@ -41,7 +41,7 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
// Store.sheetBarHeight = 31;
// }
customSheetbarConfig();
// if (!luckysheetConfigsetting.showstatisticBar) {
@ -73,7 +73,7 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
if(luckysheetConfigsetting.showConfigWindowResize){//数据透视表 图表 交替颜色 Protection
if($("#luckysheet-modal-dialog-slider-pivot").is(":visible")){
gridW -= $("#luckysheet-modal-dialog-slider-pivot").outerWidth();
}
}
else if($(".chartSetting").is(":visible")){
gridW -= $(".chartSetting").outerWidth();
}
@ -82,12 +82,12 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
}
if($("#luckysheet-modal-dialog-slider-protection").is(":visible")){
gridW -= $("#luckysheet-modal-dialog-slider-protection").outerWidth();
}
}
}
const _locale = locale();
const locale_toolbar = _locale.toolbar;
let ismore = false,
let ismore = false,
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;">
<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>`,
// 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>';
if($("#luckysheet-icon-morebtn-div").length == 0){
$("body").append(morediv);
}
@ -116,7 +116,7 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
$("#luckysheet-icon-morebtn-div > div").each(function(){
const $t = $(this)[0];
const $container = $("#luckysheet-wa-editor")[0];
$container.appendChild(document.createTextNode(" "));
$container.appendChild($t);
});
@ -155,11 +155,11 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
}else{
$("#luckysheet-icon-morebtn-div").append($(`${element}`));
}
}
if(ismore){
$("#luckysheet-wa-editor").append(morebtn);
$("#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();
// $("#luckysheet-icon-morebtn-div").toggle().css("right", right < 0 ? 0 : right);
// use native js operation
$$('#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);
}
});
//$("#luckysheet-wa-editor div").trigger("create");
// $("#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);
@ -235,7 +235,7 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
// tooltip
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(){
$(this).next(".luckysheet-toolbar-button-split-right").addClass("luckysheet-toolbar-button-split-right-hover");
}, function(){
@ -254,7 +254,7 @@ export default function luckysheetsizeauto(isRefreshCanvas=true) {
$("#" + Store.container).find(".luckysheet").height(gridH - 2).width(gridW - 2);
changeSheetContainerSize(gridW, gridH)
if(isRefreshCanvas){
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.cellmainWidth = gridW - Store.rowHeaderWidth;
$("#luckysheet-cols-h-c, #luckysheet-cell-main").width(Store.cellmainWidth);
$("#luckysheet-cell-main").height(Store.cellmainHeight);
$("#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);
Store.luckysheetTableContentHW = [
Store.cellmainWidth + Store.rowHeaderWidth - Store.cellMainSrollBarSize,
Store.cellmainWidth + Store.rowHeaderWidth - Store.cellMainSrollBarSize,
Store.cellmainHeight + Store.columnHeaderHeight - Store.cellMainSrollBarSize
];
$("#luckysheetTableContent, #luckysheetTableContentF").attr({
width: Math.ceil(Store.luckysheetTableContentHW[0] * Store.devicePixelRatio),
height: Math.ceil(Store.luckysheetTableContentHW[1] * Store.devicePixelRatio)
$("#luckysheetTableContent, #luckysheetTableContentF").attr({
width: Math.ceil(Store.luckysheetTableContentHW[0] * Store.devicePixelRatio),
height: Math.ceil(Store.luckysheetTableContentHW[1] * Store.devicePixelRatio)
})
.css({ width: Store.luckysheetTableContentHW[0], height: Store.luckysheetTableContentHW[1] });
@ -313,15 +313,15 @@ export function changeSheetContainerSize(gridW, gridH){
.end()
.find(".luckysheet-freezebar-vertical-drop")
.css({ "height": gridheight - 10 });
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
*
*
* 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() {
@ -331,10 +331,10 @@ export function menuToolBarWidth() {
const toobarWidths = Store.toobarObject.toobarWidths = [];
const toobarElements = Store.toobarObject.toobarElements = [];
const toolbarConfig = Store.toobarObject.toolbarConfig = buildBoolBarConfig();
/**
* 基于 showtoolbarConfig 配置 动态生成 toolbarConfig
* @returns {object}
* @returns {object}
* @input showtoolbarConfig = ['undo', 'redo', '|' , 'font' , 'moreFormats', '|']
* {
* undo: {ele: '#luckysheet-icon-undo', index: 0},
@ -388,20 +388,19 @@ export function menuToolBarWidth() {
config[s] = false;
}
}
if (JSON.stringify(showtoolbarConfig) !== '{}') {
if(showtoolbarConfig.hasOwnProperty('undoRedo')){
config.undo = config.redo = showtoolbarConfig.undoRedo;
delete showtoolbarConfig.undoRedo;
}
Object.assign(config, showtoolbarConfig);
let current,next;
let index = 0;
for (let i = 0; i<defaultToolbar.length; i++) {
current = defaultToolbar[i];
next = defaultToolbar[i + 1];
if (current !== '|') {
if (current !== '|' && config[current]) {
obj[current] = {
ele: toolbarIdMap[current],
index: index++
@ -464,7 +463,7 @@ export function menuToolBarWidth() {
toobarWidths.forEach((item,i)=>{
toobarWidths[i] -= containerLeft;
})
}
/**
@ -481,18 +480,18 @@ function customSheetbarConfig() {
menu: true, //Worksheet management menu
sheet: true //Worksheet display
}
if(!luckysheetConfigsetting.showsheetbar){
for(let s in config){
config[s] = false;
}
}
// showsheetbarConfig determines the final result
if(JSON.stringify(luckysheetConfigsetting.showsheetbarConfig) !== '{}'){
Object.assign(config,luckysheetConfigsetting.showsheetbarConfig);
}
luckysheetConfigsetting.showsheetbarConfig = config;
}
@ -508,19 +507,19 @@ function customSheetbarConfig() {
$('#luckysheet-sheets-add').hide();
isHide++;
break;
case 'menu':
$('#luckysheet-sheets-m').hide();
isHide++;
break;
case 'sheet':
$('#luckysheet-sheet-container').hide();
$('#luckysheet-sheets-leftscroll').hide();
$('#luckysheet-sheets-rightscroll').hide();
isHide++;
break;
default:
break;
}
@ -551,18 +550,18 @@ function customStatisticBarConfig() {
view: true, // print view
zoom: true // Zoom
}
if(!luckysheetConfigsetting.showstatisticBar){
for(let s in config){
config[s] = false;
}
}
// showstatisticBarConfig determines the final result
if(JSON.stringify(luckysheetConfigsetting.showstatisticBarConfig) !== '{}'){
Object.assign(config,luckysheetConfigsetting.showstatisticBarConfig);
}
luckysheetConfigsetting.showstatisticBarConfig = config;
}
@ -578,7 +577,7 @@ function customStatisticBarConfig() {
$('#luckysheet-sta-content').hide();
isHide++;
break;
case 'view':
$('.luckysheet-print-viewList').hide();
isHide++;
@ -588,7 +587,7 @@ function customStatisticBarConfig() {
$('#luckysheet-zoom-content').hide();
isHide++;
break;
default:
break;
}
@ -603,4 +602,4 @@ function customStatisticBarConfig() {
$("#" + Store.container).find(".luckysheet-stat-area").show();
Store.statisticBarHeight = 23;
}
}
}

1
src/controllers/toolbar.js

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

Loading…
Cancel
Save