Files
learning-system-mobile/utils/tologin.js
2023-08-10 11:19:59 +08:00

36 lines
1.3 KiB
JavaScript

import config from '@/config/index.js'
import {removeToken} from '@/utils/token.js'
export function toLogin(ajaxUrl) {
let pageUrl=location.href;
//console.log(pageUrl,'pageUrl');
let urlPre=window.location.protocol+'//'+window.location.host;
//console.log(urlPre,'urlPre');
let urlContext=config.context;
//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');
if(ajaxUrl && ajaxUrl.indexOf('/xboe/portal/init')>-1){
return;
}
//跳转到登录,先把本地的登录信息清空
//removeToken();
//http://localhost:8081/mobile/pages/study/courseStudy?id=1028700304503054336
if(pageUrl.indexOf('returnUrl')>-1){
console.log(pageUrl,'to pageUrl')
//location.href=config.loginPath+"?returnUrl="+pageUrl;
// uni.redirectTo({
// url:config.loginPath
// })
}else{
if(process.env.NODE_ENV === 'development'){
location.href=config.loginPath+"?returnUrl="+encodeURIComponent(returnPage);
}else{
location.href=config.loginPath+"?returnUrl="+encodeURIComponent(urlPre+urlContext+'/pages/login/loading?returnUrl='+encodeURIComponent(returnPage));
}
//location.href=config.loginPath
}
}