Browse Source

fix: 修复重构工具栏配置后不传 showtoolbar showtoolbarConfig 时的bug

master
cdswyda 4 years ago
parent
commit
4dd527b6cf
  1. 34
      src/controllers/resize.js
  2. 22
      src/controllers/toolbar.js
  3. 13
      src/utils/util.js

34
src/controllers/resize.js

@ -5,7 +5,7 @@ import Store from '../store';
import locale from '../locale/locale'; import locale from '../locale/locale';
import sheetmanage from './sheetmanage'; import sheetmanage from './sheetmanage';
import tooltip from '../global/tooltip' import tooltip from '../global/tooltip'
import { $$, getObjType } 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,
@ -344,18 +344,14 @@ export function menuToolBarWidth() {
* } * }
*/ */
function buildBoolBarConfig() { function buildBoolBarConfig() {
let obj = {};
function array2Config(arr) {
const obj = {}; const obj = {};
// 数组形式直接生成
if (getObjType(showtoolbarConfig) === 'array') {
// show 为 false
if (!showtoolbar) {
return obj;
}
let current,next; let current,next;
let index = 0; let index = 0;
for (let i = 0; i<showtoolbarConfig.length; i++) { for (let i = 0; i<arr.length; i++) {
current = showtoolbarConfig[i]; current = arr[i];
next = showtoolbarConfig[i + 1]; next = arr[i + 1];
if (current !== '|') { if (current !== '|') {
obj[current] = { obj[current] = {
ele: toolbarIdMap[current], ele: toolbarIdMap[current],
@ -364,14 +360,22 @@ export function menuToolBarWidth() {
} }
if (next === '|') { if (next === '|') {
if (getObjType(obj[current].ele) === 'array') { if (getObjType(obj[current].ele) === 'array') {
obj[current].ele.push(`#toolbar-separator-${current.toLowerCase()}`); obj[current].ele.push(`#toolbar-separator-${camel2split(current)}`);
} else { } else {
obj[current].ele = [obj[current].ele, `#toolbar-separator-${current.toLowerCase()}`]; obj[current].ele = [obj[current].ele, `#toolbar-separator-${camel2split(current)}`];
}
} }
} }
return obj;
} }
// 数组形式直接生成
if (getObjType(showtoolbarConfig) === 'array') {
// show 为 false
if (!showtoolbar) {
return obj; return obj;
} }
return array2Config(showtoolbarConfig);
}
// 否则为全部中从记录中挑选显示或隐藏 // 否则为全部中从记录中挑选显示或隐藏
const config = defaultToolbar.reduce(function(total, curr) { const config = defaultToolbar.reduce(function(total, curr) {
if (curr !== '|') { if (curr !== '|') {
@ -405,12 +409,14 @@ export function menuToolBarWidth() {
} }
if (next === '|') { if (next === '|') {
if (getObjType(obj[current].ele) === 'array') { if (getObjType(obj[current].ele) === 'array') {
obj[current].ele.push(`#toolbar-separator-${current.toLowerCase()}`); obj[current].ele.push(`#toolbar-separator-${camel2split(current)}`);
} else { } else {
obj[current].ele = [obj[current].ele, `#toolbar-separator-${current.toLowerCase()}`]; obj[current].ele = [obj[current].ele, `#toolbar-separator-${camel2split(current)}`];
} }
} }
} }
} else {
obj = array2Config(defaultToolbar);
} }
return obj; return obj;

22
src/controllers/toolbar.js

@ -1,7 +1,7 @@
import locale from '../locale/locale'; import locale from '../locale/locale';
import luckysheetConfigsetting from './luckysheetConfigsetting'; import luckysheetConfigsetting from './luckysheetConfigsetting';
import { getObjType } from '../utils/util'; import { getObjType, camel2split } from '../utils/util';
// 默认的工具栏按钮 // 默认的工具栏按钮
export const defaultToolbar = [ export const defaultToolbar = [
@ -876,15 +876,15 @@ export function createToolbarHtml() {
delete showtoolbarConfig.undoRedo; delete showtoolbarConfig.undoRedo;
} }
Object.assign(config, showtoolbarConfig); Object.assign(config, showtoolbarConfig);
}
for (let i = 0; i < defaultToolbar.length; i++) { for (let i = 0; i < defaultToolbar.length; i++) {
let key = defaultToolbar[i]; let key = defaultToolbar[i];
if (!config[key]) { if (!config[key] && key !== '|') {
// 如果当前元素隐藏 按照之前的规则 后面紧跟的 | 分割也不需要显示了 // 如果当前元素隐藏 按照之前的规则 后面紧跟的 | 分割也不需要显示了
if (defaultToolbar[i + 1] === '|') { if (defaultToolbar[i + 1] === '|') {
i++; i++;
} }
return; continue;
} }
if (key === '|') { if (key === '|') {
buttonHTML.push( buttonHTML.push(
@ -894,18 +894,6 @@ export function createToolbarHtml() {
buttonHTML.push(htmlMap[key]); buttonHTML.push(htmlMap[key]);
} }
} }
} console.log(buttonHTML);
return buttonHTML.join(''); return buttonHTML.join('');
} }
/**
* camel 形式的单词转换为 - 形式 fillColor -> fill-color
* @param {string} camel camel 形式
* @returns
*/
function camel2split(camel) {
return camel.replace(/([A-Z])/g, function(all, group) {
return '-' + group.toLowerCase();
});
}

13
src/utils/util.js

@ -871,6 +871,16 @@ function arrayRemoveItem(array, item) {
}) })
} }
/**
* camel 形式的单词转换为 - 形式 fillColor -> fill-color
* @param {string} camel camel 形式
* @returns
*/
function camel2split(camel) {
return camel.replace(/([A-Z])/g, function(all, group) {
return '-' + group.toLowerCase();
});
}
export { export {
isJsonString, isJsonString,
@ -900,5 +910,6 @@ export {
transformRangeToAbsolute, transformRangeToAbsolute,
openSelfModel, openSelfModel,
createProxy, createProxy,
arrayRemoveItem arrayRemoveItem,
camel2split
} }
Loading…
Cancel
Save