4金币
通过重写onOpenMenu的方式给右键菜单添加项,但原来右键菜单的部分展示项隐藏了,在这个demo基础上怎么修改能实现:不影响原始右键菜单展示的情况下添加项
<template>
<div id="app">
<gc-spread-sheets-designer
:styleInfo="styleInfo"
:config="config"
:spreadOptions="spreadOptions"
@designerInitialized="designerInitialized"
>
</gc-spread-sheets-designer>
</div>
</template>
<script>
import "@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css";
import "@grapecity/spread-sheets-designer/styles/gc.spread.sheets.designer.min.css";
import * as GC from "@grapecity/spread-sheets";
import "@grapecity/spread-sheets-print";
import "@grapecity/spread-sheets-shapes";
import "@grapecity/spread-sheets-pivot-addon";
import "@grapecity/spread-sheets-tablesheet";
import "@grapecity/spread-sheets-resources-zh";
GC.Spread.Common.CultureManager.culture("zh-cn");
import "@grapecity/spread-sheets-designer-resources-cn";
import "./custom.css";
import * as ExcelIO from "@grapecity/spread-excelio";
//Apply License
//GC.Spread.Sheets.LicenseKey = 'sjs-distribution-key';
//ExcelIO.LicenseKey = 'sjs-distribution-key';
//GC.Spread.Sheets.Designer.LicenseKey = 'designer-component-distribution-key';
import { Designer } from "@grapecity/spread-sheets-designer-vue";
export default {
name: "App",
data: function() {
var config = GC.Spread.Sheets.Designer.DefaultConfig;
config.commandMap = {
Welcome: {
title: "Welcome",
text: "Welcome",
iconClass: "ribbon-button-welcome",
bigButton: "true",
commandName: "Welcome",
execute: async (context, propertyName, fontItalicChecked) => {
alert("Welcome to new designer.");
}
}
};
config.ribbon[0].buttonGroups.unshift({
label: "NewDesigner",
thumbnailClass: "welcome",
commandGroup: {
children: [
{
direction: "vertical",
commands: ["Welcome"]
}
// This is custom button ----------------end-------------
]
}
});
return {
styleInfo: { height: "98vh", width: "100%" },
config: config,
spreadOptions: {
sheetCount: 2
},
designer: null,
spread: null
};
},
methods: {
designerInitialized(value) {
this.designer = value;
this.spread = this.designer.getWorkbook();
// this.registerCommand();
// this.customContextMenu();
},
registerCommand() {
const myCmd = {
canUndo: true,
name: "myCmd",
execute: (context, options, isUndo) => {
alert("add_table_command");
}
};
this.spread.commandManager().register("myCmd", myCmd);
},
customContextMenu() {
function MyContextMenu() {}
MyContextMenu.prototype = new GC.Spread.Sheets.ContextMenu.ContextMenu();
MyContextMenu.prototype.onOpenMenu = function(
menuData,
itemsDataForShown,
hitInfo
) {
itemsDataForShown.push({
text: "菜单测试",
name: "myCmd",
command: "myCmd",
workArea: "viewport"
});
};
const contextMenu = new MyContextMenu();
this.spread.contextMenu = contextMenu;
}
}
};
</script>
<style></style>
|
最佳答案
查看完整内容
可以是可以,但是会导致你现在碰到的情况,你要想保留designer原有的菜单结构,就得改成designer自定义右键的写法
下面是spread和designer初始的右键菜单:
spread:
designer:
|