hackCode.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. (() =>
  2. {
  3. let dirname = "?pos/targetPath"
  4. const fs_extra_1 = require("fs-extra")
  5. const path_1 = require("path")
  6. const vue_1 = require(path_1.join(dirname,'node_modules' ,"vue"))
  7. const exec = require('child_process').exec;
  8. const prsPath = Editor.Project && Editor.Project.path ? Editor.Project.path : Editor.remote.projectPath;
  9. // Create temp directory if it doesn't exist
  10. const tempDir = path_1.join(prsPath, 'temp');
  11. if (!fs_extra_1.existsSync(tempDir)) {
  12. fs_extra_1.mkdirSync(tempDir);
  13. }
  14. const configPath = path_1.join(tempDir, 'tab-config.json');
  15. let d = document.getElementById('prefab-tab');
  16. if(d){
  17. d.parentNode.removeChild(d);
  18. }
  19. let div = document.createElement('div');
  20. let ht = fs_extra_1.readFileSync(path_1.join(dirname, "./static/template/default/index.html"), "utf-8");
  21. div.innerHTML = ht;
  22. div.style.cssText = 'height: 21px; border: 1px solid #040404; z-index: 1;'
  23. div.id = 'prefab-tab'
  24. document.body.insertBefore(div, document.getElementById('dock'))
  25. window.vue_1 = vue_1;
  26. console.log("显示")
  27. const e = vue_1.createApp({
  28. el: div,
  29. data() {
  30. return {
  31. tabs: [],//[{ name:'test', uuid:'2' },{ name:'test3', uuid:'3' }],
  32. uiCfg: {},
  33. menuItems: [
  34. { label: '关闭', id: 'close' },
  35. { label: '关闭右侧', id: 'close-rights' },
  36. { label: '关闭其他', id: 'close-others' },
  37. { label: '全部关闭', id: 'close-all' },
  38. { label: '在文件夹中显示', id: 'reveal-in-finder' },
  39. { label: '跳到资源管理器', id: 'reveal-in-side-bar' },
  40. ],
  41. openUuid:'',
  42. menuShow: false,
  43. selectMenuItem: null,
  44. menuPos: { x: 0, y: 0, isLeft: true },
  45. }
  46. },
  47. watch:{
  48. menuShow(val){
  49. div.style.zIndex = val ? '99' : '1';
  50. },
  51. },
  52. mounted(){
  53. vueObj = this;
  54. var style = document.createElement("style");
  55. style.innerHTML = fs_extra_1.readFileSync(path_1.join(dirname, "./static/style/default/index.css"), "utf-8");
  56. div.appendChild(style)
  57. this._openScene1 = this.openScene.bind(this);
  58. Editor.Message.addBroadcastListener('scene:ready',this._openScene1)
  59. // Load configuration from file
  60. try {
  61. if (fs_extra_1.existsSync(configPath)) {
  62. const config = JSON.parse(fs_extra_1.readFileSync(configPath, 'utf-8'));
  63. this.tabs = config.tabs || [];
  64. this.openUuid = config.openUuid || '';
  65. }
  66. } catch (error) {
  67. console.error('Error loading tab configuration:', error);
  68. }
  69. },
  70. unmounted(){
  71. Editor.Message.removeBroadcastListener('scene:ready',this._openScene1)
  72. },
  73. methods:{
  74. saveConfig() {
  75. try {
  76. fs_extra_1.writeFileSync(configPath, JSON.stringify({
  77. tabs: this.tabs,
  78. openUuid: this.openUuid
  79. }, null, 2));
  80. } catch (error) {
  81. console.error('Error saving tab configuration:', error);
  82. }
  83. },
  84. openBtn(item){
  85. Editor.Message.request("scene",'open-scene',item.uuid)
  86. },
  87. closeBtn(item){
  88. let idx = this.tabs.indexOf(item);
  89. idx != -1 && this.tabs.splice(idx,1)
  90. this.saveConfig();
  91. },
  92. async openScene(uuid){
  93. let filePath = await Editor.Message.request("asset-db",'query-path',uuid);
  94. if(!filePath) return;
  95. let name = path_1.basename(filePath).split('.')[0];
  96. let tab = this.tabs.find((v)=>v.uuid == uuid)
  97. if(!tab){
  98. this.tabs.push({
  99. uuid:uuid,
  100. name:name,
  101. extname: path_1.extname(filePath),
  102. })
  103. this.saveConfig();
  104. }else{
  105. tab.name = name;
  106. }
  107. this.openUuid = uuid;
  108. this.saveConfig();
  109. },
  110. enterTab(item){
  111. this.uiCfg[item.uuid] = true;
  112. },
  113. leaveTab(item){
  114. this.uiCfg[item.uuid] = false;
  115. },
  116. openMenu(item, event){
  117. this.selectMenuItem = item;
  118. this.menuShow = true;
  119. this.menuPos.isLeft = event.clientX < window.innerWidth * 0.85;
  120. this.menuPos.x = this.menuPos.isLeft ? event.clientX : window.innerWidth - event.clientX;
  121. this.menuPos.y = event.clientY;
  122. for(let v of this.menuItems){
  123. v.mouseenter = false;
  124. }
  125. },
  126. async clickMenu(menuItem){
  127. this.menuShow = false;
  128. if(!this.selectMenuItem) return console.warn('not selectMenuItem');
  129. if(menuItem.id == 'close'){
  130. this.closeBtn(this.selectMenuItem)
  131. }else if(menuItem.id == 'close-rights'){
  132. let idx = this.tabs.indexOf(this.selectMenuItem);
  133. if(idx != -1){
  134. this.tabs = this.tabs.slice(0,idx+1);
  135. this.saveConfig();
  136. }
  137. }else if(menuItem.id == 'close-others'){
  138. this.tabs = [this.selectMenuItem];
  139. this.saveConfig();
  140. }else if(menuItem.id == 'close-all'){
  141. this.tabs = [];
  142. this.saveConfig();
  143. }else if(menuItem.id == 'reveal-in-finder'){
  144. let url = await Editor.Message.request('asset-db','query-path',this.selectMenuItem.uuid)
  145. let isWin32 = path_1.sep == '\\';
  146. url && exec(isWin32 ? 'Explorer /select,"'+url+'"' : "open -R " + url)
  147. }else if(menuItem.id == 'reveal-in-side-bar'){
  148. Editor.Message.broadcast('twinkle',this.selectMenuItem.uuid)
  149. }
  150. },
  151. }
  152. });
  153. // e.config.compilerOptions.isCustomElement = (e) => e.startsWith("ui-") || e.startsWith("nobr");
  154. e.mount(div);
  155. })();