打开上一次文件支持仓库

This commit is contained in:
purocean
2018-08-06 19:56:50 +08:00
parent 713386010f
commit dae8a4e799
3 changed files with 23 additions and 9 deletions
+10 -3
View File
@@ -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)
}
}
},
+1
View File
@@ -51,6 +51,7 @@ export default {
if (repo) {
this.repo = repo
this.tree = null
this.file = null
}
File.tree(this.repo, tree => {
+12 -6
View File
@@ -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