mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-09 10:56:47 +08:00
104 lines
2.8 KiB
Vue
104 lines
2.8 KiB
Vue
<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;
|
|
},
|
|
mounted() {
|
|
let token=getToken();
|
|
let $this=this;
|
|
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
|
|
window.open(this.$config.loginPath)
|
|
// #endif
|
|
}else{
|
|
console.log('获取用户信息');
|
|
apiLogin.boeLogin(token).then(rs=>{
|
|
if(rs.status==200){
|
|
console.log('获取用户信息成功');
|
|
//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;
|
|
if(openUrl){
|
|
console.log('跳转url='+openUrl);
|
|
if(openUrl.startsWith('http')){
|
|
//alert('跳转url0='+openUrl)
|
|
location.href=openUrl
|
|
}else{
|
|
if(openUrl=='/pages/index/index' || openUrl=='/pages/study/index' || openUrl=='/pages/plus/index' || openUrl=='/pages/my/index'){
|
|
//alert('跳转url1='+openUrl)
|
|
uni.switchTab({
|
|
url:openUrl
|
|
})
|
|
}else{
|
|
//alert('跳转url2='+openUrl)
|
|
uni.navigateTo({url:openUrl})
|
|
}
|
|
}
|
|
}else{
|
|
console.log('跳转到首页');
|
|
alert('跳转到首页')
|
|
uni.switchTab({
|
|
url:'/pages/index/index'
|
|
})
|
|
}
|
|
|
|
}).catch(error => {
|
|
console.log('加载用户信息错误:',error);
|
|
alert('加载用户信息错误')
|
|
uni.showModal({
|
|
title:'错误',
|
|
content:error
|
|
})
|
|
})
|
|
}else{
|
|
alert('加载用户错误')
|
|
console.log(rs.message+','+rs.error);
|
|
//#ifdef APP-PLUS
|
|
plus.runtime.openURL(this.$config.loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
|
|
// #endif
|
|
// #ifdef H5
|
|
location.href=this.$config.loginPath;
|
|
//window.open(this.$config.loginPath)
|
|
// #endif
|
|
}
|
|
}).catch(err=>{
|
|
//
|
|
alert('请求超时')
|
|
uni.showToast({
|
|
title:'请求超时'
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
</style>
|