store multiple navigation info

This commit is contained in:
Weidi Deng 2021-01-07 11:58:59 +08:00
parent e73c6e6019
commit 0bd9ece0e6
4 changed files with 38 additions and 28 deletions

View File

@ -13,6 +13,15 @@ const getters = {
let sum = state.upload.progress.reduce((acc, val) => acc + val)
return Math.ceil(sum / state.upload.size * 100);
},
getLastViewedDetail: state => (path) => {
if (state.lastViewed.details.has(path)) {
let i = state.lastViewed.paths.indexOf(path)
state.lastViewed.paths.splice(i, 1)
state.lastViewed.paths.push(path)
return state.lastViewed.details.get(path)
}
return null
}
}

View File

@ -27,9 +27,8 @@ const state = {
previewMode: false,
hash: '',
lastViewed: {
path: '',
clicked: '',
pageOffset: 0
paths: [],
details: new Map()
}
}

View File

@ -88,7 +88,14 @@ const mutations = {
state.previewMode = value
},
setHash: (state, value) => (state.hash = value),
setLastViewed: (state, value) => (state.lastViewed = value)
addLastViewed: (state, value) => {
let paths = state.lastViewed.paths
if (!state.lastViewed.details.has(value.path)) paths.push(value.path)
state.lastViewed.details.set(value.path, value.detail)
if (paths.length > 10) {
state.lastViewed.details.delete(paths.shift())
}
}
}
export default mutations

View File

@ -55,7 +55,8 @@ export default {
'selectedCount',
'isListing',
'isEditor',
'isFiles'
'isFiles',
'getLastViewedDetail'
]),
...mapState([
'req',
@ -63,8 +64,7 @@ export default {
'reload',
'multiple',
'loading',
'show',
'lastViewed'
'show'
]),
isPreview () {
return !this.loading && !this.isListing && !this.isEditor || this.loading && this.$store.state.previewMode
@ -131,40 +131,35 @@ export default {
methods: {
...mapMutations([ 'setLoading' ]),
async nav() {
if (!this.isPreview && !this.isEditor && clean(`/${this.$route.params.pathMatch}`) !== clean(this.lastViewed.path) && clean(`/${this.$route.params.pathMatch}`).startsWith(clean(this.lastViewed.path))) {
if (!this.isPreview && !this.isEditor && clean(`/${this.$route.params.pathMatch}`).startsWith(clean(this.req.path))) {
let dirs = clean(this.$route.fullPath).split("/")
this.$store.commit('setLastViewed', {
path: this.req.path,
clicked: decodeURIComponent(dirs[dirs.length - 1]),
pageOffset: window.pageYOffset
this.$store.commit('addLastViewed', {
path: clean(this.req.path),
detail: {
clicked: decodeURIComponent(dirs[dirs.length - 1]),
pageOffset: window.pageYOffset
}
})
this.fetchData()
} else if (clean(this.lastViewed.path) === clean(`/${this.$route.params.pathMatch}`)) {
await this.fetchData()
let offset = 1000, oldPageOffset = 0, pageOffset = window.pageYOffset, _this = this
let int = setInterval(function() {
}
await this.fetchData()
let detail = this.getLastViewedDetail(clean(`/${this.$route.params.pathMatch}`))
if (detail !== null) {
let offset = Math.min(1000, detail.pageOffset), oldPageOffset = 0, pageOffset = window.pageYOffset
let int = setInterval(function () {
window.scrollTo(0, offset)
oldPageOffset = pageOffset
pageOffset = window.pageYOffset
if (offset >= _this.lastViewed.pageOffset || oldPageOffset === pageOffset) clearInterval(int);
offset += Math.min(1000, _this.lastViewed.pageOffset - offset)
if (offset >= detail.pageOffset || oldPageOffset === pageOffset) clearInterval(int);
offset += Math.min(1000, detail.pageOffset - offset)
}, 20);
for (let i = 0; i < this.req.items.length; i++) {
if (this.req.items[i].name === this.lastViewed.clicked) {
if (this.req.items[i].name === detail.clicked) {
this.$store.commit('addSelected', i)
break
}
}
} else {
this.$store.commit('setLastViewed', {
path: '',
clicked: '',
pageOffset: 0
})
this.fetchData()
}
},
async fetchData () {