parent
d15106024a
commit
d16eb297bc
@ -0,0 +1,29 @@
|
||||
document.getElementById('loginForm').addEventListener('submit', async (event) => {
|
||||
event.preventDefault(); // 阻止表单默认提交行为
|
||||
|
||||
const username = document.getElementById('username').value;
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
try {
|
||||
// 调用API进行登录验证
|
||||
const response = await fetch('/api/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ username, password })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
// 登录成功,跳转到功能页面
|
||||
window.location.href = '';
|
||||
} else {
|
||||
// 显示错误信息
|
||||
alert('登录失败');
|
||||
}
|
||||
} catch (error) {
|
||||
// 处理网络错误
|
||||
console.error('Error:', error);
|
||||
alert('无法连接到服务器,请检查网络');
|
||||
}
|
||||
});
|
@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>语音登录</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-container">
|
||||
<h2>Login</h2>
|
||||
<form id="loginForm">
|
||||
<label for="username">用户名:</label>
|
||||
<input type="text" id="username" required>
|
||||
<br><br>
|
||||
<label for="password">密码:</label>
|
||||
<input type="password" id="password" required>
|
||||
<br><br>
|
||||
<button type="submit">登录</button>
|
||||
</form>
|
||||
</div>
|
||||
<script src="scripts.js"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue