update all login-down

This commit is contained in:
2025-06-23 16:21:37 +08:00
parent 8204504f5a
commit 08239024ef
339 changed files with 34769 additions and 361 deletions

View File

@@ -31,23 +31,41 @@
font-size: 22px;
}
.login-form .login-type {
/* Tab 样式 */
.tab-container {
display: flex;
justify-content: center;
margin-bottom: 12px;
margin-bottom: 20px;
border-bottom: 1px solid #ddd;
}
.login-form .login-type label {
margin: 0 15px;
.tab-button {
flex: 1;
padding: 12px;
background: none;
border: none;
cursor: pointer;
font-size: 15px;
display: flex;
align-items: center;
font-size: 16px;
transition: all 0.3s ease;
border-bottom: 2px solid transparent;
}
.login-form .login-type input[type="radio"] {
margin-right: 5px;
width: auto;
.tab-button.active {
color: #3498db;
border-bottom-color: #3498db;
font-weight: bold;
}
.tab-button:hover {
color: #3498db;
background-color: #f8f9fa;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.login-form input {
@@ -106,7 +124,7 @@
cursor: not-allowed;
}
.login-form button {
.login-form button[type="submit"] {
width: 100%;
padding: 10px;
background-color: #3498db;
@@ -119,7 +137,7 @@
transition: background-color 0.3s ease;
}
.login-form button:hover {
.login-form button[type="submit"]:hover {
background-color: #2980b9;
}
@@ -260,15 +278,35 @@
<div class="login-content">
<span class="close" onclick="closeLoginModal()">&times;</span>
<h2>飞腾云登录/注册</h2>
<form id="loginForm" class="login-form">
<input type="email" id="email" placeholder="请输入邮箱" required>
<div class="code-container">
<input type="text" id="verificationCode" class="code-input" placeholder="请输入验证码" required>
<button type="button" id="sendCodeBtn" class="send-code-btn">发送验证码</button>
</div>
<div class="hint-text">(首次登录自动注册)</div>
<button type="submit">提交</button>
</form>
<!-- Tab 切换按钮 -->
<div class="tab-container">
<button class="tab-button active" onclick="switchTab('login')">登录</button>
<button class="tab-button" onclick="switchTab('register')">注册</button>
</div>
<!-- 登录表单 -->
<div id="loginTab" class="tab-content active">
<form id="loginForm" class="login-form">
<input type="email" id="loginEmail" placeholder="请输入邮箱" required>
<input type="password" id="loginPassword" placeholder="请输入密码" required>
<button type="submit">登录</button>
</form>
</div>
<!-- 注册表单 -->
<div id="registerTab" class="tab-content">
<form id="registerForm" class="login-form">
<input type="email" id="registerEmail" placeholder="请输入邮箱" required>
<div class="code-container">
<input type="text" id="verificationCode" class="code-input" placeholder="请输入验证码" required>
<button type="button" id="sendCodeBtn" class="send-code-btn">发送验证码</button>
</div>
<input type="password" id="registerPassword" placeholder="请输入密码" required>
<input type="password" id="confirmPassword" placeholder="请确认密码" required>
<button type="submit">注册</button>
</form>
</div>
</div>
</div>
@@ -279,40 +317,61 @@
// 定义API的基础URL
const baseUrl = 'https://api.phaten-audio.com/api';
//const baseUrl = 'http://localhost:8010/api';
// 获取模态框元素
const modal = document.getElementById("loginModal");
const loginForm = document.getElementById("loginForm");
const registerForm = document.getElementById("registerForm");
const sendCodeBtn = document.getElementById("sendCodeBtn");
const emailInput = document.getElementById("email");
let countdownTimer;
// 获取消息弹出框元素
const messageModal = document.getElementById("messageModal");
const messageTitle = document.getElementById("messageTitle");
const messageText = document.getElementById("messageText");
const messageBtn = document.getElementById("messageBtn");
const closeMessage = document.getElementsByClassName("close-message")[0];
// 获取消息弹出框元素
const messageModal = document.getElementById("messageModal");
const messageTitle = document.getElementById("messageTitle");
const messageText = document.getElementById("messageText");
const messageBtn = document.getElementById("messageBtn");
const closeMessage = document.getElementsByClassName("close-message")[0];
// 显示自定义消息弹出框
function showMessage(title, text, type = 'info') {
messageTitle.textContent = title;
messageText.textContent = text;
// 根据类型设置样式
messageText.className = type === 'success' ? 'success' : (type === 'error' ? 'error' : '');
messageModal.style.display = "block";
}
// Tab 切换功能
window.switchTab = function(tabName) {
// 隐藏所有tab内容
const tabContents = document.querySelectorAll('.tab-content');
tabContents.forEach(tab => tab.classList.remove('active'));
// 移除所有tab按钮的active状态
const tabButtons = document.querySelectorAll('.tab-button');
tabButtons.forEach(btn => btn.classList.remove('active'));
// 显示对应的tab内容和设置按钮active状态
if (tabName === 'login') {
document.getElementById('loginTab').classList.add('active');
document.querySelector('.tab-button').classList.add('active');
} else if (tabName === 'register') {
document.getElementById('registerTab').classList.add('active');
document.querySelectorAll('.tab-button')[1].classList.add('active');
}
}
// 关闭消息弹出框
function closeMessageModal() {
messageModal.style.display = "none";
}
// 显示自定义消息弹出框
function showMessage(title, text, type = 'info') {
messageTitle.textContent = title;
messageText.textContent = text;
// 根据类型设置样式
messageText.className = type === 'success' ? 'success' : (type === 'error' ? 'error' : '');
messageModal.style.display = "block";
}
// 绑定消息弹出框关闭事件
closeMessage.onclick = closeMessageModal;
messageBtn.onclick = closeMessageModal;
// 关闭消息弹出框
function closeMessageModal() {
messageModal.style.display = "none";
}
// 绑定消息弹出框关闭事件
closeMessage.onclick = closeMessageModal;
messageBtn.onclick = closeMessageModal;
// 添加登录框关闭按钮
function closeLoginModal() {
@@ -346,20 +405,20 @@ messageBtn.onclick = closeMessageModal;
}
});
// 检查本地存储中是否有token
function getLocalToken() {
return localStorage.getItem('ftyToken');
}
// 检查本地存储中是否有token
function getLocalToken() {
return localStorage.getItem('ftyToken');
}
// 保存token到本地存储
function saveToken(token) {
localStorage.setItem('ftyToken', token);
}
// 保存token到本地存储
function saveToken(token) {
localStorage.setItem('ftyToken', token);
}
// 清除token
function clearToken() {
localStorage.removeItem('ftyToken');
}
// 清除token
function clearToken() {
localStorage.removeItem('ftyToken');
}
// 验证token是否有效
async function validateToken() {
@@ -453,130 +512,221 @@ function clearToken() {
}
}
// 发送验证码
sendCodeBtn.onclick = function() {
const contactValue = emailInput.value;
if (!validateEmail(contactValue)) {
showMessage('输入错误', '请输入有效的邮箱地址!', 'error');
return;
}
// 禁用按钮并开始倒计时
startCountdown();
// 发送AJAX请求获取验证码
fetch(`${baseUrl}/fty/sendCode`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: "1", // 固定为邮箱类型
username: contactValue
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
showMessage('发送成功', '验证码已发送到您的邮箱!', 'success');
} else {
showMessage('发送失败', data.msg || '验证码发送失败,请稍后重试!', 'error');
resetCountdown();
// 发送验证码
sendCodeBtn.onclick = function() {
const contactValue = document.getElementById('registerEmail').value;
if (!validateEmail(contactValue)) {
showMessage('输入错误', '请输入有效的邮箱地址!', 'error');
return;
}
})
.catch(error => {
console.error('Error:', error);
showMessage('网络错误', '验证码发送请求失败,请稍后重试!', 'error');
resetCountdown();
});
}
// 禁用按钮并开始倒计时
startCountdown();
// 发送AJAX请求获取验证码
fetch(`${baseUrl}/fty/sendCode`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: "1", // 固定为邮箱类型
username: contactValue
})
})
.then(response => response.json())
.then(data => {
console.log("验证码发送返回",data);
if (data.code==2000) {
showMessage('发送成功', '验证码已发送到您的邮箱!', 'success');
} else {
showMessage('发送失败', data.msg || '验证码发送失败,请稍后重试!', 'error');
resetCountdown();
}
})
.catch(error => {
console.error('Error:', error);
showMessage('网络错误', '验证码发送请求失败,请稍后重试!', 'error');
resetCountdown();
});
}
// 验证邮箱格式
function validateEmail(email) {
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
// 验证邮箱格式
function validateEmail(email) {
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
// 开始倒计时
function startCountdown() {
let countdown = 60;
sendCodeBtn.disabled = true;
sendCodeBtn.textContent = `${countdown}秒后重试`;
countdownTimer = setInterval(() => {
countdown--;
// 开始倒计时
function startCountdown() {
let countdown = 60;
sendCodeBtn.disabled = true;
sendCodeBtn.textContent = `${countdown}秒后重试`;
if (countdown <= 0) {
resetCountdown();
countdownTimer = setInterval(() => {
countdown--;
sendCodeBtn.textContent = `${countdown}秒后重试`;
if (countdown <= 0) {
resetCountdown();
}
}, 1000);
}
// 重置倒计时
function resetCountdown() {
clearInterval(countdownTimer);
sendCodeBtn.disabled = false;
sendCodeBtn.textContent = '发送验证码';
}
// 处理登录表单提交
loginForm.onsubmit = function(e) {
console.log("Login form submitted");
e.preventDefault();
const email = document.getElementById("loginEmail").value;
const password = document.getElementById("loginPassword").value;
if (!validateEmail(email)) {
showMessage('输入错误', '请输入有效的邮箱地址!', 'error');
return;
}
}, 1000);
}
// 重置倒计时
function resetCountdown() {
clearInterval(countdownTimer);
sendCodeBtn.disabled = false;
sendCodeBtn.textContent = '发送验证码';
}
// 处理登录表单提交
loginForm.onsubmit = function(e) {
console.log("Form submitted");
e.preventDefault();
const verificationCode = document.getElementById("verificationCode").value;
const contactValue = emailInput.value;
// 发送AJAX请求
fetch(`${baseUrl}/fty/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: "1", // 固定为邮箱类型
username: contactValue,
code: verificationCode
if (!password) {
showMessage('输入错误', '请输入密码!', 'error');
return;
}
// 发送AJAX请求
fetch(`${baseUrl}/fty/userLogin`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: email,
type: 1,
password: password
})
})
})
.then(response => response.json())
.then(data => {
console.log("登录返回",data);
if (data.code==2000) {
// 保存token到本地存储
if (data.data.token) {
saveToken(data.data.token);
}
showMessage('登录成功', '登录成功!', 'success');
// 登录成功后关闭模态框
modal.style.display = "none";
resetCountdown();
// 检查是否有待下载的链接
const pendingDownloadUrl = sessionStorage.getItem('pendingDownloadUrl');
if (pendingDownloadUrl) {
sessionStorage.removeItem('pendingDownloadUrl');
.then(response => response.json())
.then(data => {
console.log("登录返回",data);
if (data.code==2000) {
// 保存token到本地存储
if (data.data.token) {
saveToken(data.data.token);
}
// 延迟一下再跳转,让用户看到成功消息
setTimeout(() => {
if (downloadBtn) {
downloadBtn.innerHTML = '下载中...';
}
window.location.href = pendingDownloadUrl;
}, 1500);
showMessage('登录成功', '登录成功!', 'success');
// 登录成功后关闭模态框
modal.style.display = "none";
// 检查是否有待下载的链接
const pendingDownloadUrl = sessionStorage.getItem('pendingDownloadUrl');
if (pendingDownloadUrl) {
sessionStorage.removeItem('pendingDownloadUrl');
// 延迟一下再跳转,让用户看到成功消息
setTimeout(() => {
const downloadBtn = document.getElementById('designDownloadBtn');
if (downloadBtn) {
downloadBtn.innerHTML = '下载中...';
}
window.location.href = pendingDownloadUrl;
}, 1500);
}
} else {
showMessage('登录失败', data.msg || '登录失败,请检查邮箱和密码!', 'error');
}
} else {
showMessage('登录失败', data.msg || '登录失败,请检查邮箱和验证码!', 'error');
})
.catch(error => {
console.error('Error:', error);
showMessage('网络错误', '登录请求失败,请稍后重试!', 'error');
});
}
// 处理注册表单提交
registerForm.onsubmit = function(e) {
console.log("Register form submitted");
e.preventDefault();
const email = document.getElementById("registerEmail").value;
const verificationCode = document.getElementById("verificationCode").value;
const password = document.getElementById("registerPassword").value;
const confirmPassword = document.getElementById("confirmPassword").value;
if (!validateEmail(email)) {
showMessage('输入错误', '请输入有效的邮箱地址!', 'error');
return;
}
})
.catch(error => {
console.error('Error:', error);
showMessage('网络错误', '登录请求失败,请稍后重试!', 'error');
});
}
if (!verificationCode) {
showMessage('输入错误', '请输入验证码!', 'error');
return;
}
if (!password) {
showMessage('输入错误', '请输入密码!', 'error');
return;
}
if (password !== confirmPassword) {
showMessage('输入错误', '两次输入的密码不一致!', 'error');
return;
}
// 发送AJAX请求
fetch(`${baseUrl}/fty/register`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: 1, // 固定为邮箱类型
username: email,
code: verificationCode,
password: password,
confirm_password:confirmPassword
})
})
.then(response => response.json())
.then(data => {
console.log("注册返回",data);
if (data.code==2000) {
// 保存token到本地存储
if (data.data.token) {
saveToken(data.data.token);
}
showMessage('注册成功', '注册成功!', 'success');
// 注册成功后关闭模态框
modal.style.display = "none";
resetCountdown();
// 检查是否有待下载的链接
const pendingDownloadUrl = sessionStorage.getItem('pendingDownloadUrl');
if (pendingDownloadUrl) {
sessionStorage.removeItem('pendingDownloadUrl');
// 延迟一下再跳转,让用户看到成功消息
setTimeout(() => {
const downloadBtn = document.getElementById('designDownloadBtn');
if (downloadBtn) {
downloadBtn.innerHTML = '下载中...';
}
window.location.href = pendingDownloadUrl;
}, 1500);
}
} else {
showMessage('注册失败', data.msg || '注册失败,请检查输入信息!', 'error');
}
})
.catch(error => {
console.error('Error:', error);
showMessage('网络错误', '注册请求失败,请稍后重试!', 'error');
});
}
// ESC键关闭登录框
document.addEventListener('keydown', function(event) {