Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -266,6 +266,7 @@ def clear_orders():
|
|
| 266 |
return gr.update(value="🗑️ 所有訂單已清空"), gr.update(value=get_orders_data()), gr.update(value=get_revenue())
|
| 267 |
|
| 268 |
def verify_password(pwd):
|
|
|
|
| 269 |
if pwd == ADMIN_PASSWORD:
|
| 270 |
return gr.update(visible=False), gr.update(visible=True), gr.update(value="")
|
| 271 |
return gr.update(visible=True), gr.update(visible=False), gr.update(value="❌ **密碼錯誤。**")
|
|
@@ -352,17 +353,27 @@ with gr.Blocks(theme=gr.themes.Soft(), title="簡易訂單管理系統", css=cus
|
|
| 352 |
|
| 353 |
quantity_components = []
|
| 354 |
|
|
|
|
|
|
|
|
|
|
| 355 |
# 迴圈會讀取最新的 MENU 全域變數
|
| 356 |
for item, price in MENU.items():
|
| 357 |
with gr.Row(elem_classes="menu-row"):
|
| 358 |
-
# 🖼️ 【
|
| 359 |
with gr.Column(scale=1, min_width=70):
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
else:
|
| 365 |
-
# 如果沒有找到實體檔案,直接使用 CSS 繪製質感的純文字佔位方塊
|
| 366 |
first_char = item[0] if item else "品"
|
| 367 |
placeholder_html = f"""
|
| 368 |
<div style="width: 60px; height: 60px; background-color: #e2e8f0; color: #475569; display: flex; align-items: center; justify-content: center; border-radius: 8px; font-size: 24px; font-weight: bold; margin: 0 auto;">
|
|
|
|
| 266 |
return gr.update(value="🗑️ 所有訂單已清空"), gr.update(value=get_orders_data()), gr.update(value=get_revenue())
|
| 267 |
|
| 268 |
def verify_password(pwd):
|
| 269 |
+
# 驗證全域的 ADMIN_PASSWORD
|
| 270 |
if pwd == ADMIN_PASSWORD:
|
| 271 |
return gr.update(visible=False), gr.update(visible=True), gr.update(value="")
|
| 272 |
return gr.update(visible=True), gr.update(visible=False), gr.update(value="❌ **密碼錯誤。**")
|
|
|
|
| 353 |
|
| 354 |
quantity_components = []
|
| 355 |
|
| 356 |
+
# 取得當前檔案的最頂層絕對目錄,確保路徑不跑掉
|
| 357 |
+
base_dir = os.path.dirname(os.path.abspath(__file__))
|
| 358 |
+
|
| 359 |
# 迴圈會讀取最新的 MENU 全域變數
|
| 360 |
for item, price in MENU.items():
|
| 361 |
with gr.Row(elem_classes="menu-row"):
|
| 362 |
+
# 🖼️ 【強化版:精準絕對路徑尋找圖片】
|
| 363 |
with gr.Column(scale=1, min_width=70):
|
| 364 |
+
found_img_path = None
|
| 365 |
+
# 支援多種常見副檔名與大小寫防呆
|
| 366 |
+
for ext in ['.jpg', '.jpeg', '.png', '.JPG', '.PNG']:
|
| 367 |
+
temp_path = os.path.join(base_dir, f"{item}{ext}")
|
| 368 |
+
if os.path.exists(temp_path):
|
| 369 |
+
found_img_path = temp_path
|
| 370 |
+
break
|
| 371 |
+
|
| 372 |
+
if found_img_path:
|
| 373 |
+
# 如果找到圖片檔案,傳入絕對路徑給 Gradio
|
| 374 |
+
gr.Image(value=found_img_path, interactive=False, show_label=False, show_download_button=False, container=False, elem_classes="item-pic")
|
| 375 |
else:
|
| 376 |
+
# 如果沒有找到實體檔案,直接使用 CSS 繪製質感的純文字佔位方塊
|
| 377 |
first_char = item[0] if item else "品"
|
| 378 |
placeholder_html = f"""
|
| 379 |
<div style="width: 60px; height: 60px; background-color: #e2e8f0; color: #475569; display: flex; align-items: center; justify-content: center; border-radius: 8px; font-size: 24px; font-weight: bold; margin: 0 auto;">
|