import locale from '../locale/locale'; import luckysheetConfigsetting from './luckysheetConfigsetting'; import { getObjType, camel2split } from '../utils/util'; // 默认的工具栏按钮 export const defaultToolbar = [ 'undo', 'redo', 'paintFormat', '|', 'currencyFormat', 'percentageFormat', 'numberDecrease', 'numberIncrease', 'moreFormats', '|', 'font', '|', 'fontSize', '|', 'bold', 'italic', 'strikethrough', 'underline', 'textColor', '|', 'fillColor', 'border', 'mergeCell', '|', 'horizontalAlignMode', 'verticalAlignMode', 'textWrapMode', 'textRotateMode', '|', 'image', 'link', 'chart', 'postil', 'pivotTable', '|', 'function', 'frozenMode', 'sortAndFilter', 'conditionalFormat', 'dataVerification', 'splitColumn', 'screenshot', 'findAndReplace', 'protection', 'print' ]; // 工具栏按钮 id 关系 export const toolbarIdMap = { undo: '#luckysheet-icon-undo', //Undo redo redo: '#luckysheet-icon-redo', paintFormat: ['#luckysheet-icon-paintformat'], //Format brush currencyFormat: '#luckysheet-icon-currency', //currency format percentageFormat: '#luckysheet-icon-percent', //Percentage format numberDecrease: '#luckysheet-icon-fmt-decimal-decrease', //'Decrease the number of decimal places' numberIncrease: '#luckysheet-icon-fmt-decimal-increase', //'Increase the number of decimal places moreFormats: '#luckysheet-icon-fmt-other', //'More Formats' font: '#luckysheet-icon-font-family', //'font' fontSize: '#luckysheet-icon-font-size', //'Font size' bold: '#luckysheet-icon-bold', //'Bold (Ctrl+B)' italic: '#luckysheet-icon-italic', //'Italic (Ctrl+I)' strikethrough: '#luckysheet-icon-strikethrough', //'Strikethrough (Alt+Shift+5)' underline: '#luckysheet-icon-underline', //'Underline (Alt+Shift+6)' textColor: ['#luckysheet-icon-text-color', '#luckysheet-icon-text-color-menu'], //'Text color' fillColor: ['#luckysheet-icon-cell-color', '#luckysheet-icon-cell-color-menu'], //'Cell color' border: ['#luckysheet-icon-border-all', '#luckysheet-icon-border-menu'], //'border' mergeCell: ['#luckysheet-icon-merge-button', '#luckysheet-icon-merge-menu'], //'Merge cells' horizontalAlignMode: ['#luckysheet-icon-align', '#luckysheet-icon-align-menu'], //'Horizontal alignment' verticalAlignMode: ['#luckysheet-icon-valign', '#luckysheet-icon-valign-menu'], //'Vertical alignment' textWrapMode: ['#luckysheet-icon-textwrap', '#luckysheet-icon-textwrap-menu'], //'Wrap mode' textRotateMode: ['#luckysheet-icon-rotation', '#luckysheet-icon-rotation-menu'], //'Text Rotation Mode' image: '#luckysheet-insertImg-btn-title', //'Insert link' link: '#luckysheet-insertLink-btn-title', //'Insert picture' chart: '#luckysheet-chart-btn-title', //'chart' (the icon is hidden, but if the chart plugin is configured, you can still create a new chart by right click) postil: '#luckysheet-icon-postil', //'comment' pivotTable: ['#luckysheet-pivot-btn-title'], //'PivotTable' function: ['#luckysheet-icon-function', '#luckysheet-icon-function-menu'], //'formula' frozenMode: ['#luckysheet-freezen-btn-horizontal', '#luckysheet-icon-freezen-menu'], //'freeze mode' sortAndFilter: '#luckysheet-icon-autofilter', //'sort and filter' conditionalFormat: '#luckysheet-icon-conditionformat', //'Conditional Format' dataVerification: '#luckysheet-dataVerification-btn-title', // 'Data Verification' splitColumn: '#luckysheet-splitColumn-btn-title', //'Split column' screenshot: '#luckysheet-chart-btn-screenshot', //'screenshot' findAndReplace: '#luckysheet-icon-seachmore', //'Find and Replace' protection: '#luckysheet-icon-protection', // 'Worksheet protection' print: '#luckysheet-icon-print' // 'print' }; // 创建工具栏按钮的html export function createToolbarHtml() { const toolbar = locale().toolbar; const fontarray = locale().fontarray; const defaultFmtArray = locale().defaultFmt; const htmlMap = { undo: `
`, redo: ` `, paintFormat: ` `, currencyFormat: ` `, percentageFormat: ` `, //Percentage format numberDecrease: ` `, //'Decrease the number of decimal places' numberIncrease: ` `, //'Increase the number of decimal places moreFormats: ` `, //'More Formats' font: ` `, //'font' fontSize: ` `, //'Font size' bold: ` `, //'Bold (Ctrl+B)' italic: ` `, //'Italic (Ctrl+I)' strikethrough: ` `, //'Strikethrough (Alt+Shift+5)' underline: ` `, //'Underline (Alt+Shift+6)' textColor: ` `, //'Text color' fillColor: ` `, //'Cell color' border: ` `, //'border' mergeCell: ` `, //'Merge cells' horizontalAlignMode: ` `, //'Horizontal alignment' verticalAlignMode: ` `, //'Vertical alignment' textWrapMode: ` `, //'Wrap mode' textRotateMode: ` `, //'Text Rotation Mode' image: ` `, // 'Insert picture' link: ` `, // 'Insert link'(TODO) chart: ` `, //'chart' (the icon is hidden, but if the chart plugin is configured, you can still create a new chart by right click) postil: ` `, //'comment' pivotTable: ` `, //'PivotTable' function: ` `, //'formula' frozenMode: ` `, //'freeze mode' sortAndFilter: ` `, //'Sort and filter' conditionalFormat: ` `, //'Conditional Format' dataVerification: ` `, // 'Data Verification' splitColumn: ` `, //'Split column' screenshot: ` `, //'screenshot' findAndReplace: ` `, //'Find and Replace' protection: ` `, // 'Worksheet protection' print: ` ` // 'print' }; const showtoolbar = luckysheetConfigsetting.showtoolbar; const showtoolbarConfig = luckysheetConfigsetting.showtoolbarConfig; const buttonHTML = ['']; // 数组形式直接生成 if (getObjType(showtoolbarConfig) === 'array') { // 此时不根据 showtoolbar=false,showtoolbarConfig为某几个进行适配,此时showtoolbarConfig本身就是全部要显示的按钮 if (!showtoolbar) { return ''; } let i = 0; showtoolbarConfig.forEach(function(key, i) { if (key === '|') { const nameKeys = showtoolbarConfig[i - 1] if(nameKeys !== '|') { buttonHTML.push( `` ); } } else { buttonHTML.push(htmlMap[key]); } }); return buttonHTML.join(''); } const config = defaultToolbar.reduce(function(total, curr) { if (curr !== '|') { total[curr] = true; } return total; }, {}); if (!showtoolbar) { for (let s in config) { config[s] = false; } } // 对象模式 则从里面挑选 true 保留 false 删掉 if (JSON.stringify(showtoolbarConfig) !== '{}') { if(showtoolbarConfig.hasOwnProperty('undoRedo')){ config.undo = config.redo = showtoolbarConfig.undoRedo; } Object.assign(config, showtoolbarConfig); } for (let i = 0; i < defaultToolbar.length; i++) { let key = defaultToolbar[i]; if (!config[key] && key !== '|') { // 如果当前元素隐藏 按照之前的规则 后面紧跟的 | 分割也不需要显示了 if (defaultToolbar[i + 1] === '|') { i++; } continue; } if (key === '|') { const nameKeys = defaultToolbar[i - 1] if(nameKeys !== '|') { buttonHTML.push( `` ); } } else { buttonHTML.push(htmlMap[key]); } } return buttonHTML.join(''); }