51 lines
1.1 KiB
Vue
51 lines
1.1 KiB
Vue
<script>
|
|
import { getToken } from '@/core/utils/auth'
|
|
import { ensureEntry } from '@/core/utils/auth-guard'
|
|
|
|
let bootstrapping = false
|
|
let validatedToken = ''
|
|
|
|
export default {
|
|
onLaunch() {
|
|
this.bootstrapAuth()
|
|
},
|
|
onShow() {
|
|
this.bootstrapAuth()
|
|
},
|
|
methods: {
|
|
async bootstrapAuth() {
|
|
if (bootstrapping) {
|
|
return
|
|
}
|
|
|
|
const token = getToken()
|
|
const forceValidate = !!token && token !== validatedToken
|
|
|
|
bootstrapping = true
|
|
try {
|
|
const result = await ensureEntry(this.$store, forceValidate)
|
|
validatedToken = result.loggedIn ? token : ''
|
|
} finally {
|
|
bootstrapping = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
/* 每个页面公共css */
|
|
@import "@/uni_modules/uview-ui/index.scss";
|
|
@import "common/demo.scss";
|
|
|
|
.status_bar {
|
|
height: var(--status-bar-height);
|
|
background-color: #FFFFFF;
|
|
}
|
|
.normar_container{
|
|
height:100vh;
|
|
display:flex;
|
|
flex-direction: column;
|
|
background-color: #f8f8f8;
|
|
}
|
|
</style> |