意思是右键菜单的显示,是通过动态传参数去控制的。
下面是我的
控制逻辑
//如果满足禁用条件,设置菜单禁用
if(a<b){
spread.contextMenu = onOpenMenu(false, false, false, false, false, false, false);
}else{ //否则都可以操作
spread.contextMenu = onOpenMenu();
}
/**
* 控制右键菜单总的方法
* @param copy 复制
* @param cut 粘贴
* @param allowInsertRows 是否能插入行
* @param allowDeleteRows 是否能删除行
* @param allowInsertColumns 是否能插入列
* @param allowDeleteColumns 是否能删除列
* @param clearContents 清除
*/
function onOpenMenu(copy = true, cut = true, allowInsertRows = true, allowDeleteRows = true, allowInsertColumns = true, allowDeleteColumns = true, clearContents = true) {
function MyContextMenu() {}
MyContextMenu.prototype = new GC.Spread.Sheets.ContextMenu.ContextMenu(spread);
MyContextMenu.prototype.onOpenMenu = (menuData, itemsDataForShown, hitInfo, spread) => {
console.log('是否可复制',copy);
console.log(itemsDataForShown);
itemsDataForShown.forEach((item, index) => {
switch (item && item.name) {
case 'gc.spread.copy':
item.disable = !copy;
break;
case 'gc.spread.cut':
item.disable = !cut;
break;
case 'gc.spread.insertRows':
item.disable = !allowInsertRows;
break;
case 'gc.spread.deleteRows':
item.disable = !allowDeleteRows;
break;
case 'gc.spread.clearContents':
item.disable = !clearContents;
break;
case 'gc.spread.insertColumns':
item.disable = !allowInsertColumns;
break;
case 'gc.spread.deleteColumns':
item.disable = !allowDeleteColumns;
break;
}
});
};
let contextMenu = new MyContextMenu();
return contextMenu
} |