diff --git a/bin/app-configure.js b/bin/app-configure.js index 90118e0..e5f5835 100644 --- a/bin/app-configure.js +++ b/bin/app-configure.js @@ -186,9 +186,7 @@ AppConfigure.prototype = { }); break; case 'save': - context.save(configure, function (){ - this.showMessageBox('保存成功!', { type: 'info' }); - }, function (){ + context.save(configure, null, function (){ this.showMessageBox('保存失败!'); }); break; diff --git a/static/js/app/index.js b/static/js/app/index.js index 4f3e7a8..c4713b2 100644 --- a/static/js/app/index.js +++ b/static/js/app/index.js @@ -15,15 +15,19 @@ require('../components/project-base'); require('../components/dynamic-item'); window.addEventListener('DOMContentLoaded', function (){ + function normalize(configure){ + return JSON.parse(JSON.stringify(configure)); + } + var app = new Vue({ el: '#app', data: { activeIndex: 0, - configure: { projects: [] } + configure: {} }, events: { 'save-configure': function (){ - + ipc.send('app-configure', 'save', normalize(this.configure)); } } }); diff --git a/static/js/components/app-configure/index.js b/static/js/components/app-configure/index.js index b31792d..8714abc 100644 --- a/static/js/components/app-configure/index.js +++ b/static/js/components/app-configure/index.js @@ -27,9 +27,22 @@ module.exports = Vue.component('app-configure', { popup: false } }, + computed: { + uniqueCache: function (){ + var cache = {}; + + this.configure.projects && this.configure.projects.forEach(function (project){ + cache[project.name] = true; + }); + + return cache; + } + }, methods: { - focus: function (){ - this.submitError = ''; + focus: function (event){ + if (event.target.type === 'text') { + this.submitError = ''; + } }, appConfigure: function (command, configure){ ipc.send('app-configure', command, configure); @@ -45,25 +58,23 @@ module.exports = Vue.component('app-configure', { addProject: function (){ this.$broadcast('submit'); + console.log(this.uniqueCache[this.name]); + if (this.name && this.path) { - if (this.$data._cached[this.name]) { + if (this.uniqueCache[this.name]) { this.submitError = '项目已存在'; } else { this.popup = false; this.configure.projects.push({ name: this.name, path: this.path }); - this.$data._cached[this.name] = true; // clean imput this.name = ''; this.path = ''; this.submitError = ''; + + this.$dispatch('save-configure'); } } } - }, - created: function (){ - this.configure.projects.forEach(function (project){ - this.$data._cached[project.name] = true; - }, this); } }); diff --git a/static/js/components/project-base/index.js b/static/js/components/project-base/index.js index e4bd219..63df44d 100644 --- a/static/js/components/project-base/index.js +++ b/static/js/components/project-base/index.js @@ -29,8 +29,10 @@ module.exports = Vue.component('project-base', { }; }, methods: { - focus: function (key){ - this[key] = ''; + focus: function (key, event){ + if (event.target.type === 'text') { + this[key] = ''; + } } }, events: { diff --git a/static/js/components/project-base/project-base.html b/static/js/components/project-base/project-base.html index 44a0300..cdac0ba 100644 --- a/static/js/components/project-base/project-base.html +++ b/static/js/components/project-base/project-base.html @@ -1,12 +1,12 @@