- let elements = sheetList[sheetIndex].elements;
- let isAllowDeleteRow = sheetList[sheetIndex].isAllowDeleteRow;
- let oldOpenMenu = spread.contextMenu.onOpenMenu;
- function ContextMenu() {}
- ContextMenu.prototype = new GC.Spread.Sheets.ContextMenu.ContextMenu(spread);
- ContextMenu.prototype.onOpenMenu = function (
- menuData,
- itemsDataForShown,
- hitInfo,
- spread
- ) {
- const Alltrue = [
- "gc.spread.insertComment",
- "formatCells",
- "gc.spread.tableDelete",
- "gc.spread.tableInsert",
- "link",
- "richText",
- "defineName",
- "cellTag",
- ];
- const coltrue = ["gc.spread.deleteRows", "gc.spread.clearContents"];
- const Allfalse = [
- "gc.spread.clearContents",
- "gc.spread.tableDelete",
- "gc.spread.insertComment",
- "gc.spread.tableInsert",
- "formatCells",
- "link",
- "richText",
- "defineName",
- "cellTag",
- ];
- // const Alltrue = ["插入批注","设置单元格格式...","超链接...","编辑富文本...","定义名称..." ,"标签..."]
- // const Allfalse = ["清除内容","删除","插入批注","设置单元格格式...","超链接...","编辑富文本...","定义名称..." ,"标签..."]
- const selections = spread.getSheetFromName(element.sheetName).getSelections();
- console.log(selections);
- console.log(itemsDataForShown);
- for (let i = 0; i < itemsDataForShown.length; i++) {
- var item = itemsDataForShown[i];
- if (selections[0].row == -1) {
- item.disable = true;
- if (item.subMenu) {
- item.subMenu.forEach((citem) => {
- citem.disable = true;
- });
- }
- }
- if (
- !isAllowDeleteRow &&
- selections[0].col == -1 &&
- coltrue.includes(item.name)
- ) {
- item.disable = true;
- if (item.subMenu) {
- item.subMenu.forEach((citem) => {
- citem.disable = true;
- });
- }
- }
- 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 (
- citem.name == "gc.spread.tableDeleteRows" ||
- citem.name == "gc.spread.tableInsertRowsAbove"
- ) {
- citem.disable = false;
- }
- });
- }
- }
- if (
- elements[selections[0].col]?.isAllowEdit === 0 &&
- Allfalse.includes(item.name)
- ) {
- item.disable = true;
- if (item.subMenu) {
- item.subMenu.forEach((citem) => {
- citem.disable = true;
- if (citem.name == "gc.spread.tableInsertRowsAbove") {
- citem.disable = false;
- }
- });
- }
- }
- }
- };
- // 将自定义右键菜单赋值给spread.contextMenu
- spread.contextMenu = new ContextMenu();
复制代码 |