261 lines
8.7 KiB
HTML
261 lines
8.7 KiB
HTML
|
|
<!DOCTYPE html>
|
|||
|
|
<html lang="zh-CN">
|
|||
|
|
<head>
|
|||
|
|
<meta charset="UTF-8">
|
|||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|||
|
|
<title>系统登录</title>
|
|||
|
|
<script src="js/axios.min.js"></script>
|
|||
|
|
<script src="https://g.alicdn.com/dingding/h5-dingtalk-login/0.21.0/ddlogin.js"></script>
|
|||
|
|
<style>
|
|||
|
|
body {
|
|||
|
|
font-family: 'Arial', sans-serif;
|
|||
|
|
background-image: url('images/b.jpg'); /* 科技感背景 */
|
|||
|
|
background-size: cover;
|
|||
|
|
background-position: center;
|
|||
|
|
display: flex;
|
|||
|
|
justify-content: center;
|
|||
|
|
align-items: center;
|
|||
|
|
height: 100vh;
|
|||
|
|
margin: 0;
|
|||
|
|
color: white;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.logo {
|
|||
|
|
position: absolute; /* 使用绝对定位 */
|
|||
|
|
top: 10px; /* 距离顶部 0px */
|
|||
|
|
left: 10px; /* 距离左侧 0px */
|
|||
|
|
width: 200px; /* 设置宽度 */
|
|||
|
|
height: 50px; /* 设置高度 */
|
|||
|
|
}
|
|||
|
|
.login-container {
|
|||
|
|
/*rgba(12, 20, 41, 0.8);*/
|
|||
|
|
background-color: rgb(3 105 161);
|
|||
|
|
padding: 30px;
|
|||
|
|
border-radius: 15px;
|
|||
|
|
box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
|
|||
|
|
width: 350px;
|
|||
|
|
text-align: center;
|
|||
|
|
position: relative;
|
|||
|
|
}
|
|||
|
|
.tabs {
|
|||
|
|
display: flex;
|
|||
|
|
justify-content: space-around;
|
|||
|
|
margin-bottom: 20px;
|
|||
|
|
}
|
|||
|
|
.tab-button {
|
|||
|
|
background-color: transparent;
|
|||
|
|
border: none;
|
|||
|
|
color: #d6deec;
|
|||
|
|
font-size: 18px;
|
|||
|
|
cursor: pointer;
|
|||
|
|
padding: 10px 20px;
|
|||
|
|
transition: color 0.3s;
|
|||
|
|
}
|
|||
|
|
.tab-button.active {
|
|||
|
|
color: #ffffff;
|
|||
|
|
border-bottom: 2px solid #ffffff;
|
|||
|
|
}
|
|||
|
|
.tab-content {
|
|||
|
|
display: none;
|
|||
|
|
}
|
|||
|
|
.tab-content.active {
|
|||
|
|
display: block;
|
|||
|
|
}
|
|||
|
|
.form-group {
|
|||
|
|
margin-bottom: 20px;
|
|||
|
|
text-align: left;
|
|||
|
|
}
|
|||
|
|
.form-group label {
|
|||
|
|
display: block;
|
|||
|
|
margin-bottom: 5px;
|
|||
|
|
}
|
|||
|
|
.form-group input {
|
|||
|
|
width: calc(100% - 22px); /* 调整输入框宽度以适应边距 */
|
|||
|
|
padding: 10px;
|
|||
|
|
border: 1px solid #4d5569;
|
|||
|
|
border-radius: 5px;
|
|||
|
|
/* #1e293b */
|
|||
|
|
background-color: #dde1e7;
|
|||
|
|
color: black;
|
|||
|
|
}
|
|||
|
|
.button {
|
|||
|
|
display: inline-block;
|
|||
|
|
padding: 10px 20px;
|
|||
|
|
margin-top: 10px;
|
|||
|
|
border: none;
|
|||
|
|
border-radius: 5px;
|
|||
|
|
cursor: pointer;
|
|||
|
|
color: white;
|
|||
|
|
font-size: 16px;
|
|||
|
|
transition: background-color 0.3s;
|
|||
|
|
width: calc(100% - 22px); /* 调整按钮宽度以适应边距 */
|
|||
|
|
}
|
|||
|
|
.login-btn {
|
|||
|
|
background-color: #0ea5e9;
|
|||
|
|
}
|
|||
|
|
.login-btn:hover {
|
|||
|
|
background-color: #0c8ab8;
|
|||
|
|
}
|
|||
|
|
.qr-code img {
|
|||
|
|
width: 250px;
|
|||
|
|
height: 250px;
|
|||
|
|
border-radius: 10px;
|
|||
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
|
|||
|
|
}
|
|||
|
|
.qr-code iframe {
|
|||
|
|
width: 300px;
|
|||
|
|
height: 300px;
|
|||
|
|
border-radius: 10px;
|
|||
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
</style>
|
|||
|
|
</head>
|
|||
|
|
<body>
|
|||
|
|
<img id="logo" class="logo" src="images/logo2.jpg"/>
|
|||
|
|
<div class="login-container">
|
|||
|
|
<h2 style="margin-bottom: 10px;" id="title">
|
|||
|
|
欢迎登录</h2>
|
|||
|
|
<div class="tabs">
|
|||
|
|
<button class="tab-button active" onclick="showTab('credentials')">帐号登录</button>
|
|||
|
|
<button class="tab-button" onclick="showTab('wechat')">企业微信</button>
|
|||
|
|
<button class="tab-button" onclick="showTab('dingtalk')">钉钉扫码</button>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<!-- 账号密码登录 -->
|
|||
|
|
<div id="credentials" class="tab-content active">
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label for="username">用户名</label>
|
|||
|
|
<input type="text" id="username" placeholder="请输入用户名">
|
|||
|
|
</div>
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label for="password">密码</label>
|
|||
|
|
<input type="password" id="telphone" placeholder="请输入密码">
|
|||
|
|
</div>
|
|||
|
|
<button class="button login-btn" onclick="login()">登录</button>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<!-- 微信登录 -->
|
|||
|
|
<div id="wechat" class="tab-content">
|
|||
|
|
<div class="qr-code">
|
|||
|
|
<img src="https://gw.alicdn.com/imgextra/i2/O1CN01ZGwvTz1OQrUqDUCnI_!!6000000001184-2-o.png" alt="WeChat QR Code">
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<!-- 钉钉登录 -->
|
|||
|
|
<div id="dingtalk" class="tab-content">
|
|||
|
|
<div class="qr-code" id="self_defined_element">
|
|||
|
|
<img src="https://gw.alicdn.com/imgextra/i2/O1CN01ZGwvTz1OQrUqDUCnI_!!6000000001184-2-o.png" alt="DingTalk QR Code">
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
<marquee scrollamount="3" style="text-align: left; margin-top: 15px; font-size: 14px;" id="demo">具体描述</marquee>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<script>
|
|||
|
|
function showTab(tabName) {
|
|||
|
|
const tabs = document.querySelectorAll('.tab-button');
|
|||
|
|
const contents = document.querySelectorAll('.tab-content');
|
|||
|
|
|
|||
|
|
tabs.forEach(tab => tab.classList.remove('active'));
|
|||
|
|
contents.forEach(content => content.classList.remove('active'));
|
|||
|
|
|
|||
|
|
document.querySelector(`#${tabName}`).classList.add('active');
|
|||
|
|
document.querySelector(`button[onclick*='${tabName}']`).classList.add('active');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var kagent; //配置信息
|
|||
|
|
const url = new URL(window.location.href);
|
|||
|
|
|
|||
|
|
axios.get('/api/login_cfg').then(response => {
|
|||
|
|
kagent = response.data;
|
|||
|
|
|
|||
|
|
//logo配置
|
|||
|
|
if (kagent.logo!=""){
|
|||
|
|
document.getElementById("logo").src="/api/img/"+kagent.logo;
|
|||
|
|
}
|
|||
|
|
document.getElementById("demo").innerHTML=kagent.slogan;
|
|||
|
|
|
|||
|
|
if ("dingtalk" in kagent){
|
|||
|
|
|
|||
|
|
var redirect_uri=window.location.protocol+"//"+url.hostname;
|
|||
|
|
if (window.location.port==""){
|
|||
|
|
redirect_uri = redirect_uri+'/api/dingtalk_auth'
|
|||
|
|
}else{
|
|||
|
|
redirect_uri = redirect_uri+':'+window.location.port+'/api/dingtalk_auth'
|
|||
|
|
}
|
|||
|
|
console.info(redirect_uri);
|
|||
|
|
|
|||
|
|
//钉钉登录
|
|||
|
|
window.DTFrameLogin(
|
|||
|
|
{
|
|||
|
|
id: 'self_defined_element',
|
|||
|
|
width: 250,
|
|||
|
|
height: 250,
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
redirect_uri: encodeURIComponent(redirect_uri),
|
|||
|
|
client_id: kagent.dingtalk.client_id,
|
|||
|
|
scope: 'openid',
|
|||
|
|
response_type: 'code',
|
|||
|
|
state: "k3gpt",
|
|||
|
|
prompt: 'consent',
|
|||
|
|
exclusiveLogin: "true",
|
|||
|
|
exclusiveCorpId: kagent.dingtalk.corpid,
|
|||
|
|
|
|||
|
|
},
|
|||
|
|
(loginResult) => {
|
|||
|
|
const {redirectUrl, authCode, state} = loginResult;
|
|||
|
|
// 这里可以直接进行重定向
|
|||
|
|
window.location.href = redirectUrl;
|
|||
|
|
// 也可以在不跳转页面的情况下,使用code进行授权
|
|||
|
|
//console.log(authCode);
|
|||
|
|
},
|
|||
|
|
(errorMsg) => {
|
|||
|
|
// 这里一般需要展示登录失败的具体原因,可以使用toast等轻提示
|
|||
|
|
console.error(`errorMsg of errorCbk: ${errorMsg}`);
|
|||
|
|
alert(errorMsg);
|
|||
|
|
},
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
}).catch(error => {
|
|||
|
|
console.error('Error fetching data:', error);
|
|||
|
|
throw error; // 重新抛出错误以便调用者可以处理
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
//登录
|
|||
|
|
function login(){
|
|||
|
|
// 其它类型
|
|||
|
|
var newItem = {
|
|||
|
|
username: document.getElementById("username").value,
|
|||
|
|
telphone: document.getElementById("telphone").value,
|
|||
|
|
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
if (newItem.username=="" || telphone==""){
|
|||
|
|
|
|||
|
|
alert("用户名或密码没有输入!")
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
// 使用 axios 发送 POST 请求
|
|||
|
|
axios.post('/api/login', newItem)
|
|||
|
|
.then(response =>{
|
|||
|
|
|
|||
|
|
if (response.data.code==200){
|
|||
|
|
window.location.href=response.data.url;
|
|||
|
|
}else{
|
|||
|
|
alert(response.data.msg);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
})
|
|||
|
|
.catch(error => {
|
|||
|
|
console.error('Error post data:', error);
|
|||
|
|
throw error; // 重新抛出错误以便调用者可以处理
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
</script>
|
|||
|
|
</body>
|
|||
|
|
</html>
|