106 lines
3.2 KiB
HTML
106 lines
3.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: 0;
|
|
padding: 20px;
|
|
background-color: #f4f4f9;
|
|
}
|
|
h1 {
|
|
text-align: center;
|
|
color: #333;
|
|
}
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 20px;
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
}
|
|
th, td {
|
|
padding: 12px;
|
|
text-align: left;
|
|
border: 1px solid #ddd;
|
|
}
|
|
th {
|
|
background-color: #f2f2f2;
|
|
}
|
|
tr:nth-child(even) {
|
|
background-color: #f9f9f9;
|
|
}
|
|
.valid {
|
|
color: green;
|
|
font-weight: bold;
|
|
}
|
|
.invalid {
|
|
color: red;
|
|
font-weight: bold;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>订单信息</h1>
|
|
<table id="orders-table">
|
|
<thead>
|
|
<tr>
|
|
<th>订单ID</th>
|
|
<th>订单分类</th>
|
|
<th>订单名称</th>
|
|
<th>数量</th>
|
|
<th>日期</th>
|
|
<th>是否有效</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<!-- 这里将通过 JavaScript 动态填充订单数据 -->
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<script>
|
|
// 定义一个函数用于请求数据并更新表格
|
|
function fetchAndUpdateOrders() {
|
|
fetch('/readkafka') // Flask API 路径
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
const tableBody = document.querySelector('#orders-table tbody');
|
|
// 清空现有的表格内容
|
|
tableBody.innerHTML = '';
|
|
// 填充新的数据
|
|
data.forEach(order => {
|
|
const row = document.createElement('tr');
|
|
row.innerHTML = `
|
|
<td>${order.order_id}</td>
|
|
<td>${order.order_category}</td>
|
|
<td>${order.order_name}</td>
|
|
<td>${order.order_quantity}</td>
|
|
<td>${order.date}</td>
|
|
<td class="${order.is_valid === 'Y' ? 'valid' : 'invalid'}">${order.is_valid === 'Y' ? '有效' : '无效'}</td>
|
|
`;
|
|
tableBody.appendChild(row);
|
|
});
|
|
})
|
|
.catch(error => {
|
|
console.error('获取订单数据失败:', error);
|
|
});
|
|
}
|
|
|
|
// 页面加载时,立即调用一次更新数据的函数
|
|
fetchAndUpdateOrders();
|
|
|
|
// 设置轮询:每 5 秒请求一次数据并更新表格
|
|
setInterval(fetchAndUpdateOrders, 5000); // 5000 毫秒 = 5 秒
|
|
</script>
|
|
</body>
|
|
</html>
|