Skip to content

Commit cf41912

Browse files
committed
完善页面后退逻辑
1 parent 2ff29bb commit cf41912

1 file changed

Lines changed: 19 additions & 26 deletions

File tree

‎box/chavy.boxjs.html‎

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,10 +1076,10 @@ <h2>{{curbak.name}}</h2>
10761076
</v-main>
10771077
<!-- 底部 -->
10781078
<v-bottom-navigation app grow color="primary" :value="view">
1079-
<v-btn @click="switchView('/')" value="">首页<v-icon>mdi-home</v-icon></v-btn>
1080-
<v-btn @click="switchView('/app')" value="app">应用<v-icon>mdi-application</v-icon></v-btn>
1081-
<v-btn @click="switchView('/sub')" value="sub">订阅<v-icon>mdi-database</v-icon></v-btn>
1082-
<v-btn @click="switchView('/my')" value="my">
1079+
<v-btn @click="switchView('')" value="">首页<v-icon>mdi-home</v-icon></v-btn>
1080+
<v-btn @click="switchView('app')" value="app">应用<v-icon>mdi-application</v-icon></v-btn>
1081+
<v-btn @click="switchView('sub')" value="sub">订阅<v-icon>mdi-database</v-icon></v-btn>
1082+
<v-btn @click="switchView('my')" value="my">
10831083
<template v-if="myIcon">
10841084
<span v-if="!isHideMyTitle">我的</span>
10851085
<v-avatar :size="isHideMyTitle ? 36 : 24"><v-img :src="myIcon" /></v-avatar>
@@ -1524,7 +1524,12 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
15241524
watch: {
15251525
'ui.path': {
15261526
handler(newval, oldval) {
1527+
this.handleHistory(newval)
1528+
if (/^\/#/.test(newval)) {
1529+
newval = newval.replace('/#', '')
1530+
}
15271531
const [, view, subview] = newval.split('/')
1532+
15281533
this.ui.view = view
15291534
this.ui.subview = subview
15301535
if (oldval) {
@@ -1672,9 +1677,7 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
16721677
this.path = defview
16731678
}
16741679
// 监听浏览器后退事件
1675-
window.addEventListener('popstate', (e) => {
1676-
this.path = e.state.url
1677-
}, false)
1680+
window.addEventListener('popstate', (e) => (this.path = e.state.url), false)
16781681
// 如果后端没有渲染数据, 则发出请求获取数据
16791682
if (this.boxServerData) {
16801683
this.box = this.boxServerData
@@ -1694,22 +1697,15 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
16941697
this.ui.scrollY[this.path] = event.currentTarget.scrollY
16951698
},
16961699
handleHistory(path) {
1697-
const state = { title: 'BoxJs', url: path };
1698-
1700+
const state = { title: 'BoxJs', url: path }
16991701
if (!history.state) {
1700-
history.replaceState(state, '');
1702+
history.replaceState(state, '')
17011703
}
1702-
history.pushState(state, '', '#' + path)
1704+
history.pushState(state, '', path)
17031705
},
17041706
// 页面返回
17051707
back() {
1706-
if (this.view === 'bak' && !this.bfpath) {
1707-
this.path = '/my'
1708-
} else if (this.view === 'app' && !this.bfpath) {
1709-
this.path = '/app'
1710-
} else {
1711-
this.path = this.bfpath
1712-
}
1708+
history.back()
17131709
},
17141710
// 切换当前容器环境
17151711
switchEnv(env) {
@@ -1718,37 +1714,34 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
17181714
// 切换当前视图
17191715
switchView(path) {
17201716
if (this.path !== path) {
1721-
this.path = path
1717+
this.path = `/#/${path}`
17221718
} else {
17231719
const scrollY = this.ui.scrollY[this.path]
17241720
const isTopY = _.isNil(scrollY) || scrollY === 0
1725-
if (path === '/app' && isTopY) {
1721+
if (path === '/#/app' && isTopY) {
17261722
Object.assign(this.box.usercfgs, { favapppanel: [], subapppanel: [], sysapppanel: [] })
1727-
} else if (path === '/sub' && isTopY) {
1723+
} else if (path === '/#/sub' && isTopY) {
17281724
this.reloadAppSub()
17291725
}
17301726
if (this.ui.scrollY[path] !== 0) {
17311727
this.$vuetify.goTo(0, { duration: 200, offset: 0 })
17321728
}
17331729
}
1734-
this.handleHistory(path)
17351730
},
17361731
// 切换应用视图
17371732
switchAppView(appId) {
1738-
const path = `/app/${appId}`
1733+
const path = `/#/app/${appId}`
17391734
this.path = path
1740-
this.handleHistory(path)
17411735
},
17421736
// 切换备份视图
17431737
switchBakView(bakId) {
17441738
const bak = this.baks.find((bak) => bak.id === bakId)
1745-
const path = `/bak/${bakId}`
1739+
const path = `/#/bak/${bakId}`
17461740
if (!bak.bak) {
17471741
this.loadGlobalBak().then((resp) => (this.path = path))
17481742
} else {
17491743
this.path = path
17501744
}
1751-
this.handleHistory(path)
17521745
},
17531746
// 重载主题
17541747
loadTheme() {

0 commit comments

Comments
 (0)