serve-tool.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const Path = require('path');
  2. const Fs = require('fs');
  3. const Util = Editor.require('packages://hot-update-tools/core/Util.js');
  4. const OutPut = Editor.require('packages://hot-update-tools/core/OutPut.js');
  5. Vue.component('serve-tool', {
  6. template: Fs.readFileSync(Editor.url('packages://hot-update-tools/panel/serve-tool.html'), 'utf-8'),
  7. mixins: [Editor.require('packages://hot-update-tools/panel/mixin.js')],
  8. data () {
  9. return {
  10. staticFileServer: null,
  11. staticFileDir: null,
  12. staticFileUrl: null,
  13. };
  14. },
  15. created () {
  16. this.$nextTick(() => {
  17. this.staticFileDir = OutPut.testServerDir;
  18. });
  19. },
  20. methods: {
  21. onBtnClickSelectHttpDir () {
  22. let selectPath = [
  23. OutPut.testServerDir,
  24. this.staticFileDir,
  25. Path.join(Editor.projectInfo.path, 'build'),
  26. Editor.projectInfo.path,
  27. ];
  28. for (let i = 0; i < selectPath.length; i++) {
  29. let item = selectPath[i];
  30. if (item && Fs.existsSync(item)) {
  31. selectPath = item;
  32. break;
  33. }
  34. }
  35. let res = Editor.Dialog.openFile({
  36. title: '选择目录',
  37. defaultPath: selectPath,
  38. properties: ['openDirectory'],
  39. });
  40. if (res !== -1) {
  41. this.staticFileDir = res[0];
  42. }
  43. },
  44. onBtnClickHttpDir () {
  45. this.openDir(this.staticFileDir);
  46. },
  47. },
  48. });