Files
learning-system-mobile/pages/login/loading.vue
2023-03-02 10:47:30 +08:00

101 lines
3.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view>
<u-loading-page loadingText="加载中...." :loading="true"></u-loading-page>
</view>
</template>
<script>
import apiLogin from '@/api/login.js'
import { getToken,setToken } from '@/utils/token'
export default{
data(){
return {
toUrl:''
}
},
onLoad(options) {
this.toUrl=options.returnUrl;
console.log(this.toUrl,'options.returnUrl');
},
mounted() {
let token=getToken();
let $this=this;
let urlPre=window.location.protocol+'//'+window.location.host+this.$config.context;
//console.log(token,'得到token');
if(!token){
console.log('未获得token,转向登录');
//this.$router.push({ path: process.env.VUE_APP_LOGIN_URL })
// #ifdef APP-PLUS
plus.runtime.openURL(this.$config.loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// #endif
// #ifdef H5
//console.log('this.toUrl',this.toUrl);
//console.log('this.$config.loginPath',this.$config.loginPath);
if(this.toUrl){
location.href=this.$config.loginPath+"?returnUrl="+encodeURIComponent(urlPre+'/pages/login/loading?returnUrl='+encodeURIComponent(this.toUrl));
}else{
location.href=this.$config.loginPath+"?returnUrl="+encodeURIComponent(urlPre+'/pages/login/loading');
}
// #endif
}else{
apiLogin.boeLogin(token).then(rs=>{
if(rs.status==200){
//setToken(rs.result.access_token);
//加载用户信息
this.$store.dispatch("InitData").then(res => {
//console.log(res)
//this.$watermark.set(res.result.name + res.result.loginName);
// uni.switchTab({
// url:'/pages/index/index'
// })
uni.setStorageSync("boe_new_login",1);//记录新登录
let openUrl=$this.toUrl;
console.log(openUrl);
//http://localhost:8081/mobile/pages/login/loading?returnUrl=/pages/study/courseStudy?id=1028700304503054336
if(openUrl){
//如果openUrl的页面不存在或不对就会出现跳转不动的问题这个情况
if(openUrl.startsWith('http')){
location.href=openUrl
}else{
if(openUrl=='/pages/index/index' || openUrl=='/pages/study/index' || openUrl=='/pages/plus/index' || openUrl=='/pages/my/index'){
uni.switchTab({
url:openUrl
})
}else{
uni.navigateTo({url:openUrl})
}
}
}else{
uni.switchTab({
url:'/pages/index/index'
})
}
});
}else{
console.log(rs.message+','+rs.error);
//#ifdef APP-PLUS
plus.runtime.openURL(this.$config.loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// #endif
// #ifdef H5
if(this.toUrl){
location.href=this.$config.loginPath+"?returnUrl="+encodeURIComponent(urlPre+'/pages/login/loading?returnUrl='+encodeURIComponent(this.toUrl));
}else{
location.href=this.$config.loginPath+"?returnUrl="+encodeURIComponent(urlPre+'/pages/login/loading');
}
// #endif
}
}).catch(err=>{
//
uni.showToast({
title:'请求超时'
})
})
}
}
}
</script>
<style>
</style>