完成Action导航栏的链接搭建,修复了登出的一些小bug
This commit is contained in:
244
frontend/Web/admin.html
Normal file
244
frontend/Web/admin.html
Normal file
@ -0,0 +1,244 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Admin Panel - ZYM's Book Store</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
background-color: #333;
|
||||||
|
color: #fff;
|
||||||
|
padding: 10px 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-bar {
|
||||||
|
float: right;
|
||||||
|
padding: 10px;
|
||||||
|
background-color: #007bff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-bar span {
|
||||||
|
margin-right: 20px; /* Add spacing between "Welcome, Guest" and "Actions" */
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-bar a {
|
||||||
|
color: #fff;
|
||||||
|
margin-right: 10px;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-bar a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-button-container {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-button {
|
||||||
|
padding: 10px 15px;
|
||||||
|
background-color: #007bff;
|
||||||
|
color: #fff;
|
||||||
|
border: 2px solid #0056b3; /* Dark blue border */
|
||||||
|
border-radius: 5px; /* Rounded corners */
|
||||||
|
cursor: pointer;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-button:hover,
|
||||||
|
.dropdown-content:hover {
|
||||||
|
background-color: #87CEFA; /* Light blue background on hover */
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-content {
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
background-color: #87CEFA; /* Light blue background */
|
||||||
|
box-shadow: 0 8px 16px rgba(0,0,0,0.1);
|
||||||
|
z-index: 1;
|
||||||
|
max-width: 150px;
|
||||||
|
right: 0;
|
||||||
|
top: 100%; /* Position below the action button */
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-content a {
|
||||||
|
display: block;
|
||||||
|
padding: 10px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: #333;
|
||||||
|
text-align: center; /* Horizontally center the text */
|
||||||
|
width: 100%; /* Make the width 100% */
|
||||||
|
box-sizing: border-box; /* Include padding in the width */
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-content a:hover {
|
||||||
|
background-color: #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown:hover .dropdown-content {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
height: 80vh;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav {
|
||||||
|
width: 200px;
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
padding: 20px;
|
||||||
|
height: 80vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav a {
|
||||||
|
display: block;
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: #333;
|
||||||
|
border-radius: 5px;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav a:hover {
|
||||||
|
background-color: #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
flex: 1;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
.passwd-box {
|
||||||
|
width: 300px;
|
||||||
|
padding: 20px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
background-color: #fff;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
background-color: #4caf50;
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-box {
|
||||||
|
width: 300px;
|
||||||
|
padding: 20px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
background-color: #fff;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<header>
|
||||||
|
<h1>ZYM's Book Store</h1>
|
||||||
|
<div class="user-bar">
|
||||||
|
<span>Welcome, <span id="username">[Guest]</span></span>
|
||||||
|
<div class="action-button-container" onmouseover="showDropdown()" onmouseout="hideDropdown()">
|
||||||
|
<div class="action-button">Actions</div>
|
||||||
|
<div class="dropdown">
|
||||||
|
<div class="dropdown-content">
|
||||||
|
<a href="/login">Login</a>
|
||||||
|
<a href="#" onclick="(async () => { await Request('logout'); await UpdateUserInfo(); location.reload();})(); return false;">Logout</a>
|
||||||
|
<a href="/register">Register</a>
|
||||||
|
<a href="/passwd">Change Password</a>
|
||||||
|
<a href="/admin">Admin Panel</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="main-content">
|
||||||
|
<nav>
|
||||||
|
<a href="#">Search Books</a>
|
||||||
|
<a href="#">Purchase Books</a>
|
||||||
|
</nav>
|
||||||
|
<div class="content">
|
||||||
|
This is content.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="/socket.io/socket.io.js"></script>
|
||||||
|
<script src="/communication.js"></script>
|
||||||
|
<script>
|
||||||
|
function showDropdown() {
|
||||||
|
document.querySelector('.dropdown-content').style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideDropdown() {
|
||||||
|
document.querySelector('.dropdown-content').style.display = 'none';
|
||||||
|
}
|
||||||
|
function ChangeUsername(newUsername) {
|
||||||
|
document.getElementById('username').textContent = newUsername;
|
||||||
|
}
|
||||||
|
async function UpdateUserInfo(){
|
||||||
|
let nm=await GetMyName();
|
||||||
|
let pri=await GetMyPrivilege();
|
||||||
|
if(nm=='')
|
||||||
|
{
|
||||||
|
await RefreshSession();
|
||||||
|
nm=await GetMyName();
|
||||||
|
pri=await GetMyPrivilege();
|
||||||
|
}
|
||||||
|
if(pri==0)
|
||||||
|
{
|
||||||
|
ChangeUsername("[Guest]");
|
||||||
|
}
|
||||||
|
else if(pri==1)
|
||||||
|
{
|
||||||
|
ChangeUsername(nm);
|
||||||
|
}
|
||||||
|
else if(pri==3)
|
||||||
|
{
|
||||||
|
ChangeUsername(nm+" [Worker]");
|
||||||
|
}
|
||||||
|
else if(pri==7)
|
||||||
|
{
|
||||||
|
ChangeUsername(nm+" [Admin]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.addEventListener('SessionReady', async () => {
|
||||||
|
await UpdateUserInfo();
|
||||||
|
if((await GetMyPrivilege())<3)
|
||||||
|
{
|
||||||
|
document.querySelector('.content').innerHTML = '<div class="info-box"><h2>Please log in as worker or root first.</h2><p>Redirecting to home page in 3 seconds...</p></div>';
|
||||||
|
setTimeout(function(){window.location.href="/";},3000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<script src="/sessioninit.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -132,10 +132,10 @@
|
|||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<div class="dropdown-content">
|
<div class="dropdown-content">
|
||||||
<a href="/login">Login</a>
|
<a href="/login">Login</a>
|
||||||
<a href="#" onclick="(async () => { await Request('logout'); await UpdateUserInfo(); })();">Logout</a>
|
<a href="#" onclick="(async () => { await Request('logout'); await UpdateUserInfo(); location.reload();})(); return false;">Logout</a>
|
||||||
<a href="/register">Register</a>
|
<a href="/register">Register</a>
|
||||||
<a href="/passwd">Change Password</a>
|
<a href="/passwd">Change Password</a>
|
||||||
<a href="#">Admin Panel</a>
|
<a href="/admin">Admin Panel</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -169,6 +169,10 @@ app.get('/passwd', (req, res) => {
|
|||||||
res.sendFile(join(__dirname, 'passwd.html'));
|
res.sendFile(join(__dirname, 'passwd.html'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/admin', (req, res) => {
|
||||||
|
res.sendFile(join(__dirname, 'admin.html'));
|
||||||
|
});
|
||||||
|
|
||||||
server.listen(3000, () => {
|
server.listen(3000, () => {
|
||||||
console.log('server running at http://localhost:3000');
|
console.log('server running at http://localhost:3000');
|
||||||
});
|
});
|
@ -170,10 +170,10 @@
|
|||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<div class="dropdown-content">
|
<div class="dropdown-content">
|
||||||
<a href="/login">Login</a>
|
<a href="/login">Login</a>
|
||||||
<a href="#" onclick="(async () => { await Request('logout'); await UpdateUserInfo(); })();">Logout</a>
|
<a href="#" onclick="(async () => { await Request('logout'); await UpdateUserInfo(); location.reload();})(); return false;">Logout</a>
|
||||||
<a href="/register">Register</a>
|
<a href="/register">Register</a>
|
||||||
<a href="/passwd">Change Password</a>
|
<a href="/passwd">Change Password</a>
|
||||||
<a href="#">Admin Panel</a>
|
<a href="/admin">Admin Panel</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -171,10 +171,10 @@
|
|||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<div class="dropdown-content">
|
<div class="dropdown-content">
|
||||||
<a href="/login">Login</a>
|
<a href="/login">Login</a>
|
||||||
<a href="#" onclick="(async () => { await Request('logout'); await UpdateUserInfo(); })();">Logout</a>
|
<a href="#" onclick="(async () => { await Request('logout'); await UpdateUserInfo(); location.reload();})(); return false;">Logout</a>
|
||||||
<a href="/register">Register</a>
|
<a href="/register">Register</a>
|
||||||
<a href="/passwd">Change Password</a>
|
<a href="/passwd">Change Password</a>
|
||||||
<a href="#">Admin Panel</a>
|
<a href="/admin">Admin Panel</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -171,10 +171,10 @@
|
|||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<div class="dropdown-content">
|
<div class="dropdown-content">
|
||||||
<a href="/login">Login</a>
|
<a href="/login">Login</a>
|
||||||
<a href="#" onclick="(async () => { await Request('logout'); await UpdateUserInfo(); })();">Logout</a>
|
<a href="#" onclick="(async () => { await Request('logout'); await UpdateUserInfo(); location.reload();})(); return false;">Logout</a>
|
||||||
<a href="/register">Register</a>
|
<a href="/register">Register</a>
|
||||||
<a href="/passwd">Change Password</a>
|
<a href="/passwd">Change Password</a>
|
||||||
<a href="#">Admin Panel</a>
|
<a href="/admin">Admin Panel</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user