spread.contextMenu.onOpenMenu = function (
menuData,
itemsDataForShown,
hitInfo,
spread
) {
console.log(itemsDataForShown);
let itemMenu = itemsDataForShown
const selections = spread.getSheetFromName(element.sheetName).getSelections();
if (selections[0].row !== -1) {
oldOpenMenu.apply(this, [
menuData,
itemsDataForShown,
hitInfo,
spread,
]);
}
// 根据isAllowEdit判断菜单禁用问题
// console.log(selections[0].col,elements[selections[0].col]);
// if (elements[selections[0].col].isAllowEdit === 1) {
// // console.log(item);
// spread.contextMenu.menuData = itemsDataForShown.filter((item: any) => {
// return (
// item.text !== "插入批注" &&
// item.text !== "设置单元格格式..." &&
// item.text !== "超链接..." &&
// item.text !== "编辑富文本..." &&
// item.text !== "定义名称..." &&
// item.text !== "标签..."
// );
// });
// } else {
// spread.contextMenu.menuData = itemsDataForShown.filter((item: any) => {
// return (
// item.text !== "删除..." &&
// item.text !== "删除" &&
// item.text !== "清除内容" &&
// item.text !== "插入批注" &&
// item.text !== "设置单元格格式..." &&
// item.text !== "超链接..." &&
// item.text !== "编辑富文本..." &&
// item.text !== "定义名称..." &&
// item.text !== "标签..."
// );
// });
// }
const Alltrue = ["gc.spread.contextMenu.insertComment","formatCells","link","richText" , "defineName" ,"cellTag"]
const Allfalse = ["gc.spread.contextMenu.clearContents","tableDelete","gc.spread.contextMenu.insertComment","formatCells","link","richText" , "defineName" ,"cellTag"]
// const Alltrue = ["插入批注","设置单元格格式...","超链接...","编辑富文本..." , "定义名称..." ,"标签..."]
// const Allfalse = ["清除内容","删除","插入批注","设置单元格格式...","超链接...","编辑富文本...","定义名称..." ,"标签..."]
for(let i=0; i<itemsDataForShown.length; i++){
var item = itemsDataForShown;
if(elements[selections[0].col].isAllowEdit === 1 && Alltrue.includes(item.name)){
item.disable = true;
if(item.subMenu){
item.subMenu.forEach(citem => {
citem.disable = true;
})
}
}
if(elements[selections[0].col].isAllowEdit === 0 && Allfalse.includes(item.name)){
item.disable = true;
if(item.subMenu){
item.subMenu.forEach(citem => {
citem.disable = true;
})
}
}
}
spread.contextMenu.menuData = itemsDataForShown
console.log(elements);
};
你好,我这里想根据条件禁用右键部分菜单,但目前我发现删除没在上面Alltrue 数组中,但被置灰了,但可以选他子菜单,但是再Allfalse中,可以正常禁用 |