找回密码
 立即注册

QQ登录

只需一步,快速开始

Derrick.Jiao 讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2021-10-12 15:59  /   查看:2722  /  回复:0
本帖最后由 Derrick.Jiao 于 2021-10-13 18:12 编辑

在我们的组件化编辑器推出之后,有小伙伴想要能够像在SpreadJS中那样定制状态栏,甚至是将对应的图标添加到状态栏上。但是我们在14.2之前,是没有接口或者方法可以直接获取的。针对这个问题,我们暴露了一个findControl接口,这样我们就可以获取状态栏实例了。获取到这个实例之后,我们就能根据自己的需求进行定制。

那么接下来我们看下如何实现设计器上状态栏的自定义。

在14.2中,这个查找状态栏的实例的接口为
  1. var statusBar = GC.Spread.Sheets.StatusBar.findControl(document.getElementsByClassName("gc-statusBar")[0]);
复制代码

接着,通过自定义状态项 GC.Spread.Sheets.StatusBar.StatusItem 类的onCreateItemView方法, 为状态条创建项目元素。这个方法可以被复写以自定制对应的状态项UI。
  1. var StatusItem = GC.Spread.Sheets.StatusBar.StatusItem;

  2.         function Popup(name, options) {
  3.             StatusItem.call(this, name, options);
  4.         }

  5.         Popup.prototype = new StatusItem();
  6.         Popup.prototype.onCreateItemView = function (container) {
  7.             var item = document.createElement('div');
  8.             item.style.padding = "0 3px";
  9.             item.innerHTML = `<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADoAAAA7CAIAAAClhQ7aAAAQoElEQVR4Ae2aBXcjSdam33sjIkGSbdkFXY3V9NEwfczMzMw/YH/PMjMz7zAzT3MXm21BZkZcWKuqGoY0NQcX+j3PuY5zLXiUTOTu+L8nr+m+pvua7vq8pguFFC3BOMUIDVCsMCCJ1NxDxZZTYQQCA32PJeHoFPuH2LuFgyM/OUKXYXoWpBDbCTYnOHce953H9gVMJ6gYbUAdl3BXq6mOlACGOIhWlR2BDaVYCSkFJFqju8jzlFKgxGByQIDicEEdT/vj0KRxDCiGYcDJqd3aff59H+aTxTCf6XLpQ2aRmqiKzByLaqdaiFClOB5X4wnG7RPf/7147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Ej/8g2pThzBzdwQEUAP76GzLrlRDRCIUhaj1OeOvb3qzlY3//79fd3I72WrOd6TbYT3JnatHoLE4A2IgACBmROxHx3W1ZBAFEBpBXKYjZKLUmGI4H4kmYXjipR6/7vd/DW9+Mth0CnQWwQbpgGkO79ky44WLSAgwMBTGF8OD9NP3xt9bxC//u3572ywerrVm/GE6Pqog21oFrgJSg5EooMIUbjIhJEUEVOIKDBzYnF++yuxxTjqPNdufSYQn+2EOXf+RH8VM/hMnYKWopVZUMKAzm4MDau5YoDqmsYg69GBHVgWLpMAx46ovP/7N/8vz73nuBcCFyO3QjTnkpADyyBfewqgYzODNj5UfBODhYicTcjINKFfN04+ZQ9pd6th24fLbZeuMb0dQD16bKSlVi9TKwRMSIEMBfV3eAGCyAHcFAAYgO7ntIQXDkef7Aez7wr/81nr/ymIZ4Oh+l2t3NC2DEDpiZOAwAnIjCGUxxNUB0wqIUHTW3VPiRh173y7/YfN/3YGsbdT0DMdcRIRqCOtxzZQ6O4LBm6pYyxJQMcKAADEoAq6MUBIIs4QXHhyf/450v/Pd38/5BYxYlQ3KE1vCKKbkyHCB1LxQyUIyEo4ckVb2k0Dejb/++79386R/HQ5e8Clq1hZhwBjmY4ZVFOMAooikFrNFFZ0iMYEZaAHFh4ybU5LCsxEoweIEV7O7aFz7/kX/zr9Nijvmc++Uol5FZJYVMAXamHNMicBdjadow3ugnG2/9mV9ovvXbcd8l1BWa1glaJIbbfjr0EeBKEWqEmIECtACv0R0AM6NMTTBA4apehdoEDBgQojMUklF6kCIP2N3Di1e6F144ufLC/OZed3CYlwsA9XgyOn9ufN/58f0PTh55GI88sjp+bSaoasTkoEGciGoK0AxiyGB1KBQHMKlv9BEM1Ot1DaA7bXupy/jK1dMAwA1+d6sKAO5wg93pYxUCiMG3KwEgMIMjmEAMwF/55Ffeorf7BAR7+UNee7jla+c13f8NwE0UijNFsNoAAAAASUVORK5CYII=' height='20' width='20'></img>`;
  10.             container.appendChild(item);
  11.             container.addEventListener('click', function () {
  12.                 alert('我是图标按钮');
  13.             })
  14.         };
复制代码

在上面的代码中,我们通过innerHTML插入img标签,以及为这个容器添加了点击事件。
最后,我们再将其添加到statusBar中
  1. statusBar.add(new Popup('Popup', { menuContent: 'popup item', tipText: 'popup' }));
复制代码

下载附件即可查看完整demo。

statusbar.html

8.51 KB, 下载次数: 94

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部