This commit is contained in:
hailin 2024-10-25 15:31:07 +08:00
parent 35864176ed
commit b189b282d3
2 changed files with 25 additions and 10 deletions

15
app.py
View File

@ -147,3 +147,18 @@ def set_customer_data(data):
customer_data = data
else:
raise ValueError("Data must be a list of dictionaries.")
@app.route('/customer/top')
def view_top_customer():
# 跳转到数据库的第一条记录
return redirect(url_for('view_customer', index=0))
@app.route('/customer/bottom')
def view_bottom_customer():
# 跳转到数据库的最后一条记录
if not customer_data:
return "No customer data available.", 400
last_index = len(customer_data) - 1 # 计算最后一条记录的索引
return redirect(url_for('view_customer', index=last_index))

View File

@ -36,11 +36,11 @@
<!-- 新增导航按钮 -->
<div>
<!-- 跳转到顶部按钮 -->
<button onclick="scrollToTop()">Go to Top</button>
<!-- 跳转到数据库的第一条记录按钮 -->
<button onclick="goToTop()">Go to Top</button>
<!-- 跳转到底部按钮 -->
<button onclick="scrollToBottom()">Go to Bottom</button>
<!-- 跳转到数据库的最后一条记录按钮 -->
<button onclick="goToBottom()">Go to Bottom</button>
<!-- 跳转到指定页面的输入框和按钮 -->
<input type="number" id="pageIndex" placeholder="Enter page number">
@ -61,14 +61,14 @@
<!-- JavaScript 脚本 -->
<script>
// 跳转到顶部
function scrollToTop() {
window.scrollTo({ top: 0, behavior: 'smooth' });
// 跳转到数据库的第一条记录
function goToTop() {
window.location.href = "/customer/top"; // 跳转到后端“Top”路由
}
// 跳转到底部
function scrollToBottom() {
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
// 跳转到数据库的最后一条记录
function goToBottom() {
window.location.href = "/customer/bottom"; // 跳转到后端“Bottom”路由
}
// 跳转到指定页面