- 更新页面布局,优化导航栏和面包屑导航 - 重新组织页面内容,突出公司使命和价值观 - 添加发展历程和核心团队介绍 - 更新合作伙伴展示方式 - 调整页脚内容,增加社交媒体链接
159 lines
6.2 KiB
HTML
159 lines
6.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>活牛采购系统</title>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; margin: 20px; }
|
|
.container { max-width: 800px; margin: 0 auto; }
|
|
.form-group { margin-bottom: 15px; }
|
|
label { display: block; margin-bottom: 5px; }
|
|
input, select { width: 100%; padding: 8px; box-sizing: border-box; }
|
|
button { background-color: #007bff; color: white; padding: 10px 20px; border: none; cursor: pointer; }
|
|
button:hover { background-color: #0056b3; }
|
|
.response { margin-top: 20px; padding: 10px; background-color: #f8f9fa; border: 1px solid #dee2e6; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>活牛采购系统</h1>
|
|
|
|
<h2>用户注册</h2>
|
|
<form id="registerForm">
|
|
<div class="form-group">
|
|
<label for="username">用户名:</label>
|
|
<input type="text" id="username" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">密码:</label>
|
|
<input type="password" id="password" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="phone">手机号:</label>
|
|
<input type="text" id="phone" required>
|
|
</div>
|
|
<button type="submit">注册</button>
|
|
</form>
|
|
|
|
<h2>用户登录</h2>
|
|
<form id="loginForm">
|
|
<div class="form-group">
|
|
<label for="loginUsername">用户名:</label>
|
|
<input type="text" id="loginUsername" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="loginPassword">密码:</label>
|
|
<input type="password" id="loginPassword" required>
|
|
</div>
|
|
<button type="submit">登录</button>
|
|
</form>
|
|
|
|
<h2>创建订单</h2>
|
|
<form id="orderForm">
|
|
<div class="form-group">
|
|
<label for="cattleType">牛种:</label>
|
|
<select id="cattleType" required>
|
|
<option value="黄牛">黄牛</option>
|
|
<option value="水牛">水牛</option>
|
|
<option value="牦牛">牦牛</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="quantity">数量:</label>
|
|
<input type="number" id="quantity" min="1" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="unitPrice">单价:</label>
|
|
<input type="number" id="unitPrice" step="0.01" min="0" required>
|
|
</div>
|
|
<button type="submit">创建订单</button>
|
|
</form>
|
|
|
|
<div class="response" id="response"></div>
|
|
</div>
|
|
|
|
<script>
|
|
const baseUrl = 'http://localhost:3000/api';
|
|
const responseDiv = document.getElementById('response');
|
|
|
|
// 显示响应结果
|
|
function showResponse(data) {
|
|
responseDiv.innerHTML = `<pre>${JSON.stringify(data, null, 2)}</pre>`;
|
|
}
|
|
|
|
// 注册表单提交
|
|
document.getElementById('registerForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
const username = document.getElementById('username').value;
|
|
const password = document.getElementById('password').value;
|
|
const phone = document.getElementById('phone').value;
|
|
|
|
try {
|
|
const res = await fetch(`${baseUrl}/auth/register`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ username, password, phone })
|
|
});
|
|
const data = await res.json();
|
|
showResponse(data);
|
|
} catch (error) {
|
|
showResponse({ error: error.message });
|
|
}
|
|
});
|
|
|
|
// 登录表单提交
|
|
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
const username = document.getElementById('loginUsername').value;
|
|
const password = document.getElementById('loginPassword').value;
|
|
|
|
try {
|
|
const res = await fetch(`${baseUrl}/auth/login`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ username, password })
|
|
});
|
|
const data = await res.json();
|
|
// 保存token到localStorage
|
|
if (data.token) {
|
|
localStorage.setItem('token', data.token);
|
|
}
|
|
showResponse(data);
|
|
} catch (error) {
|
|
showResponse({ error: error.message });
|
|
}
|
|
});
|
|
|
|
// 创建订单表单提交
|
|
document.getElementById('orderForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
const cattleType = document.getElementById('cattleType').value;
|
|
const quantity = parseInt(document.getElementById('quantity').value);
|
|
const unitPrice = parseFloat(document.getElementById('unitPrice').value);
|
|
|
|
// 获取token
|
|
const token = localStorage.getItem('token');
|
|
if (!token) {
|
|
showResponse({ error: '请先登录' });
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const res = await fetch(`${baseUrl}/orders`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': `Bearer ${token}`
|
|
},
|
|
body: JSON.stringify({ cattleType, quantity, unitPrice })
|
|
});
|
|
const data = await res.json();
|
|
showResponse(data);
|
|
} catch (error) {
|
|
showResponse({ error: error.message });
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |