本身是直接在工具栏直接进行按钮的添加,某些情况会不触发,使用的是官方的写法
//初始化自定义Tab
initRibbon() {
_this.config = GC.Spread.Sheets.Designer.DefaultConfig;
let configTab = GC.Spread.Sheets.Designer.DefaultConfig;
if (configTab.ribbon[0].buttonGroups[7]) {
let editFirstElement =
configTab.ribbon[0].buttonGroups[7].commandGroup.children[0]
.children[2];
let edit = configTab.ribbon[0].buttonGroups[7];
edit.commandGroup = editFirstElement;
_this.config.ribbon[4].buttonGroups.push(edit);
}
// add new tab
let newTab = {
id: "operate",
text: "自定义",
buttonGroups: [],
};
if (
Array.isArray(_this.config && _this.config.ribbon) &&
!_this.config.ribbon.filter((d) => d && d.text === "自定义").length
) {
_this.config.ribbon.unshift(newTab);
let dataSaveInfo = {};
if (
localStorage.getItem("se_oss_authority") &&
JSON.parse(localStorage.getItem("se_oss_authority")).indexOf(
"MY_REPORT_SUBMIT"
) !== -1
) {
dataSaveInfo.release = {
iconClass: "ribbon-button-save", //按钮的样式
text: "发布", //显示的文字
bigButton: true,
commandName: "reportRelease", //命令名称,需要全局唯一
execute: this.reportRelease, //对应执行内容的function
};
}
//创建按钮
dataSaveInfo = Object.assign(dataSaveInfo, {
exit: {
iconClass: "ribbon-button-save", //按钮的样式
text: "退出",
bigButton: true,
commandName: "exitReport",
execute: this.exitReport,
},
saveTemplateCommand: {
iconClass: "ribbon-button-save", //按钮的样式
text: "保存", //显示的文字
bigButton: true,
commandName: "saveDatas", //命令名称,需要全局唯一
execute: this.saveInfos, //对应执行内容的function
},
relateMutCheck: {
iconClass: "ribbon-button-save", //按钮的样式
text: "多选其他关联",
bigButton: true,
commandName: "relateMutCheck",
execute: this.relateMutCheck,
},
reWrite: {
iconClass: "ribbon-button-save", //按钮的样式
text: "自动回填", //显示的文字
bigButton: true,
commandName: "reWriteBtn", //命令名称,需要全局唯一
execute: this.reWriteBtn, //对应执行内容的function
},
overReWrite: {
iconClass: "ribbon-button-save", //按钮的样式
text: "取消自动回填", //显示的文字
bigButton: true,
commandName: "overReWriteBtn", //命令名称,需要全局唯一
execute: this.overReWriteBtn, //对应执行内容的function
},
childrenDropdown: {
commandName: "childrenDropdown",
text: "校验规则",
title: "Children",
iconClass: "ribbon-button-welcome",
bigButton: "true",
// direction: "vertical",
},
childrenDropdown2: {
title: "设置正则",
text: "设置正则",
iconClass: "ribbon-button-welcome",
commandName: "childrenDropdown2",
execute: function (context, propertyName, fontItalicChecked) {
_this.diaMode = "reg";
_this.dialogVisible = true;
// let spread = context.Spread; //获取工作簿
// let activeCell = _this.getCell(); //获取激活单元格
// let sheet = _this.getActiveSheet(); //获取工作表
// let style = new GC.Spread.Sheets.Style();
// style.locked = false;
// style.backColor = "#C3C3C3";
// sheet.setStyle(activeCell.row, activeCell.col, style);
},
},
ruleSource: {
title: "多选框校验",
text: "多选框校验",
iconClass: "ruleSource",
commandName: "ruleSource",
execute: this.ruleSources,
},
resetDataSourceList: {
title: "清除所选数据",
text: "清除所选数据",
iconClass: "resetDataSourceList",
commandName: "resetDataSourceList",
execute: this.resetDSList,
},
});
//将图标放入工具栏
if (
!_this.config.ribbon[0].buttonGroups[0] ||
(!(_this.config.ribbon[0].buttonGroups[0].label === "保存设计") &&
!_this.config.ribbon[0].buttonGroups.filter(
(d) => d.label === "保存设计"
).length)
) {
_this.config.ribbon[0].buttonGroups.unshift({
label: "常用操作",
thumbnailClass: "ribbon-thumbnail-spreadsettings",
commandGroup: {
children: [
{
direction: "vertical",
commands: ["saveTemplateCommand"],
},
{
type: "separator",
},
{
direction: "vertical",
commands: ["release"],
},
{
type: "separator",
},
{
direction: "vertical",
commands: ["exit"],
},
{
type: "separator",
},
{
direction: "vertical",
commands: ["relateMutCheck"],
},
{
type: "separator",
},
{
direction: "vertical",
commands: ["reWrite"],
},
{
type: "separator",
},
{
direction: "vertical",
commands: ["overReWrite"],
},
{
type: "separator",
},
{
command: "childrenDropdown", //父命令可以有自己的execute,点击执行;也可以没有,点击弹出children
type: "dropdown",
children: [
// "childrenDropdown1",
"childrenDropdown2",
"ruleSource",
// "resetDataSourceList",
],
},
{
type: "separator",
},
],
},
});
}
_this.config.commandMap = {};
Object.assign(_this.config.commandMap, dataSaveInfo);
}
return _this.config;
}, |