first commit
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<!--sso login-->
|
||||
<template>
|
||||
<view class="container">
|
||||
<web-view :src="url"></web-view>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
url:'',
|
||||
intervalId:null,
|
||||
newUrl:'',
|
||||
siteData:null
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
this.siteData = uni.getStorageSync("siteData");
|
||||
if(options && options.uid && options.pwd){
|
||||
let username = options.uid.replaceAll(" ", "+");
|
||||
let password = options.pwd.replaceAll(" ", "+");
|
||||
this.url = this.siteData.internalUrl + this.siteData.apiPath + "/app/sso/login_saml_with_mfa?username="+encodeURIComponent(username)+"&password="+encodeURIComponent(password);
|
||||
}
|
||||
if (options && options.url){
|
||||
this.url = options.url;
|
||||
}
|
||||
this.listenUrl()
|
||||
},
|
||||
onShow() {
|
||||
this.siteData = uni.getStorageSync("siteData");
|
||||
},
|
||||
methods: {
|
||||
listenUrl() {
|
||||
var that = this;
|
||||
var count = 0;
|
||||
this.intervalId = setInterval(() => {
|
||||
var currentUrl = that.getCurrentUrl();
|
||||
that.newUrl = currentUrl;
|
||||
var code = that.getCurrentQueryString(currentUrl, 'SAMLResponse');
|
||||
var errorCode = that.getCurrentQueryString(currentUrl, 'errorCode');
|
||||
//uni.$u.toast('url1='+currentUrl);
|
||||
if(currentUrl.indexOf('/sso_callback/login')!=-1){
|
||||
//uni.$u.toast('url2='+currentUrl);
|
||||
if (code){
|
||||
//uni.$u.toast('get code');
|
||||
clearInterval(that.intervalId);
|
||||
uni.redirectTo({
|
||||
url:'/pages/login/login?code='+encodeURIComponent(code)
|
||||
})
|
||||
}
|
||||
else if (errorCode){
|
||||
//uni.$u.toast('get errorcode');
|
||||
clearInterval(that.intervalId);
|
||||
uni.redirectTo({
|
||||
url:'/pages/idpLogin/idpLogin?errorCode='+encodeURIComponent(errorCode)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}, 1000);
|
||||
},
|
||||
getCurrentQueryString(url, name) {
|
||||
try{
|
||||
var queryString = url.substring(url.indexOf('?'));
|
||||
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
|
||||
var r = queryString.substr(1).match(reg);
|
||||
if (r != null) {
|
||||
return unescape(r[2]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch(e){
|
||||
uni.$u.toast('getCurrentQueryString exception:'+e.errMsg);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
getCurrentUrl(){
|
||||
var pages = getCurrentPages();
|
||||
var page = pages[pages.length - 1];
|
||||
var currentWebview = page.$getAppWebview();
|
||||
var url = currentWebview.children()[0].getURL();
|
||||
console.log("=======当前地址======", url);
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user