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