app.js
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import './utils/polyfill'
import './app.less'
import { saveCurrentPagePath, hasAuth, silentAuth, navigateToAuth } from '@/utils/authRedirect'
import { useTabbarStore } from '@/stores/tabbar'
const pinia = createPinia()
const App = createApp({
async onLaunch(options) {
const path = options?.path || ''
const query = options?.query || {}
const query_string = Object.keys(query)
.map((key) => `${key}=${encodeURIComponent(query[key])}`)
.join('&')
const full_path = query_string ? `${path}?${query_string}` : path
if (full_path) {
saveCurrentPagePath(full_path)
}
if (path === 'pages/auth/index') return
if (!hasAuth()) {
try {
await silentAuth()
} catch (error) {
console.error('静默授权失败:', error)
navigateToAuth(full_path || undefined)
return
}
}
try {
const tabbarStore = useTabbarStore(pinia)
await tabbarStore.ensureLoaded()
} catch (error) {
console.error('预加载底部导航配置失败:', error)
}
},
onShow() {
},
})
App.use(pinia)
export default App