This commit is contained in:
2025-11-19 19:42:47 +08:00
parent e0cf330ca2
commit 7ccd1dcd8e

316
main/x/login.html Normal file
View File

@@ -0,0 +1,316 @@
<!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>
<script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
<style>
body {
font-family: 'Arial', sans-serif;
background-image: url('/x/b.jpg'); /* 科技感背景 */
background-size: cover;
background-position: center;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
color: white;
}
.login-container {
/*#2c3e50 #0857a6 #021d39 */
background: linear-gradient(to bottom, #9333ea, #021d39); /* 紫色到蓝色的渐变 */
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-code1 img {
width: 300px;
height: 300px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
.qr-code2 img {
width: 300px;
height: 300px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
.qr-code2 iframe {
width: 300px;
height: 300px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
#wechat_element iframe {
width: 300px;
height: 300px;
border-radius: 10px;
}
.logo {
position: absolute; /* 使用绝对定位 */
top: 10px; /* 距离顶部 0px */
left: 10px; /* 距离左侧 0px */
width: 200px; /* 设置宽度 */
height: 50px; /* 设置高度 */
}
</style>
</head>
<body>
<!--<img id="logo" class="logo" src="/ui/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="text" id="telphone" placeholder="请输入手机号码(必填)">
</div>
<div class="form-group">
<label for="password">单位信息</label>
<input type="text" id="org" placeholder="公司名称、职务、E-Mail等信息">
</div>
<button class="button login-btn" onclick="login()">登录</button>
</div>
<!-- 微信登录 -->
<div id="wechat" class="tab-content">
<div class="qr-code1" id="wechat_element">
<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-code2" id="self_defined_element">
<img src="https://gw.alicdn.com/imgextra/i2/O1CN01ZGwvTz1OQrUqDUCnI_!!6000000001184-2-o.png" alt="WeChat 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');
}
const url = new URL(window.location.href);
var Agent_Kasn = url.searchParams.get('sn');
var kagent; //配置信息
axios.get('/api/kagent_cfg/'+this.Agent_Kasn).then(response => {
kagent = response.data;
//智能体名称
document.getElementById("title").innerText=kagent.title;
document.title= this.kagent.title+"_系统登录";
document.getElementById("demo").innerHTML=kagent.demo;
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: 300,
height: 300,
},
{
redirect_uri: encodeURIComponent(redirect_uri),
client_id: kagent.dingtalk.client_id,
scope: 'openid',
response_type: 'code',
state: Agent_Kasn,
prompt: 'consent',
exclusiveLogin: kagent.dingtalk.close_login,
exclusiveCorpId: kagent.dingtalk.cropid,
},
(loginResult) => {
const {redirectUrl, authCode, state} = loginResult;
// 这里可以直接进行重定向
window.location.href = redirectUrl;
// 也可以在不跳转页面的情况下使用code进行授权
//console.log(authCode);
},
(errorMsg) => {
// 这里一般需要展示登录失败的具体原因,可以使用toast等轻提示
console.error(`errorMsg of errorCbk: ${errorMsg}`);
},
);
}
if ("wechat" in kagent){
var redirect_uri=window.location.protocol+"//"+url.hostname;
var css_uri= window.location.protocol+"//"+url.hostname;
if (window.location.port==""){
redirect_uri = redirect_uri+'/api/wechat_auth';
css_uri = css_uri+"/x/wechat.css";
}else{
redirect_uri = redirect_uri+':'+window.location.port+'/api/wechat_auth';
css_uri = css_uri+':'+window.location.port+"/x/wechat.css";
}
console.info(redirect_uri);
var obj = new WxLogin({
self_redirect:false,
id:"wechat_element",
appid: kagent.wechat,
scope: "snsapi_login",
redirect_uri: encodeURIComponent(redirect_uri),
state: Agent_Kasn,
style: "white",
href: css_uri,
stylelite: 1,
onReady: function(isReady){
console.log(isReady);
}
});
}
}).catch(error => {
console.error('Error fetching data:', error);
throw error; // 重新抛出错误以便调用者可以处理
});
//登录
function login(){
// 其它类型
var newItem = {
username: document.getElementById("username").value,
kagent_sn: Agent_Kasn,
telphone: document.getElementById("telphone").value,
org: document.getElementById("org").value,
};
if (!validateFormattedPhoneNumber(newItem.telphone)){
alert("手机号码不正确!")
return;
}
// 使用 axios 发送 POST 请求
axios.post('/api/login', newItem)
.then(response =>{
if (response.data.code==200){
window.location.href="kagent.html?sn="+Agent_Kasn;
}else{
alert(response.data.msg);
}
})
.catch(error => {
console.error('Error post data:', error);
throw error; // 重新抛出错误以便调用者可以处理
});
}
function validateFormattedPhoneNumber(phone) {
// 去除非数字字符
const cleanedPhone = phone.replace(/[-\s()]/g, "");
// 验证清理后的手机号
const phoneRegex = /^1[3-9]\d{9}$/;
return phoneRegex.test(cleanedPhone);
}
</script>
</body>
</html>