Skip to content

Commit 59dc61d

Browse files
authored
Merge pull request chavyleung#216 from id77/master
webApp 不适用 pushState
2 parents c7457cb + 9172f14 commit 59dc61d

1 file changed

Lines changed: 21 additions & 25 deletions

File tree

‎box/chavy.boxjs.html‎

Lines changed: 21 additions & 25 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,18 @@ <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+
// if (this.isWebApp == true) {
1701+
// return
1702+
// }
1703+
const state = { title: 'BoxJs', url: path }
16991704
if (!history.state) {
1700-
history.replaceState(state, '');
1705+
history.replaceState(state, '')
17011706
}
17021707
history.pushState(state, '', path)
17031708
},
17041709
// 页面返回
17051710
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-
}
1711+
history.back()
17131712
},
17141713
// 切换当前容器环境
17151714
switchEnv(env) {
@@ -1718,37 +1717,34 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
17181717
// 切换当前视图
17191718
switchView(path) {
17201719
if (this.path !== path) {
1721-
this.path = path
1720+
this.path = `/#/${path}`
17221721
} else {
17231722
const scrollY = this.ui.scrollY[this.path]
17241723
const isTopY = _.isNil(scrollY) || scrollY === 0
1725-
if (path === '/app' && isTopY) {
1724+
if (path === '/#/app' && isTopY) {
17261725
Object.assign(this.box.usercfgs, { favapppanel: [], subapppanel: [], sysapppanel: [] })
1727-
} else if (path === '/sub' && isTopY) {
1726+
} else if (path === '/#/sub' && isTopY) {
17281727
this.reloadAppSub()
17291728
}
17301729
if (this.ui.scrollY[path] !== 0) {
17311730
this.$vuetify.goTo(0, { duration: 200, offset: 0 })
17321731
}
17331732
}
1734-
this.handleHistory(path)
17351733
},
17361734
// 切换应用视图
17371735
switchAppView(appId) {
1738-
const path = `/app/${appId}`
1736+
const path = `/#/app/${appId}`
17391737
this.path = path
1740-
this.handleHistory(path)
17411738
},
17421739
// 切换备份视图
17431740
switchBakView(bakId) {
17441741
const bak = this.baks.find((bak) => bak.id === bakId)
1745-
const path = `/bak/${bakId}`
1742+
const path = `/#/bak/${bakId}`
17461743
if (!bak.bak) {
17471744
this.loadGlobalBak().then((resp) => (this.path = path))
17481745
} else {
17491746
this.path = path
17501747
}
1751-
this.handleHistory(path)
17521748
},
17531749
// 重载主题
17541750
loadTheme() {

0 commit comments

Comments
 (0)