41 lines
996 B
Vue
41 lines
996 B
Vue
<script>
|
|
import config from './config'
|
|
import { getToken } from '@/utils/auth'
|
|
|
|
export default {
|
|
onLaunch: function() {
|
|
this.initApp()
|
|
},
|
|
methods: {
|
|
// 初始化应用
|
|
initApp() {
|
|
// 初始化应用配置
|
|
this.initConfig()
|
|
// 检查用户登录状态
|
|
//#ifdef H5
|
|
this.checkLogin()
|
|
//#endif
|
|
},
|
|
initConfig() {
|
|
this.globalData.config = config
|
|
},
|
|
checkLogin() {
|
|
const token = getToken()
|
|
if (!token) {
|
|
this.$tab.reLaunch('/subpages/auth/login')
|
|
} else {
|
|
// 有 token 时重新获取用户信息,恢复 Vuex 状态
|
|
this.$store.dispatch('GetInfo').catch(() => {
|
|
// 如果获取用户信息失败,说明 token 可能过期,跳转到登录页
|
|
this.$tab.reLaunch('/subpages/auth/login')
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
@import '@/static/scss/index.scss'
|
|
</style>
|