对登录控制验证进行整理

This commit is contained in:
daihh
2023-03-01 19:25:50 +08:00
parent 8d2a270fa7
commit b874ef5307
9 changed files with 180 additions and 114 deletions

View File

@@ -20,7 +20,13 @@
});
//获取或加载一次用户信息
//console.log('App Launch');
//登录页面不需要,此页面用于本地测试
//console.log(location.href,'location.href');
var href=location.href;
if(href.indexOf('/pages/login/login')==-1){
this.$store.dispatch('GetUserInfo');
}
},
mounted() {
},

View File

@@ -1,9 +1,11 @@
import config from '@/config/index.js'
import {toLogin} from '@/utils/tologin.js'
import {getToken,removeToken} from '@/utils/token.js'
import qs from 'qs'
const ReLoginUrl="/login";
const formatUrl=function(url){
return url;
// if(url.startsWith('http') || url.startsWith('https')){
@@ -32,24 +34,28 @@ const formRequest=function(method,url,data){
dataType: 'json',
header: headers,
success:function(rs,statusCode){
//toLogin();
if(rs.statusCode==200){
if(rs.data.status==401 || rs.data.status==402){
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)
// toLogin();
// //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);
}
@@ -86,20 +92,21 @@ const jsonRequest=function(method,url,data){
if(rs.statusCode==200){
if(rs.data.status==401 || rs.data.status==402){
removeToken();
let loginPath=config.loginPath;
if(loginPath.startsWith('http')){
// #ifdef APP-PLUS
plus.runtime.openURL(loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// #endif
// #ifdef H5
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
// 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);
}

View File

@@ -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);
}

View File

@@ -19,7 +19,7 @@ if(process.env.NODE_ENV === 'development'){
statApiBaseUrl='/statApi';
socialApiBaseUrl='/socialApi';
fileUrl = 'http://127.0.0.1:9090/cdn/upload';
loginPath='/pages/login/login';
loginPath='/mobile/pages/login/login';
scormPlayer='http://localhost:9083/scorm-player';
}else if(process.env.ENV_TYPE === 'preview'){
// 预发布环境,当前配置未使用上

View File

@@ -19,6 +19,7 @@
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,转向登录');
@@ -27,14 +28,13 @@
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.$config.loginPath.startsWith('http')){
let returnUrl=window.location.protocol+'//'+window.location.host+this.$config.context;
location.href=this.$config.loginPath+"?returnUrl="+encodeURIComponent(returnUrl+'/pages/login/loading');
if(this.toUrl){
location.href=this.$config.loginPath+"?returnUrl="+encodeURIComponent(urlPre+'/pages/login/loading?returnUrl='+this.toUrl);
}else{
location.href=this.$config.loginPath;
location.href=this.$config.loginPath+"?returnUrl="+encodeURIComponent(urlPre+'/pages/login/loading');
}
// #endif
}else{
apiLogin.boeLogin(token).then(rs=>{
@@ -49,7 +49,10 @@
// })
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{
@@ -74,8 +77,11 @@
plus.runtime.openURL(this.$config.loginPath) //这里默认使用外部浏览器打开而不是内部web-view组件打开
// #endif
// #ifdef H5
location.href=this.$config.loginPath;
//window.open(this.$config.loginPath)
if(this.toUrl){
location.href=this.$config.loginPath+"?returnUrl="+encodeURIComponent(urlPre+'/pages/login/loading?returnUrl='+this.toUrl);
}else{
location.href=this.$config.loginPath+"?returnUrl="+encodeURIComponent(urlPre+'/pages/login/loading');
}
// #endif
}
}).catch(err=>{

View File

@@ -33,14 +33,17 @@
loginName: '',//10181457
password: '',//666666
loading:false,
redirect: undefined
redirect: ''
}
},
onLoad(options) {
this.redirect=options.returnUrl;
},
mounted() {
//对cookies进行操作这里是写
//document.cookie = "mytest=qweqwe131231; path=/; max-age=" + 30*24*60*60;
console.log('process.env.NODE_ENV',process.env.NODE_ENV);
console.log('process.env.ENV_TYPE',process.env.ENV_TYPE);
//console.log('process.env.NODE_ENV',process.env.NODE_ENV);
//console.log('process.env.ENV_TYPE',process.env.ENV_TYPE);
},
methods: {
submitLogin(){
@@ -63,9 +66,14 @@
// uni.switchTab({
// url:'/pages/index/index'
// })
if($this.redirect){
location.href=$this.redirect;
}else{
uni.switchTab({
url:'/pages/index/index'
})
}
});
}else{
console.log(rs.error);

View File

@@ -84,7 +84,7 @@
</view>
<div v-if="curContent.contentType == 50" style="min-height: 500px;">
<!--因为web-view 动态切换地址不好用所以这里先使用iframe-->
<iframe id="iframe-scorm" v-if="scormUrl" :src="scormUrl" onload="iframeScormLoad()" frameborder="0" scrolling="no" border="0px" style="width:100%;min-height:500px;border:0px;"></iframe>
<iframe id="iframe-scorm" v-if="scormUrl" :src="scormUrl" @load="iframeScormLoad()" frameborder="0" scrolling="no" border="0px" style="width:100%;min-height:500px;border:0px;"></iframe>
</div>
<view v-if="curContent.contentType==52">
<!--外连接-->

33
utils/tologin.js Normal file
View File

@@ -0,0 +1,33 @@
import config from '@/config/index.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;
}
//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='+returnPage);
}
//location.href=config.loginPath
}
}

View File

@@ -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'
@@ -34,21 +35,22 @@ const formRequest=function(method,url,data){
if(rs.statusCode==200){
if(rs.data.status==401 || rs.data.status==402){
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==401 || rs.data.status==402){
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);
}