index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const setting = Editor.require('packages://build-helper/core/build-setting.js');
  2. // panel/index.js, this filename needs to match the one registered in package.json
  3. Editor.Panel.extend({
  4. // css style for panel
  5. style: `
  6. :host {
  7. display: flex;
  8. flex-direction: column;
  9. }
  10. .wrapper {
  11. box-sizing: border-box;
  12. border: 2px solid white;
  13. font-size: 20px;
  14. font-weight: bold;
  15. }
  16. .top {
  17. height: 50px;
  18. border-color: red;
  19. }
  20. .middle {
  21. flex: 1;
  22. border-color: green;
  23. overflow-y: auto;
  24. overflow-x: hidden;
  25. }
  26. .bottom {
  27. height: 50px;
  28. border-color: blue;
  29. }
  30. `,
  31. // html template for panel
  32. template: `
  33. <div class="wrapper top layout horizontal center">
  34. <ui-select id="module" class="massive" value="assets-crypto-setting">
  35. <option value="assets-hotupdate-setting">资源热更</option>
  36. <option value="assets-obfuscator-setting">代码混淆</option>
  37. <option value="assets-compress-setting">资源压缩</option>
  38. <option value="assets-crypto-setting">资源加密</option>
  39. <option value="assets-android-pack-setting">安卓打包</option>
  40. </ui-select>
  41. </div>
  42. <div id="view" class="wrapper middle scroll">
  43. </div>
  44. <div class="wrapper bottom layout horizontal center-justified">
  45. <ui-button id="btn" class="massive">保存配置</ui-button>
  46. </div>
  47. `,
  48. // method executed when template and styles are successfully loaded and initialized
  49. ready () {
  50. // 加载编译配置
  51. setting.getInstance().load();
  52. this.$ = {
  53. module: this.shadowRoot.querySelector('#module'),
  54. view: this.shadowRoot.querySelector('#view'),
  55. btn: this.shadowRoot.querySelector('#btn')
  56. };
  57. // 模块
  58. let moduleValue = this.profiles.local.data.module;
  59. if (!moduleValue) {
  60. moduleValue = this.$.module.value;
  61. this.profiles.local.data.module = moduleValue;
  62. }
  63. this.$.module.value = moduleValue;
  64. this.showPreview(moduleValue);
  65. this.$.module.addEventListener('confirm', event => {
  66. let value = event.target.value;
  67. this.profiles.local.data.scrollTop = 0;
  68. this.profiles.local.data.module = value;
  69. this.profiles.local.save();
  70. this.showPreview(value);
  71. });
  72. this.$.btn.addEventListener('confirm', (event) => {
  73. this.saveSetting();
  74. });
  75. },
  76. close () {
  77. this.profiles.local.data.scrollTop = this.$.view.scrollTop;
  78. this.profiles.local.save();
  79. },
  80. showPreview (modeule) {
  81. Editor.import(`packages://build-helper/panel/${modeule}.js`).then(initFn => {
  82. initFn(this);
  83. setTimeout(() => {
  84. this.$.view.scrollTop = this.profiles.local.data.scrollTop;
  85. }, 10);
  86. });
  87. },
  88. getSettingItem (key) {
  89. return setting.getInstance().getItem(key);
  90. },
  91. setSettingItem (key, value) {
  92. setting.getInstance().setItem(key, value);
  93. },
  94. saveSetting () {
  95. setting.getInstance().save();
  96. let config = setting.getInstance().getConfig();
  97. Editor.Ipc.sendToMain('build-helper:panel-saved-setting', config);
  98. },
  99. // register your ipc messages here
  100. messages: {
  101. }
  102. });