实现订单详情页面

This commit is contained in:
wystan_rin 2024-11-22 14:21:33 +08:00
parent fc428269ed
commit 99a544e643
1 changed files with 84 additions and 60 deletions

View File

@ -4,77 +4,97 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Order Information</title>
<!-- 引入 Google Fonts 和 Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
<style>
body {
font-family: Arial, sans-serif;
font-family: 'Inter', sans-serif;
background: linear-gradient(135deg, #e0eafc, #cfdef3);
color: #333;
margin: 0;
padding: 0;
background-color: #f9f9f9;
}
.container {
width: 80%;
margin: 20px auto;
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
margin: 40px auto;
background: #ffffff;
padding: 20px 30px;
border-radius: 12px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
max-width: 90%;
}
table {
width: 100%;
border-collapse: collapse;
}
table th, table td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
table th {
background-color: #f2f2f2;
}
.pagination {
margin: 20px 0;
h2 {
text-align: center;
font-weight: 700;
margin-bottom: 30px;
}
.pagination button {
margin: 0 5px;
padding: 10px 20px;
border: none;
background-color: #007bff;
color: white;
cursor: pointer;
border-radius: 5px;
.table {
margin-top: 20px;
}
.pagination button[disabled] {
background-color: #ccc;
cursor: not-allowed;
.table th, .table td {
vertical-align: middle;
}
.table th {
background: #f7f9fc;
font-weight: 600;
}
.pagination-container {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 20px;
}
.pagination-container span {
font-weight: 500;
color: #666;
}
.btn {
transition: background-color 0.3s ease, transform 0.2s ease;
}
.btn:hover {
background-color: #0056b3;
transform: scale(1.05);
}
.loading {
display: none;
text-align: center;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h2>Order Information</h2>
<table id="orderTable">
<thead>
<tr>
<th>Order ID</th>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
<th>Quantity</th>
<th>Payment Method</th>
<th>From Address</th>
<th>Create Timestamp</th>
<th>Update Timestamp</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<!-- Orders will be dynamically inserted here -->
</tbody>
</table>
<div class="pagination">
<button id="prevPageBtn" disabled>Previous</button>
<button id="nextPageBtn">Next</button>
<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Order ID</th>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
<th>Quantity</th>
<th>Payment Method</th>
<th>From Address</th>
<th>Create Timestamp</th>
<th>Update Timestamp</th>
<th>Status</th>
</tr>
</thead>
<tbody id="orderTableBody">
<!-- Orders will be dynamically inserted here -->
</tbody>
</table>
</div>
<div class="pagination-container">
<button class="btn btn-primary" id="prevPageBtn" disabled>Previous</button>
<span id="currentPage">Page: 1</span>
<button class="btn btn-primary" id="nextPageBtn">Next</button>
</div>
<div class="loading" id="loading">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
@ -88,9 +108,12 @@
queryParams.page = queryParams.page || 1;
queryParams.pageSize = queryParams.pageSize || 10;
// 查询接口
const apiBaseUrl = 'http://127.0.0.1:5000';
async function queryOrder() {
const loading = document.getElementById('loading');
loading.style.display = 'block'; // 显示加载动画
try {
const response = await fetch(`${apiBaseUrl}/queryOrder`, {
method: 'POST',
@ -101,16 +124,19 @@
if (!response.ok) {
throw new Error('Failed to query orders');
}
const data = await response.json();
renderTable(data.orders);
updatePaginationButtons(data.totalOrders);
} catch (error) {
console.error('Network or server error:', error);
} finally {
loading.style.display = 'none'; // 隐藏加载动画
}
}
function renderTable(orders) {
const tbody = document.querySelector('#orderTable tbody');
const tbody = document.getElementById('orderTableBody');
tbody.innerHTML = ''; // 清空表格内容
orders.forEach(order => {
const row = `
@ -131,14 +157,13 @@
});
}
// 更新分页按钮状态
function updatePaginationButtons(totalOrders) {
const totalPages = Math.ceil(totalOrders / queryParams.pageSize);
document.getElementById('prevPageBtn').disabled = queryParams.page <= 1;
document.getElementById('nextPageBtn').disabled = queryParams.page >= totalPages;
document.getElementById('currentPage').textContent = `Page: ${queryParams.page}`;
}
// 翻页操作
document.getElementById('prevPageBtn').addEventListener('click', () => {
if (queryParams.page > 1) {
queryParams.page -= 1;
@ -151,7 +176,6 @@
queryOrder();
});
// 页面加载时查询第一页
queryOrder();
</script>
</body>