添加了购买图书的功能
This commit is contained in:
@ -70,7 +70,7 @@
|
||||
<div class="main-content">
|
||||
<nav>
|
||||
<a href="#">Search Books</a>
|
||||
<a href="#">Purchase Books</a>
|
||||
<a href="/buy">Purchase Books</a>
|
||||
</nav>
|
||||
<div class="content">
|
||||
This is content.
|
||||
|
124
frontend/Web/buy.html
Normal file
124
frontend/Web/buy.html
Normal file
@ -0,0 +1,124 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Buy - ZYM's Book Store</title>
|
||||
<link rel="stylesheet" href="basic.css">
|
||||
<style>
|
||||
.buy-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="/buy">Purchase Books</a>
|
||||
</nav>
|
||||
<div class="content">
|
||||
<div class="buy-box">
|
||||
<form onsubmit="console.log('trying passwd'); TryBuy(); return false;">
|
||||
<input id="isbn" type="text" placeholder="ISBN" required>
|
||||
<input id="quantity" type="text" placeholder="Quantity" required>
|
||||
<button type="submit">Buy</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script src="/communication.js"></script>
|
||||
<script src="/basic.js"></script>
|
||||
<script>
|
||||
document.addEventListener('SessionReady', async () => {
|
||||
await UpdateUserInfo();
|
||||
if((await GetMyPrivilege())<1)
|
||||
{
|
||||
document.querySelector('.buy-box').style.display = 'none';
|
||||
document.querySelector('.content').innerHTML = '<div class="info-box"><h2>Please log in first.</h2><p>Redirecting to home page in 3 seconds...</p></div>';
|
||||
setTimeout(function(){window.location.href="/";},3000);
|
||||
}
|
||||
});
|
||||
function isFloat(str) {
|
||||
// 使用parseFloat尝试将字符串转换为浮点数
|
||||
var floatValue = parseFloat(str);
|
||||
|
||||
// 使用isNaN检查是否成功转换,并确保不是Infinity或NaN
|
||||
return !isNaN(floatValue) && isFinite(floatValue);
|
||||
}
|
||||
async function TryBuy()
|
||||
{
|
||||
console.log("TryBuy called");
|
||||
var isbn = document.getElementById("isbn").value;
|
||||
var quantity = document.getElementById("quantity").value;
|
||||
var ret=await Request("buy "+isbn+" "+quantity);
|
||||
if(isFloat(ret))
|
||||
{
|
||||
// 删除注册框,在中间显示“注册成功”,三秒后自动跳转到首页
|
||||
document.querySelector('.buy-box').style.display = 'none';
|
||||
document.querySelector('.content').innerHTML = '<div class="info-box"><h3>Successfully bought book with ISBN='+isbn+'</h3><h3>Used '+ret+'RMB</h3><p>Auto refreshing page in 10 seconds...</p></div>';
|
||||
setTimeout(function(){location.reload();},10000);
|
||||
}
|
||||
else alert("Invalid bookname or quantity");
|
||||
}
|
||||
</script>
|
||||
<script src="/sessioninit.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -29,7 +29,7 @@
|
||||
<div class="main-content">
|
||||
<nav>
|
||||
<a href="#">Search Books</a>
|
||||
<a href="#">Purchase Books</a>
|
||||
<a href="/buy">Purchase Books</a>
|
||||
</nav>
|
||||
<div class="content">
|
||||
<!-- Your content goes here -->
|
||||
|
@ -195,6 +195,10 @@ app.get('/admin', (req, res) => {
|
||||
res.sendFile(join(__dirname, 'admin.html'));
|
||||
});
|
||||
|
||||
app.get('/buy', (req, res) => {
|
||||
res.sendFile(join(__dirname, 'buy.html'));
|
||||
});
|
||||
|
||||
server.listen(3000, () => {
|
||||
console.log('server running at http://localhost:3000');
|
||||
});
|
@ -69,7 +69,7 @@
|
||||
<div class="main-content">
|
||||
<nav>
|
||||
<a href="#">Search Books</a>
|
||||
<a href="#">Purchase Books</a>
|
||||
<a href="/buy">Purchase Books</a>
|
||||
</nav>
|
||||
<div class="content">
|
||||
<div class="login-box">
|
||||
|
@ -70,7 +70,7 @@
|
||||
<div class="main-content">
|
||||
<nav>
|
||||
<a href="#">Search Books</a>
|
||||
<a href="#">Purchase Books</a>
|
||||
<a href="/buy">Purchase Books</a>
|
||||
</nav>
|
||||
<div class="content">
|
||||
<div class="passwd-box">
|
||||
|
@ -70,7 +70,7 @@
|
||||
<div class="main-content">
|
||||
<nav>
|
||||
<a href="#">Search Books</a>
|
||||
<a href="#">Purchase Books</a>
|
||||
<a href="/buy">Purchase Books</a>
|
||||
</nav>
|
||||
<div class="content">
|
||||
<div class="register-box">
|
||||
|
Reference in New Issue
Block a user