Add front-end login demo #4

Open
beppeb wants to merge 4 commits from dev1 into main
Showing only changes of commit 4bfb449865 - Show all commits

40
index.html Normal file
View File

@@ -0,0 +1,40 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Demo - 主页</title>
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
<main class="container">
<header>
<h1>Demo 应用</h1>
</header>
<section id="content">
<p id="greeting">正在检查登录状态……</p>
<div id="actions"></div>
</section>
</main>
<script>
// 简单客户端令牌检查
const token = localStorage.getItem('demo_auth_token');
const greeting = document.getElementById('greeting');
const actions = document.getElementById('actions');
if (token) {
greeting.textContent = '欢迎,已登录用户!';
const logoutBtn = document.createElement('button');
logoutBtn.textContent = '退出登录';
logoutBtn.onclick = () => {
localStorage.removeItem('demo_auth_token');
location.reload();
};
actions.appendChild(logoutBtn);
} else {
greeting.innerHTML = '你还未登录。前往 <a href="/login.html">登录页面</a>。';
}
</script>
</body>
</html>