优化体验

This commit is contained in:
purocean
2019-08-26 12:47:52 +08:00
parent 1c00c99f9e
commit 01c6d19c0f
2 changed files with 18 additions and 12 deletions
+10 -12
View File
@@ -63,9 +63,11 @@ export default {
}
}, 500)
},
mounted () {
async mounted () {
this.$refs.input.focus()
this.updateDataSource()
await this.$store.dispatch('app/fetchMarkedFiles')
this.updateDataSource()
},
methods: {
travelFiles (tree) {
@@ -136,12 +138,7 @@ export default {
if (this.currentTab === 'file') {
this.list = this.files
} else if (this.currentTab === 'marked') {
this.list = null
file.markedFiles().then(result => {
if (this.currentTab === 'marked') {
this.list = result.map(x => ({ ...x, name: file.basename(x.path) }))
}
})
this.list = this.markedFiles
} else if (this.currentTab === 'search') {
this.list = null
this.searchWithDebounce(this.searchText.trim(), data => {
@@ -150,18 +147,16 @@ export default {
}
})
}
this.$nextTick(this.highlightText(this.searchText.trim()))
},
updateSelected (item = null) {
if (this.list === null) {
if (this.dataList === null) {
return
}
if (item) {
this.selected = item
} else {
this.selected = this.list.length > 0 ? this.list[0] : null
this.selected = this.dataList.length > 0 ? this.dataList[0] : null
}
this.$nextTick(() => {
@@ -227,6 +222,9 @@ export default {
searchText () {
this.updateDataSource()
},
dataList () {
this.$nextTick(() => this.highlightText(this.searchText.trim()))
},
currentTab () {
this.list = null
this.$refs.input.focus()
@@ -234,7 +232,7 @@ export default {
}
},
computed: {
...mapState('app', ['currentRepo', 'recentOpenTime', 'tree']),
...mapState('app', ['currentRepo', 'recentOpenTime', 'tree', 'markedFiles']),
files () {
return this.travelFiles(this.tree || [])
},
+8
View File
@@ -52,8 +52,12 @@ export default {
line: 0,
column: 0
},
markedFiles: [],
},
mutations: {
setMarkedFiles (state, files) {
state.markedFiles = files
},
setPasswordHash (state, { file, passwordHash }) {
if (file && passwordHash) {
state.passwordHash = { ...state.passwordHash, [`${file.repo}|${file.path}`]: passwordHash }
@@ -108,6 +112,10 @@ export default {
getters: {
},
actions: {
async fetchMarkedFiles ({ commit }) {
const files = (await file.markedFiles()).map(x => ({ ...x, name: file.basename(x.path) }))
commit('setMarkedFiles', files)
},
async fetchRepositories ({ commit }) {
const data = await file.fetchRepositories()
commit('setRepositories', data)