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) let sum = state.upload.progress.reduce((acc, val) => acc + val)
return Math.ceil(sum / state.upload.size * 100); 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, previewMode: false,
hash: '', hash: '',
lastViewed: { lastViewed: {
path: '', paths: [],
clicked: '', details: new Map()
pageOffset: 0
} }
} }

View File

@ -88,7 +88,14 @@ const mutations = {
state.previewMode = value state.previewMode = value
}, },
setHash: (state, value) => (state.hash = 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 export default mutations

View File

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