mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-06 09:26:45 +08:00
启动时,增加对token的检查
This commit is contained in:
14
App.vue
14
App.vue
@@ -1,5 +1,6 @@
|
||||
<script>
|
||||
import Vue from 'vue'
|
||||
import apiUserbasic from '@/api/boe/userbasic.js'
|
||||
export default {
|
||||
name: 'App',
|
||||
onLaunch: function() {
|
||||
@@ -18,22 +19,21 @@
|
||||
//console.log(this.$width,'$width');
|
||||
}
|
||||
});
|
||||
//获取或加载一次用户信息
|
||||
//console.log('App Launch');
|
||||
//登录页面不需要,此页面用于本地测试
|
||||
//console.log(location.href,'location.href');
|
||||
|
||||
var href=location.href;
|
||||
if(href.indexOf('/pages/login/login')==-1){
|
||||
//不包含登录页和加载页
|
||||
if(href.indexOf('/pages/login/login')==-1 && href.indexOf('/pages/login/loading')==-1){
|
||||
//先做登录校验
|
||||
//每次加载,增加一次对token的验证,直接调用用户中心的接口,如果token不对,这里会直接返回登录
|
||||
apiUserbasic.getUserInfo();
|
||||
this.$store.dispatch('GetUserInfo');
|
||||
}
|
||||
|
||||
},
|
||||
mounted() {
|
||||
},
|
||||
|
||||
onShow: function() {
|
||||
|
||||
|
||||
},
|
||||
onHide: function() {
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import config from '@/config/index.js'
|
||||
import {toLogin} from '@/utils/tologin.js'
|
||||
import {getToken,removeToken} from '@/utils/token.js'
|
||||
import qs from 'qs'
|
||||
|
||||
@@ -35,21 +36,22 @@ const formRequest=function(method,url,data){
|
||||
if(rs.data.status==6001){
|
||||
//uni.removeStorageSync('userInfo');
|
||||
removeToken();
|
||||
let loginPath=config.loginPath;
|
||||
if(loginPath.startsWith('http')){
|
||||
// #ifdef APP-PLUS
|
||||
plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
//window.open(loginPath)
|
||||
let returnUrl=window.location.protocol+'//'+window.location.host+config.context;
|
||||
location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading');
|
||||
// #endif
|
||||
}else{
|
||||
uni.redirectTo({
|
||||
url:loginPath
|
||||
})
|
||||
}
|
||||
toLogin(reUrl);
|
||||
// let loginPath=config.loginPath;
|
||||
// if(loginPath.startsWith('http')){
|
||||
// // #ifdef APP-PLUS
|
||||
// plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
|
||||
// // #endif
|
||||
// // #ifdef H5
|
||||
// //window.open(loginPath)
|
||||
// let returnUrl=window.location.protocol+'//'+window.location.host+config.context;
|
||||
// location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading');
|
||||
// // #endif
|
||||
// }else{
|
||||
// uni.redirectTo({
|
||||
// url:loginPath
|
||||
// })
|
||||
// }
|
||||
}else{
|
||||
resolve(rs.data);
|
||||
}
|
||||
@@ -85,21 +87,22 @@ const jsonRequest=function(method,url,data){
|
||||
if(rs.statusCode==200){
|
||||
if(rs.data.status==6001){
|
||||
removeToken();
|
||||
let loginPath=config.loginPath;
|
||||
if(loginPath.startsWith('http')){
|
||||
// #ifdef APP-PLUS
|
||||
plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
//window.open(loginPath)
|
||||
let returnUrl=window.location.protocol+'//'+window.location.host+config.context;
|
||||
location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading');
|
||||
// #endif
|
||||
}else{
|
||||
uni.redirectTo({
|
||||
url:loginPath
|
||||
})
|
||||
}
|
||||
toLogin(reUrl);
|
||||
// let loginPath=config.loginPath;
|
||||
// if(loginPath.startsWith('http')){
|
||||
// // #ifdef APP-PLUS
|
||||
// plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
|
||||
// // #endif
|
||||
// // #ifdef H5
|
||||
// //window.open(loginPath)
|
||||
// let returnUrl=window.location.protocol+'//'+window.location.host+config.context;
|
||||
// location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading');
|
||||
// // #endif
|
||||
// }else{
|
||||
// uni.redirectTo({
|
||||
// url:loginPath
|
||||
// })
|
||||
// }
|
||||
}else{
|
||||
resolve(rs.data);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ const getUserInfoById = function(id) {
|
||||
return ajax.postJson('/user/list',{id});
|
||||
}
|
||||
|
||||
/**获取当前登录用户的信息*/
|
||||
const getUserInfo = function() {
|
||||
return ajax.postJson('/user/info',{});
|
||||
}
|
||||
|
||||
/**
|
||||
* https://u-pre.boe.com/userbasic/audience/userAudiences
|
||||
* 获取当前用户受众信息
|
||||
@@ -81,6 +86,7 @@ export default {
|
||||
getOrgInfo,
|
||||
findOrgTreeByOrgId,
|
||||
getUserInfoById,
|
||||
getUserInfo,
|
||||
getUserCrowds,
|
||||
getOrgHrbpInfo,
|
||||
modifyPassword,
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
<script>
|
||||
import apiLogin from '@/api/login.js'
|
||||
import {toLogin} from '@/utils/tologin.js'
|
||||
import { getToken,setToken } from '@/utils/token'
|
||||
export default{
|
||||
data(){
|
||||
@@ -28,7 +29,7 @@
|
||||
});
|
||||
this.toUrl=this.toUrl+params;
|
||||
}
|
||||
console.log(this.toUrl,'options.returnUrl');
|
||||
//console.log(this.toUrl,'options.returnUrl');
|
||||
},
|
||||
mounted() {
|
||||
let token=getToken();
|
||||
|
||||
@@ -2,14 +2,14 @@ import config from '@/config/index.js'
|
||||
|
||||
export function toLogin(ajaxUrl) {
|
||||
let pageUrl=location.href;
|
||||
console.log(pageUrl,'pageUrl');
|
||||
//console.log(pageUrl,'pageUrl');
|
||||
let urlPre=window.location.protocol+'//'+window.location.host;
|
||||
console.log(urlPre,'urlPre');
|
||||
//console.log(urlPre,'urlPre');
|
||||
let urlContext=config.context;
|
||||
console.log(urlContext,'urlContext');
|
||||
//console.log(urlContext,'urlContext');
|
||||
let returnPage=pageUrl.substring((urlPre+urlContext).length);
|
||||
console.log(returnPage,'returnPage');
|
||||
console.log(config.loginPath+"?returnUrl="+urlPre+urlContext+'/pages/login/loading?returnUrl='+returnPage,'生成的url');
|
||||
//console.log(returnPage,'returnPage');
|
||||
//console.log(config.loginPath+"?returnUrl="+urlPre+urlContext+'/pages/login/loading?returnUrl='+returnPage,'生成的url');
|
||||
|
||||
if(ajaxUrl && ajaxUrl.indexOf('/xboe/portal/init')>-1){
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user