2021-08-16 19:20:44 +08:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<title>Sa-Token-SSO-Client端-登录页</title>
|
|
|
|
|
<style type="text/css">
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div class="login-box">
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
<script src="https://unpkg.zhimg.com/jquery@3.4.1/dist/jquery.min.js"></script>
|
|
|
|
|
<script>window.jQuery || alert('当前页面CDN服务商已宕机,请将所有js包更换为本地依赖')</script>
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
|
|
// 后端接口地址
|
2024-05-17 11:41:42 +08:00
|
|
|
|
var baseUrl = "http://sa-sso-client1.com:9002";
|
2021-08-16 19:20:44 +08:00
|
|
|
|
|
|
|
|
|
var back = getParam('back', '/');
|
|
|
|
|
var ticket = getParam('ticket');
|
|
|
|
|
$(function() {
|
|
|
|
|
if(ticket) {
|
|
|
|
|
doLoginByTicket(ticket);
|
|
|
|
|
} else {
|
|
|
|
|
goSsoAuthUrl();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 重定向至认证中心
|
|
|
|
|
function goSsoAuthUrl() {
|
2022-08-20 12:05:36 +08:00
|
|
|
|
sa.ajax('/sso/getSsoAuthUrl', {clientLoginUrl: location.href}, function(res) {
|
2021-08-16 19:20:44 +08:00
|
|
|
|
console.log(res);
|
|
|
|
|
location.href = res.data;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据ticket值登录
|
|
|
|
|
function doLoginByTicket(ticket) {
|
2022-08-20 12:05:36 +08:00
|
|
|
|
sa.ajax('/sso/doLoginByTicket', {ticket: ticket}, function(res) {
|
2021-08-16 19:20:44 +08:00
|
|
|
|
console.log(res);
|
|
|
|
|
if(res.code == 200) {
|
|
|
|
|
localStorage.setItem('satoken', res.data);
|
|
|
|
|
location.href = decodeURIComponent(back);
|
2022-04-29 03:23:46 +08:00
|
|
|
|
} else {
|
|
|
|
|
alert(res.msg);
|
2021-08-16 19:20:44 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从url中查询到指定名称的参数值
|
|
|
|
|
function getParam(name, defaultValue){
|
|
|
|
|
var query = window.location.search.substring(1);
|
|
|
|
|
var vars = query.split("&");
|
|
|
|
|
for (var i=0;i<vars.length;i++) {
|
|
|
|
|
var pair = vars[i].split("=");
|
|
|
|
|
if(pair[0] == name){return pair[1];}
|
|
|
|
|
}
|
|
|
|
|
return(defaultValue == undefined ? null : defaultValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
var sa = {};
|
|
|
|
|
|
|
|
|
|
// 封装一下Ajax
|
|
|
|
|
sa.ajax = function(url, data, successFn) {
|
|
|
|
|
// sa.loading("正在努力加载...");
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: baseUrl + url,
|
|
|
|
|
type: "post",
|
|
|
|
|
data: data,
|
|
|
|
|
dataType: 'json',
|
|
|
|
|
headers: {
|
|
|
|
|
satoken: localStorage.getItem('satoken')
|
|
|
|
|
},
|
|
|
|
|
success: function(res){
|
|
|
|
|
console.log('返回数据:', res);
|
|
|
|
|
successFn(res);
|
|
|
|
|
},
|
|
|
|
|
error: function(xhr, type, errorThrown){
|
|
|
|
|
if(xhr.status == 0){
|
|
|
|
|
return alert('无法连接到服务器,请检查网络');
|
|
|
|
|
}
|
|
|
|
|
return alert("异常:" + JSON.stringify(xhr));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|