找回密码
 立即注册

QQ登录

只需一步,快速开始

snowflakes7

注册会员

6

主题

13

帖子

59

积分

注册会员

积分
59
snowflakes7
注册会员   /  发表于:2023-8-18 10:16  /   查看:1341  /  回复:3
10金币
需要创建三级菜单,了解到通过组件版设计器不支持三级菜单(通过该帖子了解: https://gcdn.grapecity.com.cn/showtopic-160173-1-1.html),所以通过spreadjs的方式创建右键三级菜单,如下截图:

1692322841665_5BA7D782-7DCD-4071-B0AD-F6DCA83CDC2A.png605214538.png
但是组件版的右键菜单有 定义名称 和 标签 功能按钮。现在需要既能实现右键三级菜单,又能使用 定义名称和标签功能,该如何实现
image.png212543944.png
  1. <template>
  2.   <div id="app">
  3.     <gc-spread-sheets-designer
  4.       :styleInfo="styleInfo"
  5.       :config="config"
  6.       :spreadOptions="spreadOptions"
  7.       @designerInitialized="designerInitialized"
  8.     >
  9.     </gc-spread-sheets-designer>
  10.   </div>
  11. </template>

  12. <script>
  13. import "@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css";
  14. import "@grapecity/spread-sheets-designer/styles/gc.spread.sheets.designer.min.css";
  15. import * as GC from "@grapecity/spread-sheets";
  16. import "@grapecity/spread-sheets-print";
  17. import "@grapecity/spread-sheets-shapes";
  18. import "@grapecity/spread-sheets-pivot-addon";
  19. import "@grapecity/spread-sheets-tablesheet";
  20. import "@grapecity/spread-sheets-resources-zh";
  21. GC.Spread.Common.CultureManager.culture("zh-cn");
  22. import "@grapecity/spread-sheets-designer-resources-cn";
  23. import "./custom.css";
  24. import * as ExcelIO from "@grapecity/spread-excelio";

  25. //Apply License
  26. //GC.Spread.Sheets.LicenseKey = 'sjs-distribution-key';
  27. //ExcelIO.LicenseKey = 'sjs-distribution-key';
  28. //GC.Spread.Sheets.Designer.LicenseKey = 'designer-component-distribution-key';

  29. import { Designer } from "@grapecity/spread-sheets-designer-vue";

  30. export default {
  31.   name: "App",
  32.   data: function() {
  33.     var config = GC.Spread.Sheets.Designer.DefaultConfig;
  34.     config.commandMap = {
  35.       Welcome: {
  36.         title: "Welcome",
  37.         text: "Welcome",
  38.         iconClass: "ribbon-button-welcome",
  39.         bigButton: "true",
  40.         commandName: "Welcome",
  41.         execute: async (context, propertyName, fontItalicChecked) => {
  42.           alert("Welcome to new designer.");
  43.         }
  44.       }
  45.     };
  46.     config.ribbon[0].buttonGroups.unshift({
  47.       label: "NewDesigner",
  48.       thumbnailClass: "welcome",
  49.       commandGroup: {
  50.         children: [
  51.           {
  52.             direction: "vertical",
  53.             commands: ["Welcome"]
  54.           }
  55.           // This is custom button ----------------end-------------
  56.         ]
  57.       }
  58.     });
  59.     return {
  60.       styleInfo: { height: "98vh", width: "100%" },
  61.       config: config,
  62.       spreadOptions: {
  63.         sheetCount: 2
  64.       },
  65.       designer: null,
  66.       spread: null
  67.     };
  68.   },
  69.   methods: {
  70.     designerInitialized(value) {
  71.       this.designer = value;
  72.       this.spread = this.designer.getWorkbook();
  73.       this.registerCommand();
  74.       this.customContextMenu();
  75.     },
  76.     registerCommand() {
  77.       const myCmd = {
  78.         canUndo: true,
  79.         name: "myCmd",
  80.         execute: (context, options, isUndo) => {
  81.           alert("add_table_command");
  82.           const activeSheet = this.spread.getActiveSheet();
  83.           const table = activeSheet.tables.add(
  84.             "table1",
  85.             2,
  86.             2,
  87.             6,
  88.             6,
  89.             GC.Spread.Sheets.Tables.TableThemes.medium2
  90.           );
  91.           const cellType = new GC.Spread.Sheets.CellTypes.CheckBox();
  92.           cellType.isThreeState(false);
  93.           const tableColumn0 = new GC.Spread.Sheets.Tables.TableColumn(
  94.             0,
  95.             "check",
  96.             "check",
  97.             null,
  98.             cellType
  99.           );
  100.           const tableColumn1 = new GC.Spread.Sheets.Tables.TableColumn(
  101.             1,
  102.             "orderDate",
  103.             "Order Date",
  104.             "yyyy-mm-dd"
  105.           );
  106.           const tableColumn2 = new GC.Spread.Sheets.Tables.TableColumn(
  107.             2,
  108.             "item",
  109.             "Item"
  110.           );
  111.           const tableColumn3 = new GC.Spread.Sheets.Tables.TableColumn(
  112.             3,
  113.             "unit",
  114.             "units"
  115.           );
  116.           const tableColumn4 = new GC.Spread.Sheets.Tables.TableColumn(
  117.             4,
  118.             "cost",
  119.             "Cost"
  120.           );
  121.           const tableColumn5 = new GC.Spread.Sheets.Tables.TableColumn(
  122.             5,
  123.             "pkid",
  124.             "Pkid"
  125.           );
  126.           table.autoGenerateColumns(false);
  127.           table.bind(
  128.             [
  129.               tableColumn0,
  130.               tableColumn1,
  131.               tableColumn2,
  132.               tableColumn3,
  133.               tableColumn4,
  134.               tableColumn5
  135.             ],
  136.             "null"
  137.           );
  138.           table.expandBoundRows(true);
  139.           table.filterButtonsVisible(
  140.             GC.Spread.Sheets.Filter.RowFilterBase,
  141.             false
  142.           );
  143.         }
  144.       };
  145.       this.spread.commandManager().register("myCmd", myCmd);
  146.     },
  147.     customContextMenu() {
  148.       function MyContextMenu() {}
  149.       MyContextMenu.prototype = new GC.Spread.Sheets.ContextMenu.ContextMenu();
  150.       MyContextMenu.prototype.onOpenMenu = function(
  151.         menuData,
  152.         itemsDataForShown,
  153.         hitInfo
  154.       ) {
  155.         itemsDataForShown.push(
  156.           {
  157.             text: "添加表格",
  158.             name: "myCmd",
  159.             command: "myCmd",
  160.             workArea: "viewport"
  161.           },
  162.           {
  163.             text: "添加按钮",
  164.             name: "addBtnCmd",
  165.             workArea: "viewport",
  166.             subMenu: [
  167.               {
  168.                 text: "新建",
  169.                 name: "add",
  170.                 command: "addCmd"
  171.               },
  172.               {
  173.                 text: "删除",
  174.                 name: "delete",
  175.                 command: "deleteCmd"
  176.               },
  177.               {
  178.                 text: "导入",
  179.                 name: "import",
  180.                 subMenu: [
  181.                   {
  182.                     text: "导入Excel",
  183.                     name: "importExcel",
  184.                     command: "importExcelCmd"
  185.                   },
  186.                   {
  187.                     text: "导入CSV",
  188.                     name: "importCSV",
  189.                     command: "importCSV"
  190.                   }
  191.                 ]
  192.               }
  193.             ]
  194.           }
  195.         );
  196.       };
  197.       const contextMenu = new MyContextMenu();
  198.       this.spread.contextMenu = contextMenu;
  199.     }
  200.   }
  201. };
  202. </script>
  203. <style></style>
复制代码


最佳答案

查看完整内容

您好,试试如下代码: let oldOpenMenu = spread.contextMenu.onOpenMenu; spread.contextMenu.onOpenMenu = function ( menuData, itemsDataForShown, hitInfo, spread ) { oldOpenMenu.apply(this, arguments); console.log(itemsDataForShown); itemsDataForShown.push( { text: "添加表格", name: "myCmd", command: "myCmd", workArea: "viewport", }, ...

3 个回复

倒序浏览
最佳答案
最佳答案
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2023-8-18 10:16:39
来自 2#
您好,试试如下代码:

let oldOpenMenu = spread.contextMenu.onOpenMenu;
spread.contextMenu.onOpenMenu = function (
  menuData,
  itemsDataForShown,
  hitInfo,
  spread
) {
  oldOpenMenu.apply(this, arguments);
  console.log(itemsDataForShown);

  itemsDataForShown.push(
    {
      text: "添加表格",
      name: "myCmd",
      command: "myCmd",
      workArea: "viewport",
    },
    {
      text: "添加按钮",
      name: "addBtnCmd",
      workArea: "viewport",
      subMenu: [
        {
          text: "新建",
          name: "add",
          command: "addCmd",
        },
        {
          text: "删除",
          name: "delete",
          command: "deleteCmd",
        },
        {
          text: "导入",
          name: "import",
          subMenu: [
            {
              text: "导入Excel",
              name: "importExcel",
              command: "importExcelCmd",
            },
            {
              text: "导入CSV",
              name: "importCSV",
              command: "importCSV",
            },
          ],
        },
      ],
    }
  );
};
回复 使用道具 举报
snowflakes7
注册会员   /  发表于:2023-8-18 16:30:08
3#
Joestar.Xu 发表于 2023-8-18 11:14
您好,试试如下代码:

let oldOpenMenu = spread.contextMenu.onOpenMenu;

问题已解决,感谢
回复 使用道具 举报
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2023-8-18 16:30:37
4#
不客气哈,后续有其他问题的话随时开贴提问。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部