123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- // panel/index.js, this filename needs to match the one registered in package.json
- var FS = require('fire-fs');
- var Electron = require('electron');
- var CfgUtil = Editor.require("packages://selection-resources/util/CfgUtil");
- var Iokit = Editor.require("packages://selection-resources/util/iokit");
- Editor.Panel.extend({
- // css style for panel
- style: `
- :host {
- padding-left: 10px;
- padding-right: 10px;
- height: auto;
- }
- .container {
- height: 100%;
- overflow-y: auto;
- }
- .button{
- float:right
- }
- ui-box-container{
- min-height: 50px;
- }
- `,
- // html template for panel
- template: `
- <div style="overflow:scroll;height:1200px;">
-
- <h2>挑选资源</h2>
- <hr />
-
- <ui-box-container class="layout vertical left">
- <br>
- <ui-prop name="旧版本路径">
- <div class="flex-1 layout horizontal center">
- <!--ui-input class="flex-2" disabled v-value="OldVersionPath"></ui-input-->
- <ui-input class="flex-2" v-value="OldVersionPath"></ui-input>
- <ui-button v-on:confirm="onSelectOldVersionPath">选择</ui-button>
- <ui-button v-on:confirm="onOpenSelectOldVersionPath">
- <i class="icon-doc-text"></i>
- </ui-button>
- </div>
- </ui-prop>
- <br>
- <ui-prop name="新版本路径">
- <div class="flex-1 layout horizontal center">
- <ui-input class="flex-2" v-value="NewVersionPath"></ui-input>
- <ui-button v-on:confirm="onSelectNewVersionPath">选择</ui-button>
- <ui-button v-on:confirm="onOpenSelectNewVersionPath">
- <i class="icon-doc-text"></i>
- </ui-button>
- </div>
- </ui-prop>
- <br>
- <ui-prop name="生成文件路径">
- <div class="flex-1 layout horizontal center">
- <ui-input class="flex-2" v-value="FinalPath"></ui-input>
- <ui-button v-on:confirm="onSelectFinalPath">选择</ui-button>
- <ui-button v-on:confirm="onOpenSelectFinalPath">
- <i class="icon-doc-text"></i>
- </ui-button>
- </div>
- </ui-prop>
- <br>
- <br>
- <ui-button class="button blue big" @click="save()">开始生成</ui-button>
- <br>
- <label>使用说明:<br>
- 遍历不同版本路径下文件,比对MD5差异<br>
- 把不同的文件拷贝到生成资源路径下<br>
- </label>
- <h2>日志:</h2>
- <textarea class="" id="logTextArea" v-value="logView"
- style="width: 100%; height: 300px; background: #252525; color: #fd942b; border-color: #fd942b;">
- </textarea>
- </ui-box-container>
- <ui-button v-on:confirm="onClearLog">清空日志</ui-button>
- </div>
- `,
- // element and variable binding
- $: {
- logTextArea: '#logTextArea',
- },
- // method executed when template and styles are successfully loaded and initialized
- ready () {
- let logCtrl = this.$logTextArea;
- let logListScrollToBottom = function () {
- setTimeout(function () {
- logCtrl.scrollTop = logCtrl.scrollHeight;
- }, 10);
- };
- let vue = new window.Vue({
- el: this.shadowRoot,
- created(){
- //初始化插件
- this._addLog("初始化插件");
- this.initPlugin();
- },
- data:{
- OldVersionPath:"", //旧版本路径
- NewVersionPath:"", //新版本路径
- FinalPath:"", //最终生成文件路径
- logView:[],
- },
- methods: {
- //面板Log
- _addLog(str,flag) {
- if(flag){
- this.logView += "[" + flag + "]: " + str + "\n";
- }else{
- let time = new Date();
- this.logView += "[" + time.toLocaleString() + "]: " + str + "\n";
- }
- //Editor.log(this.logView);
- logListScrollToBottom();
- },
-
- //初始化插件
- initPlugin(){
- CfgUtil.initCfg(function (data) {
- if (data) {
- this.OldVersionPath = data.OldVersionPath;
- this.NewVersionPath = data.NewVersionPath;
- this.FinalPath = data.FinalPath;
- } else {
- this._saveConfig();
- }
- }.bind(this));
- },
-
- //保存配置信息
- _saveConfig() {
- CfgUtil.saveConfig();
- },
-
- onStopTouchEvent(event){
- event.preventDefault();
- event.stopPropagation();
- },
-
- save() {
- //CfgUtil.commSet("FinalPath",this.FinalPath);
- this._saveConfig();
-
- this._addLog('旧版本:' + this.OldVersionPath);
- this._addLog('新版本:' + this.NewVersionPath);
- this._addLog('生成路径:' + this.FinalPath);
-
- Iokit.build(this.OldVersionPath,this.NewVersionPath,this.FinalPath,
- function (data) {
- if (data) {
- this._addLog("Iokit:" + data);
- }
- }.bind(this)
-
- );
-
- },
- //旧版本
- onSelectOldVersionPath(){
- let path = Editor.Project.path;
- if (this.OldVersionPath && this.OldVersionPath.length > 0) {
- if (FS.existsSync(this.OldVersionPath)) {
- path = this.OldVersionPath;
- }
- }
- let res = Editor.Dialog.openFile({
- title: "选择旧版本目录",
- defaultPath: path,
- properties: ['openFile'],
- });
- if (res !== -1) {
- this.OldVersionPath = res[0];
- CfgUtil.commSet("OldVersionPath",this.OldVersionPath);
- this._saveConfig();
- }
-
- },
- onOpenSelectOldVersionPath(){
- if (!FS.existsSync(this.OldVersionPath)) {
- this._addLog("目录不存在:" + this.OldVersionPath);
- return;
- }
- Electron.shell.showItemInFolder(this.OldVersionPath);
- Electron.shell.beep();
-
- },
- //新版本
- onSelectNewVersionPath(){
- let path = Editor.Project.path;
- if (this.NewVersionPath && this.NewVersionPath.length > 0) {
- if (FS.existsSync(this.NewVersionPath)) {
- path = this.NewVersionPath;
- }
- }
- let res = Editor.Dialog.openFile({
- title: "选择新版本目录",
- defaultPath: path,
- properties: ['openFile'],
- });
- if (res !== -1) {
- this.NewVersionPath = res[0];
- CfgUtil.commSet("NewVersionPath",this.NewVersionPath);
- this._saveConfig();
- }
- },
- onOpenSelectNewVersionPath(){
- if (!FS.existsSync(this.NewVersionPath)) {
- this._addLog('目录不存在!' + this.NewVersionPath);
- return;
- }
- Electron.shell.showItemInFolder(this.NewVersionPath);
- Electron.shell.beep();
- },
- //生成路径
- onSelectFinalPath(){
- let path = Editor.Project.path;
- if (this.FinalPath && this.FinalPath.length > 0) {
- if (FS.existsSync(this.FinalPath)) {
- path = this.FinalPath;
- }
- }
- let res = Editor.Dialog.openFile({
- title: "选择生成文件输出目录",
- defaultPath: path,
- properties: ['openDirectory'],
- });
- if (res !== -1) {
- this.FinalPath = res[0];
- CfgUtil.commSet("FinalPath",this.FinalPath);
- this._saveConfig();
- }
- },
- onOpenSelectFinalPath(){
- if (!FS.existsSync(this.FinalPath)) {
- this._addLog('目录不存在!' + this.FinalPath);
- return;
- }
- Electron.shell.showItemInFolder(this.FinalPath);
- Electron.shell.beep();
- },
- onClearLog(){
- this.logView = "";
- },
- },
- });
-
- },
- // register your ipc messages here
- messages: {
- 'selection-resources:hello' (event) {
- }
- }
- });
|