NapCatQQ/static/QQLogin.html

294 lines
9.5 KiB
HTML
Raw Permalink Normal View History

2024-05-06 04:30:26 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2024-05-07 13:17:31 +00:00
<title>NapCat - WebUi</title>
2024-05-06 04:30:26 +00:00
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f2f5;
}
.login-container {
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
background-color: white;
max-width: 400px;
min-width: 300px;
position: relative;
}
2024-05-07 13:17:31 +00:00
.login-methods {
display: flex;
justify-content: space-between;
2024-05-06 04:30:26 +00:00
margin-bottom: 20px;
}
2024-05-07 13:17:31 +00:00
.login-method {
padding: 10px 15px;
2024-05-06 04:30:26 +00:00
font-size: 16px;
2024-05-07 13:17:31 +00:00
cursor: pointer;
transition: all 0.3s;
}
.login-method.active {
background-color: #e6f0ff;
color: #007BFF;
}
.login-form,
.qrcode {
display: flex;
flex-direction: column;
gap: 15px;
}
.qrcode {
display: flex;
justify-content: center;
align-items: center;
gap: 15px;
text-align: center;
2024-05-06 04:30:26 +00:00
}
button {
width: 100%;
padding: 10px;
background-color: #007BFF;
color: white;
border: none;
cursor: pointer;
transition: all 0.3s;
}
button:hover {
background-color: #0056b3;
}
2024-05-07 13:17:31 +00:00
.hidden {
display: none;
}
#qrcode-canvas {
width: 200px;
height: 200px;
}
#quick-login-dropdown {
width: 100%;
padding: 10px;
font-size: 16px;
background-color: transparent;
border: none;
cursor: pointer;
outline: none;
transition: all 0.3s;
}
#quick-login-dropdown:hover {
background-color: #e6f0ff;
}
#quick-login-options {
position: absolute;
top: calc(100% + 5px);
left: 0;
right: 0;
background-color: white;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
z-index: 1;
display: none;
}
#quick-login-options.show {
display: block;
}
.quick-login-option {
padding: 10px 15px;
cursor: pointer;
transition: all 0.3s;
}
.quick-login-option:hover {
background-color: #e6f0ff;
}
#quick-login-select {
width: 100%;
padding: 10px;
font-size: 16px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
cursor: pointer;
outline: none;
transition: all 0.3s;
}
#quick-login-select option {
background-color: #fff;
color: #333;
2024-05-06 04:30:26 +00:00
}
</style>
2024-05-08 13:00:53 +00:00
<script src="./assets/qrcode.min.js"></script>
2024-05-06 04:30:26 +00:00
</head>
<body>
<div class="login-container">
2024-05-07 13:17:31 +00:00
<h2>Login</h2>
<div class="login-methods">
<button id="quick-login" class="login-method active">Quick Login</button>
<button id="qrcode-login" class="login-method">QR Code</button>
</div>
<div id="quick-login-dropdown" class="login-form">
<select id="quick-login-select" onchange="selectAccount(this.value)">
2024-05-08 12:33:48 +00:00
<option value="">Select Account</option>
2024-05-07 13:17:31 +00:00
</select>
</div>
<div id="qrcode" class="qrcode" style="display: none;">
<canvas id="qrcode-canvas"></canvas>
</div>
<p id="message"></p>
2024-05-06 04:30:26 +00:00
</div>
<script>
2024-05-08 07:07:20 +00:00
async function GetQQLoginQrcode(retCredential) {
let QQLoginResponse = await fetch('../api/QQLogin/GetQQLoginQrcode', {
2024-05-08 07:07:20 +00:00
method: 'POST',
headers: {
'Authorization': "Bearer " + retCredential,
'Content-Type': 'application/json'
}
});
if (QQLoginResponse.status == 200) {
let QQLoginResponseJson = await QQLoginResponse.json();
if (QQLoginResponseJson.code == 0) {
if (QQLoginResponseJson.data.qrcode) {
return QQLoginResponseJson.data.qrcode;
} else {
return "";
}
}
}
return "";
}
2024-05-07 14:51:43 +00:00
async function CheckQQLoginStatus(retCredential) {
let QQLoginResponse = await fetch('../api/QQLogin/CheckLoginStatus', {
2024-05-07 14:51:43 +00:00
method: 'POST',
headers: {
'Authorization': "Bearer " + retCredential,
'Content-Type': 'application/json'
}
});
if (QQLoginResponse.status == 200) {
let QQLoginResponseJson = await QQLoginResponse.json();
if (QQLoginResponseJson.code == 0) {
if (QQLoginResponseJson.data.isLogin) {
return true;
} else {
return false;
}
}
}
return false;
}
async function GetQQQucickLoginList(retCredential) {
let QQLoginResponse = await fetch('../api/QQLogin/GetQuickLoginList', {
2024-05-07 14:51:43 +00:00
method: 'POST',
headers: {
'Authorization': "Bearer " + retCredential,
'Content-Type': 'application/json'
}
});
if (QQLoginResponse.status == 200) {
let QQLoginResponseJson = await QQLoginResponse.json();
if (QQLoginResponseJson.code == 0) {
return QQLoginResponseJson?.data;
}
}
return [];
}
2024-05-08 12:10:33 +00:00
async function SetQuickLogin(uin, retCredential) {
let QQLoginResponse = await fetch('../api/QQLogin/SetQuickLogin', {
2024-05-08 12:10:33 +00:00
method: 'POST',
headers: {
'Authorization': "Bearer " + retCredential,
'Content-Type': 'application/json'
},
body: JSON.stringify({
uin: uin
})
});
if (QQLoginResponse.status == 200) {
let QQLoginResponseJson = await QQLoginResponse.json();
if (QQLoginResponseJson.code == 0) {
return { result: true, errMsg: "" };
} else {
return { result: false, errMsg: QQLoginResponseJson.message };
}
}
return { result: false, errMsg: "接口异常" };;
}
2024-05-08 07:07:20 +00:00
//心跳轮询CheckQQLoginStatus 是否已经进入登录状态如果为true进入./config.html
async function HeartBeat() {
let isLogined = await CheckQQLoginStatus(localStorage.getItem('auth'));
if (isLogined) {
window.location.href = './config.html';
}
}
2024-05-08 06:29:18 +00:00
async function InitPages() {
2024-05-08 06:46:51 +00:00
let QuickLists = await GetQQQucickLoginList(localStorage.getItem('auth'));
2024-05-08 06:29:18 +00:00
let QuickListSelect = document.querySelector("#quick-login-select");
QuickLists.forEach(QuickUin => {
let optionUinEle = document.createElement('option');
optionUinEle.innerHTML = QuickUin;
optionUinEle.value = QuickUin;
2024-05-08 06:46:51 +00:00
QuickListSelect.appendChild(optionUinEle);
2024-05-07 14:51:43 +00:00
});
2024-05-08 12:54:43 +00:00
generateQrCode(await GetQQLoginQrcode(localStorage.getItem('auth')), document.querySelector('#qrcode-canvas'));
setInterval(HeartBeat, 3000);
2024-05-07 14:51:43 +00:00
}
2024-05-07 13:17:31 +00:00
document.getElementById('quick-login').addEventListener('click', function () {
let quickLoginOptions = document.querySelector('#quick-login-dropdown');
let qrcode = document.querySelector('#qrcode');
quickLoginOptions.style.display = 'flex';
qrcode.style.display = 'none';
});
2024-05-08 12:10:33 +00:00
async function selectAccount(accountName) {
//alert(`Logging in with ${accountName}...`);
const { result, errMsg } = await SetQuickLogin(accountName, localStorage.getItem('auth'));
if (result) {
alert("登录成功即将跳转");
window.location.href = './config.html';
} else {
alert("登录失败," + errMsg);
}
//await (localStorage.getItem('auth'))
2024-05-08 12:54:43 +00:00
//document.getElementById('quick-login-options').classList.remove('show');
2024-05-07 13:17:31 +00:00
}
document.getElementById('qrcode-login').addEventListener('click', function () {
let loginForm = document.querySelector('#quick-login-dropdown');
let qrcode = document.querySelector('#qrcode');
loginForm.style.display = 'none';
qrcode.style.display = 'flex';
});
function generateQrCode(data, canvas) {
QRCode.toCanvas(canvas, data, function (error) {
2024-08-11 09:53:15 +00:00
if (error) console.log(error);
2024-05-07 13:17:31 +00:00
console.log('QR Code generated!');
});
2024-05-06 04:30:26 +00:00
}
2024-05-08 06:46:51 +00:00
InitPages();
2024-05-06 04:30:26 +00:00
</script>
</body>
</html>