index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. // panel/index.js, this filename needs to match the one registered in package.json
  2. var FS = require('fire-fs');
  3. var Electron = require('electron');
  4. var CfgUtil = Editor.require("packages://selection-resources/util/CfgUtil");
  5. var Iokit = Editor.require("packages://selection-resources/util/iokit");
  6. Editor.Panel.extend({
  7. // css style for panel
  8. style: `
  9. :host {
  10. padding-left: 10px;
  11. padding-right: 10px;
  12. height: auto;
  13. }
  14. .container {
  15. height: 100%;
  16. overflow-y: auto;
  17. }
  18. .button{
  19. float:right
  20. }
  21. ui-box-container{
  22. min-height: 50px;
  23. }
  24. `,
  25. // html template for panel
  26. template: `
  27. <div style="overflow:scroll;height:1200px;">
  28. <h2>挑选资源</h2>
  29. <hr />
  30. <ui-box-container class="layout vertical left">
  31. <br>
  32. <ui-prop name="旧版本路径">
  33. <div class="flex-1 layout horizontal center">
  34. <!--ui-input class="flex-2" disabled v-value="OldVersionPath"></ui-input-->
  35. <ui-input class="flex-2" v-value="OldVersionPath"></ui-input>
  36. <ui-button v-on:confirm="onSelectOldVersionPath">选择</ui-button>
  37. <ui-button v-on:confirm="onOpenSelectOldVersionPath">
  38. <i class="icon-doc-text"></i>
  39. </ui-button>
  40. </div>
  41. </ui-prop>
  42. <br>
  43. <ui-prop name="新版本路径">
  44. <div class="flex-1 layout horizontal center">
  45. <ui-input class="flex-2" v-value="NewVersionPath"></ui-input>
  46. <ui-button v-on:confirm="onSelectNewVersionPath">选择</ui-button>
  47. <ui-button v-on:confirm="onOpenSelectNewVersionPath">
  48. <i class="icon-doc-text"></i>
  49. </ui-button>
  50. </div>
  51. </ui-prop>
  52. <br>
  53. <ui-prop name="生成文件路径">
  54. <div class="flex-1 layout horizontal center">
  55. <ui-input class="flex-2" v-value="FinalPath"></ui-input>
  56. <ui-button v-on:confirm="onSelectFinalPath">选择</ui-button>
  57. <ui-button v-on:confirm="onOpenSelectFinalPath">
  58. <i class="icon-doc-text"></i>
  59. </ui-button>
  60. </div>
  61. </ui-prop>
  62. <br>
  63. <br>
  64. <ui-button class="button blue big" @click="save()">开始生成</ui-button>
  65. <br>
  66. <label>使用说明:<br>
  67. 遍历不同版本路径下文件,比对MD5差异<br>
  68. 把不同的文件拷贝到生成资源路径下<br>
  69. </label>
  70. <h2>日志:</h2>
  71. <textarea class="" id="logTextArea" v-value="logView"
  72. style="width: 100%; height: 300px; background: #252525; color: #fd942b; border-color: #fd942b;">
  73. </textarea>
  74. </ui-box-container>
  75. <ui-button v-on:confirm="onClearLog">清空日志</ui-button>
  76. </div>
  77. `,
  78. // element and variable binding
  79. $: {
  80. logTextArea: '#logTextArea',
  81. },
  82. // method executed when template and styles are successfully loaded and initialized
  83. ready () {
  84. let logCtrl = this.$logTextArea;
  85. let logListScrollToBottom = function () {
  86. setTimeout(function () {
  87. logCtrl.scrollTop = logCtrl.scrollHeight;
  88. }, 10);
  89. };
  90. let vue = new window.Vue({
  91. el: this.shadowRoot,
  92. created(){
  93. //初始化插件
  94. this._addLog("初始化插件");
  95. this.initPlugin();
  96. },
  97. data:{
  98. OldVersionPath:"", //旧版本路径
  99. NewVersionPath:"", //新版本路径
  100. FinalPath:"", //最终生成文件路径
  101. logView:[],
  102. },
  103. methods: {
  104. //面板Log
  105. _addLog(str,flag) {
  106. if(flag){
  107. this.logView += "[" + flag + "]: " + str + "\n";
  108. }else{
  109. let time = new Date();
  110. this.logView += "[" + time.toLocaleString() + "]: " + str + "\n";
  111. }
  112. //Editor.log(this.logView);
  113. logListScrollToBottom();
  114. },
  115. //初始化插件
  116. initPlugin(){
  117. CfgUtil.initCfg(function (data) {
  118. if (data) {
  119. this.OldVersionPath = data.OldVersionPath;
  120. this.NewVersionPath = data.NewVersionPath;
  121. this.FinalPath = data.FinalPath;
  122. } else {
  123. this._saveConfig();
  124. }
  125. }.bind(this));
  126. },
  127. //保存配置信息
  128. _saveConfig() {
  129. CfgUtil.saveConfig();
  130. },
  131. onStopTouchEvent(event){
  132. event.preventDefault();
  133. event.stopPropagation();
  134. },
  135. save() {
  136. //CfgUtil.commSet("FinalPath",this.FinalPath);
  137. this._saveConfig();
  138. this._addLog('旧版本:' + this.OldVersionPath);
  139. this._addLog('新版本:' + this.NewVersionPath);
  140. this._addLog('生成路径:' + this.FinalPath);
  141. Iokit.build(this.OldVersionPath,this.NewVersionPath,this.FinalPath,
  142. function (data) {
  143. if (data) {
  144. this._addLog("Iokit:" + data);
  145. }
  146. }.bind(this)
  147. );
  148. },
  149. //旧版本
  150. onSelectOldVersionPath(){
  151. let path = Editor.Project.path;
  152. if (this.OldVersionPath && this.OldVersionPath.length > 0) {
  153. if (FS.existsSync(this.OldVersionPath)) {
  154. path = this.OldVersionPath;
  155. }
  156. }
  157. let res = Editor.Dialog.openFile({
  158. title: "选择旧版本目录",
  159. defaultPath: path,
  160. properties: ['openFile'],
  161. });
  162. if (res !== -1) {
  163. this.OldVersionPath = res[0];
  164. CfgUtil.commSet("OldVersionPath",this.OldVersionPath);
  165. this._saveConfig();
  166. }
  167. },
  168. onOpenSelectOldVersionPath(){
  169. if (!FS.existsSync(this.OldVersionPath)) {
  170. this._addLog("目录不存在:" + this.OldVersionPath);
  171. return;
  172. }
  173. Electron.shell.showItemInFolder(this.OldVersionPath);
  174. Electron.shell.beep();
  175. },
  176. //新版本
  177. onSelectNewVersionPath(){
  178. let path = Editor.Project.path;
  179. if (this.NewVersionPath && this.NewVersionPath.length > 0) {
  180. if (FS.existsSync(this.NewVersionPath)) {
  181. path = this.NewVersionPath;
  182. }
  183. }
  184. let res = Editor.Dialog.openFile({
  185. title: "选择新版本目录",
  186. defaultPath: path,
  187. properties: ['openFile'],
  188. });
  189. if (res !== -1) {
  190. this.NewVersionPath = res[0];
  191. CfgUtil.commSet("NewVersionPath",this.NewVersionPath);
  192. this._saveConfig();
  193. }
  194. },
  195. onOpenSelectNewVersionPath(){
  196. if (!FS.existsSync(this.NewVersionPath)) {
  197. this._addLog('目录不存在!' + this.NewVersionPath);
  198. return;
  199. }
  200. Electron.shell.showItemInFolder(this.NewVersionPath);
  201. Electron.shell.beep();
  202. },
  203. //生成路径
  204. onSelectFinalPath(){
  205. let path = Editor.Project.path;
  206. if (this.FinalPath && this.FinalPath.length > 0) {
  207. if (FS.existsSync(this.FinalPath)) {
  208. path = this.FinalPath;
  209. }
  210. }
  211. let res = Editor.Dialog.openFile({
  212. title: "选择生成文件输出目录",
  213. defaultPath: path,
  214. properties: ['openDirectory'],
  215. });
  216. if (res !== -1) {
  217. this.FinalPath = res[0];
  218. CfgUtil.commSet("FinalPath",this.FinalPath);
  219. this._saveConfig();
  220. }
  221. },
  222. onOpenSelectFinalPath(){
  223. if (!FS.existsSync(this.FinalPath)) {
  224. this._addLog('目录不存在!' + this.FinalPath);
  225. return;
  226. }
  227. Electron.shell.showItemInFolder(this.FinalPath);
  228. Electron.shell.beep();
  229. },
  230. onClearLog(){
  231. this.logView = "";
  232. },
  233. },
  234. });
  235. },
  236. // register your ipc messages here
  237. messages: {
  238. 'selection-resources:hello' (event) {
  239. }
  240. }
  241. });