From dae8a4e79920265eb25880ea901cb1e9999a5517 Mon Sep 17 00:00:00 2001 From: purocean Date: Mon, 6 Aug 2018 19:56:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=BC=80=E4=B8=8A=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=94=AF=E6=8C=81=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/RepositorySwitch.vue | 13 ++++++++++--- frontend/src/components/Tree.vue | 1 + frontend/src/components/TreeNode.vue | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/RepositorySwitch.vue b/frontend/src/components/RepositorySwitch.vue index d3fa59bd..f8bde7a2 100644 --- a/frontend/src/components/RepositorySwitch.vue +++ b/frontend/src/components/RepositorySwitch.vue @@ -23,10 +23,9 @@ export default { } }, created () { + this.current = this.getRepo() this.fetchRepositories() }, - mounted () { - }, beforeDestroy () { }, methods: { @@ -34,19 +33,27 @@ export default { file.fetchRepositories(data => { this.list = data const keys = Object.keys(data) - if (keys.length > 0) { + + if (keys.length > 0 && !keys.includes(this.current)) { this.choose(keys[0]) } }) }, choose (name) { this.current = name + }, + storeRepo (name) { + window.localStorage['repository'] = name + }, + getRepo () { + return window.localStorage['repository'] || null } }, watch: { current (val) { if (val) { this.$bus.emit('switch-repository', val) + this.storeRepo(this.current) } } }, diff --git a/frontend/src/components/Tree.vue b/frontend/src/components/Tree.vue index 72f173af..261e862b 100644 --- a/frontend/src/components/Tree.vue +++ b/frontend/src/components/Tree.vue @@ -51,6 +51,7 @@ export default { if (repo) { this.repo = repo this.tree = null + this.file = null } File.tree(this.repo, tree => { diff --git a/frontend/src/components/TreeNode.vue b/frontend/src/components/TreeNode.vue index 81c190b9..4e864eb7 100644 --- a/frontend/src/components/TreeNode.vue +++ b/frontend/src/components/TreeNode.vue @@ -42,14 +42,20 @@ export default { } }, mounted () { - this.$bus.on('editor-ready', () => { - this.chooseFile(this.getSelectedFilePath()) - }) - this.$bus.on('choose-file', file => { - this.chooseFile(file.path) - }) + this.$bus.on('editor-ready', this.handleEditorReady) + this.$bus.on('choose-file', this.handleChooseFile) + }, + beforeDestroy () { + this.$bus.off('editor-ready', this.handleEditorReady) + this.$bus.off('choose-file', this.handleChooseFile) }, methods: { + handleEditorReady () { + this.chooseFile(this.getSelectedFilePath()) + }, + handleChooseFile (file) { + this.chooseFile(file.path) + }, chooseFile (filePath) { if (this.item.type === 'dir' && filePath.startsWith(this.item.path)) { this.$refs.dir.open = true