Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,9 +57,7 @@ MENU_BACKUP_FILE = os.path.join(BASE_DIR, "menu_backup.csv")
|
|
| 57 |
MEMBERS_BACKUP_FILE = os.path.join(BASE_DIR, "members_backup.csv")
|
| 58 |
|
| 59 |
def load_orders():
|
| 60 |
-
"""從檔案讀取訂單。如果 JSON 不存在,則自動嘗試從 CSV 備份中還原資料"""
|
| 61 |
loaded_data = []
|
| 62 |
-
|
| 63 |
if os.path.exists(ORDERS_FILE):
|
| 64 |
try:
|
| 65 |
with open(ORDERS_FILE, "r", encoding="utf-8") as f:
|
|
@@ -96,20 +94,16 @@ def load_orders():
|
|
| 96 |
return loaded_data
|
| 97 |
|
| 98 |
def save_orders():
|
| 99 |
-
"""將訂單儲存到 JSON 檔案中,確保資料不遺失"""
|
| 100 |
try:
|
| 101 |
with open(ORDERS_FILE, "w", encoding="utf-8") as f:
|
| 102 |
json.dump(orders_db, f, ensure_ascii=False, indent=4)
|
| 103 |
except Exception as e:
|
| 104 |
print(f"儲存訂單失敗: {e}")
|
| 105 |
|
| 106 |
-
# 初始化全域訂單資料庫
|
| 107 |
orders_db = load_orders()
|
| 108 |
|
| 109 |
def load_menu():
|
| 110 |
-
"""從檔案讀取菜單,支援 json 讀取與 csv 自動還原,包含分類、規格與備註"""
|
| 111 |
loaded_menu = {}
|
| 112 |
-
|
| 113 |
if os.path.exists(MENU_FILE):
|
| 114 |
try:
|
| 115 |
with open(MENU_FILE, "r", encoding="utf-8") as f:
|
|
@@ -168,7 +162,6 @@ def load_menu():
|
|
| 168 |
return loaded_menu
|
| 169 |
|
| 170 |
def load_pwd():
|
| 171 |
-
"""從檔案讀取密碼,預設為 0000"""
|
| 172 |
if os.path.exists(PWD_FILE):
|
| 173 |
try:
|
| 174 |
with open(PWD_FILE, "r", encoding="utf-8") as f:
|
|
@@ -178,9 +171,7 @@ def load_pwd():
|
|
| 178 |
return "0000"
|
| 179 |
|
| 180 |
def load_members():
|
| 181 |
-
"""從檔案讀取會員資料,支援 json 讀取與 csv 自動還原"""
|
| 182 |
loaded_members = {}
|
| 183 |
-
|
| 184 |
if os.path.exists(MEMBERS_FILE):
|
| 185 |
try:
|
| 186 |
with open(MEMBERS_FILE, "r", encoding="utf-8") as f:
|
|
@@ -207,12 +198,10 @@ def load_members():
|
|
| 207 |
|
| 208 |
return loaded_members
|
| 209 |
|
| 210 |
-
# 初始化全域變數
|
| 211 |
MENU = load_menu()
|
| 212 |
ADMIN_PASSWORD = load_pwd()
|
| 213 |
MEMBERS = load_members()
|
| 214 |
|
| 215 |
-
# 【新增前端分類輔助函數】:確保前後台排序與對應絕對精準
|
| 216 |
def get_frontend_menu_items():
|
| 217 |
enabled_items = sorted([(k, v) for k, v in MENU.items() if v.get("enable", True)], key=lambda x: x[1].get("seq", 999))
|
| 218 |
category_order = []
|
|
@@ -232,9 +221,7 @@ def get_frontend_menu_items():
|
|
| 232 |
return category_order, items_by_cat, flat_list
|
| 233 |
|
| 234 |
def get_menu_df():
|
| 235 |
-
"""產生包含流水號、啟用、分類等 8 個欄位的 DataFrame"""
|
| 236 |
sorted_menu = sorted(MENU.items(), key=lambda x: x[1].get("seq", 999))
|
| 237 |
-
|
| 238 |
data = []
|
| 239 |
for k, v in sorted_menu:
|
| 240 |
data.append([
|
|
@@ -249,19 +236,16 @@ def get_menu_df():
|
|
| 249 |
])
|
| 250 |
|
| 251 |
max_seq = max([v.get("seq", 0) for v in MENU.values()]) if MENU else 0
|
| 252 |
-
|
| 253 |
for i in range(5):
|
| 254 |
data.append([max_seq + i + 1, False, "未分類", "", "", 0, 0, ""])
|
| 255 |
|
| 256 |
return pd.DataFrame(data, columns=["流水號", "啟用", "分類", "品項", "規格", "價格", "成本", "備註"])
|
| 257 |
|
| 258 |
def get_members_df():
|
| 259 |
-
"""產生會員資料的 DataFrame"""
|
| 260 |
data = []
|
| 261 |
for acc, info in MEMBERS.items():
|
| 262 |
data.append([acc, info.get("password", ""), info.get("name", ""), info.get("location", "")])
|
| 263 |
|
| 264 |
-
# 預留空行方便新增
|
| 265 |
for _ in range(5):
|
| 266 |
data.append(["", "", "", ""])
|
| 267 |
|
|
@@ -319,14 +303,14 @@ def update_menu(df):
|
|
| 319 |
new_menu[item] = {"price": price, "cost": cost, "enable": enable, "seq": seq, "category": cat, "spec": spec, "note": note}
|
| 320 |
|
| 321 |
if not new_menu:
|
| 322 |
-
return gr.update(value="❌ 錯誤:菜單不能為空!"),
|
| 323 |
|
| 324 |
MENU.clear()
|
| 325 |
MENU.update(new_menu)
|
| 326 |
save_menu_to_file()
|
| 327 |
|
| 328 |
new_trigger = datetime.now(TAIPEI_TZ).timestamp()
|
| 329 |
-
return gr.update(value=f"✅ 菜單已成功更新!({datetime.now(TAIPEI_TZ).strftime('%H:%M:%S')})"),
|
| 330 |
|
| 331 |
def update_members_list(df):
|
| 332 |
global MEMBERS
|
|
@@ -338,7 +322,7 @@ def update_members_list(df):
|
|
| 338 |
name = str(row[2]).strip() if pd.notna(row[2]) else ""
|
| 339 |
loc = str(row[3]).strip() if pd.notna(row[3]) else ""
|
| 340 |
|
| 341 |
-
if acc:
|
| 342 |
new_members[acc] = {"password": pwd, "name": name, "location": loc}
|
| 343 |
|
| 344 |
MEMBERS.clear()
|
|
@@ -430,7 +414,6 @@ def handle_message(event):
|
|
| 430 |
# ----------------------------
|
| 431 |
# 💻 網頁後台邏輯
|
| 432 |
# ----------------------------
|
| 433 |
-
|
| 434 |
def get_customer_choices():
|
| 435 |
customers = []
|
| 436 |
for o in orders_db:
|
|
@@ -540,14 +523,13 @@ def refresh_data(current_filter, current_time_filter, current_item_filter, curre
|
|
| 540 |
gr.update(choices=d_choices, value=current_delivery_filter)
|
| 541 |
)
|
| 542 |
|
| 543 |
-
def restore_from_backup(
|
| 544 |
global orders_db, MENU, MEMBERS
|
| 545 |
msg = ""
|
| 546 |
|
| 547 |
-
# 1. 還原訂單
|
| 548 |
if os.path.exists(BACKUP_FILE):
|
| 549 |
if os.path.getsize(BACKUP_FILE) == 0:
|
| 550 |
-
msg = "⚠️ 警告:雲端上的 orders_backup.csv 是一個空白檔案
|
| 551 |
else:
|
| 552 |
try:
|
| 553 |
df = pd.read_csv(BACKUP_FILE)
|
|
@@ -566,14 +548,11 @@ def restore_from_backup(current_filter, current_time_filter, current_item_filter
|
|
| 566 |
orders_db = loaded_data
|
| 567 |
save_orders()
|
| 568 |
msg = f"✅ 成功從備份檔強制還原了 {len(orders_db)} 筆訂單!"
|
| 569 |
-
except pd.errors.EmptyDataError:
|
| 570 |
-
msg = "⚠️ 警告:雲端上的 orders_backup.csv 內容為空,無法解析資料!"
|
| 571 |
except Exception as e:
|
| 572 |
msg = f"❌ 還原訂單失敗,發生錯誤:{e}"
|
| 573 |
else:
|
| 574 |
-
msg = "⚠️ 找不到 orders_backup.csv 備份檔!
|
| 575 |
|
| 576 |
-
# 2. 還原菜單
|
| 577 |
new_trigger = datetime.now(TAIPEI_TZ).timestamp()
|
| 578 |
if os.path.exists(MENU_BACKUP_FILE) and os.path.getsize(MENU_BACKUP_FILE) > 0:
|
| 579 |
try:
|
|
@@ -601,7 +580,6 @@ def restore_from_backup(current_filter, current_time_filter, current_item_filter
|
|
| 601 |
except Exception as e:
|
| 602 |
msg += f"\n❌ 菜單還原失敗:{e}"
|
| 603 |
|
| 604 |
-
# 3. 還原會員
|
| 605 |
if os.path.exists(MEMBERS_BACKUP_FILE) and os.path.getsize(MEMBERS_BACKUP_FILE) > 0:
|
| 606 |
try:
|
| 607 |
mem_df = pd.read_csv(MEMBERS_BACKUP_FILE)
|
|
@@ -621,47 +599,21 @@ def restore_from_backup(current_filter, current_time_filter, current_item_filter
|
|
| 621 |
msg += "\n✅ 會員資料已成功從備份同步還原!"
|
| 622 |
except Exception as e:
|
| 623 |
msg += f"\n❌ 會員資料還原失敗:{e}"
|
| 624 |
-
|
| 625 |
-
c_choices = get_customer_choices()
|
| 626 |
-
t_choices = get_time_choices()
|
| 627 |
-
i_choices = get_item_choices()
|
| 628 |
-
d_choices = get_delivery_choices()
|
| 629 |
-
|
| 630 |
-
if current_filter not in c_choices: current_filter = "所有顧客"
|
| 631 |
-
if current_time_filter not in t_choices: current_time_filter = "所有時間"
|
| 632 |
-
if current_item_filter not in i_choices: current_item_filter = "所有商品"
|
| 633 |
-
if current_delivery_filter not in d_choices: current_delivery_filter = "所有交期"
|
| 634 |
|
| 635 |
-
return (
|
| 636 |
-
gr.update(value=msg),
|
| 637 |
-
gr.update(value=get_orders_data(current_filter, current_time_filter, current_item_filter, current_delivery_filter)),
|
| 638 |
-
gr.update(value=get_revenue(current_filter, current_time_filter, current_item_filter, current_delivery_filter)),
|
| 639 |
-
gr.update(choices=c_choices, value=current_filter),
|
| 640 |
-
gr.update(choices=t_choices, value=current_time_filter),
|
| 641 |
-
gr.update(choices=i_choices, value=current_item_filter),
|
| 642 |
-
gr.update(choices=d_choices, value=current_delivery_filter),
|
| 643 |
-
get_menu_df(),
|
| 644 |
-
get_members_df(),
|
| 645 |
-
new_trigger
|
| 646 |
-
)
|
| 647 |
|
| 648 |
def add_order(c_name, p_method, d_location, d_month, d_day, d_time, nts, *qty_args):
|
| 649 |
try:
|
| 650 |
c_name = str(c_name).strip() if c_name else ""
|
| 651 |
nts = str(nts).strip() if nts else ""
|
| 652 |
-
|
| 653 |
delivery_date = f"{d_month}{d_day} {d_time}" if d_time != "盡快" else "盡快"
|
| 654 |
|
| 655 |
quantities = []
|
| 656 |
for q in qty_args:
|
| 657 |
-
try:
|
| 658 |
-
|
| 659 |
-
except:
|
| 660 |
-
quantities.append(0)
|
| 661 |
|
| 662 |
-
# 取得與前台絕對一致的平面化選單順序
|
| 663 |
_, _, flat_list = get_frontend_menu_items()
|
| 664 |
-
|
| 665 |
reset_qtys = [gr.update(value="0") for _ in range(len(flat_list))]
|
| 666 |
|
| 667 |
if not c_name:
|
|
@@ -681,16 +633,12 @@ def add_order(c_name, p_method, d_location, d_month, d_day, d_time, nts, *qty_ar
|
|
| 681 |
spec = details.get("spec", "")
|
| 682 |
|
| 683 |
item_note = f"({spec})" if spec else ""
|
| 684 |
-
|
| 685 |
total_price = price * qty
|
| 686 |
total_cost = cost * qty
|
| 687 |
total_order_price += total_price
|
| 688 |
|
| 689 |
order_id = str(uuid.uuid4())[:6].upper()
|
| 690 |
-
|
| 691 |
-
final_note = nts
|
| 692 |
-
if item_note:
|
| 693 |
-
final_note = f"{item_note} {nts}".strip()
|
| 694 |
|
| 695 |
orders_db.append({
|
| 696 |
"訂單編號": order_id,
|
|
@@ -715,7 +663,6 @@ def add_order(c_name, p_method, d_location, d_month, d_day, d_time, nts, *qty_ar
|
|
| 715 |
return [gr.update(value="❌ 錯誤:請至少選擇一項商品的數量")] + reset_qtys
|
| 716 |
|
| 717 |
save_orders()
|
| 718 |
-
|
| 719 |
msg = f"✅ 成功新增訂單:{c_name} 訂購了 {', '.join(items_desc)},總計 {total_order_price} 元。取貨方式:{p_method}"
|
| 720 |
|
| 721 |
return [gr.update(value=msg)] + reset_qtys
|
|
@@ -773,63 +720,54 @@ def do_login(acc, pwd):
|
|
| 773 |
if not acc:
|
| 774 |
return (
|
| 775 |
gr.update(visible=True), gr.update(visible=False),
|
| 776 |
-
gr.update(
|
| 777 |
-
gr.update(
|
| 778 |
-
gr.update(value="❌ 請輸入帳號!"), "", gr.update(value="")
|
| 779 |
)
|
| 780 |
|
| 781 |
if acc == "admin":
|
| 782 |
if pwd == ADMIN_PASSWORD:
|
| 783 |
return (
|
| 784 |
-
gr.update(visible=False),
|
| 785 |
-
gr.update(visible=True),
|
| 786 |
-
gr.update(
|
| 787 |
-
|
| 788 |
-
gr.update(
|
| 789 |
-
gr.update(
|
| 790 |
-
gr.update(value=""), # login_msg
|
| 791 |
-
"admin", # current_user_state
|
| 792 |
-
gr.update(value="👋 **管理員 您好!**")
|
| 793 |
)
|
| 794 |
else:
|
| 795 |
return (
|
| 796 |
gr.update(visible=True), gr.update(visible=False),
|
| 797 |
-
gr.update(
|
| 798 |
-
gr.update(
|
| 799 |
-
gr.update(value="❌ 管理員密碼錯誤!"), "", gr.update(value="")
|
| 800 |
)
|
| 801 |
|
| 802 |
else:
|
| 803 |
-
# Check against normal members
|
| 804 |
if acc in MEMBERS and MEMBERS[acc].get("password") == pwd:
|
| 805 |
user_name = MEMBERS[acc].get("name", acc)
|
| 806 |
return (
|
| 807 |
-
gr.update(visible=False),
|
| 808 |
-
gr.update(visible=True),
|
| 809 |
-
gr.update(
|
| 810 |
-
|
| 811 |
-
gr.update(
|
| 812 |
-
gr.update(
|
| 813 |
-
gr.update(value=""), # login_msg
|
| 814 |
-
acc, # current_user_state
|
| 815 |
-
gr.update(value=f"👋 **會員 {user_name} 您好!**")
|
| 816 |
)
|
| 817 |
else:
|
| 818 |
return (
|
| 819 |
gr.update(visible=True), gr.update(visible=False),
|
| 820 |
-
gr.update(
|
| 821 |
-
gr.update(
|
| 822 |
-
gr.update(value="❌ 帳號或密碼錯誤!"), "", gr.update(value="")
|
| 823 |
)
|
| 824 |
|
| 825 |
def logout():
|
| 826 |
return (
|
| 827 |
-
gr.update(visible=True),
|
| 828 |
-
gr.update(visible=False),
|
| 829 |
-
gr.update(value=""),
|
| 830 |
-
gr.update(value=""),
|
| 831 |
-
gr.update(value=""),
|
| 832 |
-
""
|
|
|
|
| 833 |
)
|
| 834 |
|
| 835 |
def run_git_cmd(command):
|
|
@@ -841,7 +779,6 @@ def run_git_cmd(command):
|
|
| 841 |
def backup_and_push_to_github():
|
| 842 |
log_messages = ["🚀 開始備份...\n" + "-"*40]
|
| 843 |
|
| 844 |
-
# Backup Orders
|
| 845 |
if not orders_db:
|
| 846 |
df = pd.DataFrame(columns=["訂單編號", "訂單時間", "預定交期", "取貨方式", "送貨地點", "顧客姓名", "商品", "單價", "成本", "數量", "總價", "總成本", "備註"])
|
| 847 |
else:
|
|
@@ -868,12 +805,10 @@ def backup_and_push_to_github():
|
|
| 868 |
df.to_csv(backup_filename, index=False, encoding="utf-8-sig")
|
| 869 |
log_messages.append(f"💾 已儲存訂單至: {backup_filename}")
|
| 870 |
|
| 871 |
-
# Backup Menu
|
| 872 |
menu_df = get_menu_df()
|
| 873 |
menu_df.to_csv(MENU_BACKUP_FILE, index=False, encoding="utf-8-sig")
|
| 874 |
log_messages.append(f"💾 已儲存菜單備份至: {MENU_BACKUP_FILE}")
|
| 875 |
|
| 876 |
-
# Backup Members
|
| 877 |
members_df = get_members_df()
|
| 878 |
members_df.to_csv(MEMBERS_BACKUP_FILE, index=False, encoding="utf-8-sig")
|
| 879 |
log_messages.append(f"💾 已儲存會員備份至: {MEMBERS_BACKUP_FILE}")
|
|
@@ -989,100 +924,110 @@ with gr.Blocks(theme=gr.themes.Soft(), title="簡易訂單管理系統", css=cus
|
|
| 989 |
login_msg = gr.Markdown(value="")
|
| 990 |
|
| 991 |
# ==========================
|
| 992 |
-
# 主系統介面 (Main View)
|
| 993 |
# ==========================
|
| 994 |
with gr.Column(visible=False) as main_container:
|
| 995 |
with gr.Row(elem_classes="menu-row"):
|
| 996 |
-
user_greeting = gr.Markdown(value="")
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
default_name =
|
| 1010 |
-
default_loc =
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
with gr.Row():
|
| 1015 |
-
with gr.Column():
|
| 1016 |
-
customer_name = gr.Textbox(label="顧客姓名", placeholder="請輸入姓名", value=default_name)
|
| 1017 |
-
|
| 1018 |
-
gr.Markdown("#### 📦 取貨方式與地點")
|
| 1019 |
-
with gr.Row():
|
| 1020 |
-
pickup_method = gr.Radio(choices=["自取", "送貨"], value=default_method, label="取貨方式", interactive=True)
|
| 1021 |
-
delivery_location = gr.Textbox(
|
| 1022 |
-
label="送貨地點",
|
| 1023 |
-
placeholder="請輸入送貨地點",
|
| 1024 |
-
value=default_loc,
|
| 1025 |
-
visible=(default_method == "送貨"),
|
| 1026 |
-
interactive=True
|
| 1027 |
-
)
|
| 1028 |
-
|
| 1029 |
-
def update_loc_vis(method):
|
| 1030 |
-
return gr.update(visible=(method == "送貨"))
|
| 1031 |
-
pickup_method.change(fn=update_loc_vis, inputs=[pickup_method], outputs=[delivery_location])
|
| 1032 |
|
| 1033 |
-
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
-
|
|
|
|
| 1037 |
|
| 1038 |
-
|
| 1039 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1040 |
|
| 1041 |
-
|
| 1042 |
-
|
|
|
|
| 1043 |
|
| 1044 |
-
|
| 1045 |
-
|
| 1046 |
-
|
| 1047 |
-
|
| 1048 |
-
|
| 1049 |
-
|
| 1050 |
-
|
| 1051 |
-
|
| 1052 |
-
|
| 1053 |
-
|
| 1054 |
-
|
| 1055 |
-
gr.Markdown("
|
| 1056 |
|
| 1057 |
-
|
| 1058 |
-
|
| 1059 |
-
|
| 1060 |
-
|
| 1061 |
-
|
| 1062 |
-
|
| 1063 |
-
|
| 1064 |
-
|
| 1065 |
-
|
| 1066 |
-
|
| 1067 |
-
|
| 1068 |
-
|
| 1069 |
-
|
| 1070 |
-
|
| 1071 |
-
|
| 1072 |
-
|
| 1073 |
-
|
| 1074 |
-
|
| 1075 |
-
|
| 1076 |
-
|
| 1077 |
-
|
| 1078 |
-
|
| 1079 |
-
|
| 1080 |
-
|
| 1081 |
-
|
| 1082 |
-
|
| 1083 |
-
|
| 1084 |
-
|
| 1085 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1086 |
first_char = item[0] if item else "品"
|
| 1087 |
placeholder_html = f"""
|
| 1088 |
<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; pointer-events: none;">
|
|
@@ -1090,221 +1035,185 @@ with gr.Blocks(theme=gr.themes.Soft(), title="簡易訂單管理系統", css=cus
|
|
| 1090 |
</div>
|
| 1091 |
"""
|
| 1092 |
gr.HTML(value=placeholder_html)
|
| 1093 |
-
|
| 1094 |
-
|
| 1095 |
-
|
| 1096 |
-
<div style=
|
| 1097 |
-
{first_char}
|
| 1098 |
-
</div>
|
| 1099 |
-
"""
|
| 1100 |
-
gr.HTML(value=placeholder_html)
|
| 1101 |
-
|
| 1102 |
-
with gr.Column(scale=1, min_width=60):
|
| 1103 |
-
spec_html = f"<span style='font-size: 0.85em; color: #ef4444; margin-left: 6px; padding: 2px 6px; background: #fee2e2; border-radius: 4px;'>{spec}</span>" if spec else ""
|
| 1104 |
-
gr.Markdown(f"<div style='line-height: 1.2;'><strong>{item}</strong>{spec_html}<br><span style='color: gray; font-size: 0.9em;'>NT$ {price}</span></div>")
|
| 1105 |
-
|
| 1106 |
-
with gr.Column(scale=0, min_width=36):
|
| 1107 |
-
minus_btn = gr.Button("➖", elem_classes="action-btn", variant="secondary")
|
| 1108 |
-
with gr.Column(scale=0, min_width=45):
|
| 1109 |
-
qty_box = gr.Textbox(value="0", show_label=False, interactive=True, elem_classes="qty-input", container=False)
|
| 1110 |
-
with gr.Column(scale=0, min_width=36):
|
| 1111 |
-
plus_btn = gr.Button("➕", elem_classes="action-btn", variant="secondary")
|
| 1112 |
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
|
| 1116 |
-
|
| 1117 |
-
|
| 1118 |
-
|
| 1119 |
-
|
| 1120 |
-
|
| 1121 |
-
|
| 1122 |
-
|
| 1123 |
-
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
-
|
| 1127 |
-
|
| 1128 |
-
|
| 1129 |
-
|
| 1130 |
-
|
| 1131 |
-
submit_btn.click(fn=add_order, inputs=inputs_list, outputs=outputs_list)
|
| 1132 |
-
|
| 1133 |
-
# --- 📊 系統管理與總覽 (僅管理員可見) ---
|
| 1134 |
-
with gr.Column(visible=False) as admin_view:
|
| 1135 |
-
with gr.Accordion("☁️ 雲端備份與還原 (點擊展開/收合)", open=True):
|
| 1136 |
-
with gr.Row():
|
| 1137 |
-
github_btn = gr.Button("🔄 備份至 GitHub", variant="primary")
|
| 1138 |
-
restore_btn = gr.Button("📥 從備份還原", variant="secondary")
|
| 1139 |
-
github_log_output = gr.Textbox(label="執行日誌", interactive=False, lines=2, elem_classes="github-log")
|
| 1140 |
-
|
| 1141 |
-
with gr.Tabs():
|
| 1142 |
-
|
| 1143 |
-
with gr.TabItem("📊 訂單詳細數據"):
|
| 1144 |
-
revenue_display = gr.Markdown(value=get_revenue())
|
| 1145 |
-
with gr.Row():
|
| 1146 |
-
customer_filter = gr.Dropdown(choices=["所有顧客"], value="所有顧客", label="🔍 篩選顧客", interactive=True)
|
| 1147 |
-
time_filter = gr.Dropdown(choices=["所有時間"], value="所有時間", label="📅 篩選訂單時間", interactive=True)
|
| 1148 |
-
item_filter = gr.Dropdown(choices=["所有商品"], value="所有商品", label="🍔 篩選商品", interactive=True)
|
| 1149 |
-
delivery_filter = gr.Dropdown(choices=["所有交期"], value="所有交期", label="🕒 篩選預定交期", interactive=True)
|
| 1150 |
-
refresh_btn = gr.Button("🔄 抓取最新訂單", variant="secondary")
|
| 1151 |
-
|
| 1152 |
-
orders_table = gr.Dataframe(value=get_orders_data(), headers=["訂單編號", "訂單時間", "預定交期", "取貨方式", "送貨地點", "顧客姓名", "商品", "單價", "成本", "數量", "總價", "總成本", "備註"], interactive=False)
|
| 1153 |
-
|
| 1154 |
-
gr.Markdown("---")
|
| 1155 |
-
gr.Markdown("### 🗑️ 刪除訂單管理")
|
| 1156 |
-
with gr.Row(elem_classes="menu-row"):
|
| 1157 |
-
with gr.Column(scale=2):
|
| 1158 |
-
delete_target = gr.Textbox(label="刪除單筆", placeholder="👉 點擊上方表格中的訂單,編號會自動帶入此處")
|
| 1159 |
-
with gr.Column(scale=1):
|
| 1160 |
-
delete_single_btn = gr.Button("🗑️ 刪除單筆", variant="stop")
|
| 1161 |
-
with gr.Column(scale=1):
|
| 1162 |
-
clear_btn = gr.Button("🚨 清空所有", variant="stop")
|
| 1163 |
|
| 1164 |
-
|
| 1165 |
-
|
| 1166 |
-
|
| 1167 |
-
|
| 1168 |
-
|
| 1169 |
-
|
| 1170 |
-
value=get_menu_df(),
|
| 1171 |
-
headers=["流水號", "啟用", "分類", "品項", "規格", "價格", "成本", "備註"],
|
| 1172 |
-
datatype=["number", "bool", "str", "str", "str", "number", "number", "str"],
|
| 1173 |
-
interactive=True,
|
| 1174 |
-
column_widths=["6%", "6%", "12%", "20%", "15%", "8%", "8%", "25%"]
|
| 1175 |
-
)
|
| 1176 |
-
save_menu_btn = gr.Button("💾 儲存菜單並更新", variant="primary")
|
| 1177 |
-
menu_status = gr.Markdown()
|
| 1178 |
-
|
| 1179 |
-
with gr.TabItem("👥 會員資料管理"):
|
| 1180 |
-
gr.Markdown("✅ **新增或修改會員**:直接在表格內輸入會員的帳號、密碼等資訊。若要刪除會員,請將該列清空即可。<br>⚠️ 修改完成後請務必點擊 **「💾 儲存會員資料並更新」**。")
|
| 1181 |
|
| 1182 |
-
|
| 1183 |
-
|
| 1184 |
-
|
| 1185 |
-
|
| 1186 |
-
|
| 1187 |
-
|
| 1188 |
-
|
| 1189 |
-
|
| 1190 |
-
|
| 1191 |
-
|
| 1192 |
-
|
| 1193 |
-
|
| 1194 |
-
|
| 1195 |
-
|
| 1196 |
-
|
| 1197 |
-
|
| 1198 |
-
|
| 1199 |
-
|
| 1200 |
-
|
| 1201 |
-
|
| 1202 |
-
|
| 1203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1204 |
|
| 1205 |
-
# 登入動作
|
| 1206 |
login_btn.click(
|
| 1207 |
fn=do_login,
|
| 1208 |
inputs=[login_acc, login_pwd],
|
| 1209 |
-
outputs=[login_container, main_container,
|
| 1210 |
)
|
| 1211 |
login_pwd.submit(
|
| 1212 |
fn=do_login,
|
| 1213 |
inputs=[login_acc, login_pwd],
|
| 1214 |
-
outputs=[login_container, main_container,
|
| 1215 |
)
|
| 1216 |
|
| 1217 |
-
# 頂部導航切換 (僅管理員可見與使用)
|
| 1218 |
-
nav_order_btn.click(
|
| 1219 |
-
fn=lambda: (gr.update(variant="primary"), gr.update(variant="secondary"), gr.update(visible=True), gr.update(visible=False)),
|
| 1220 |
-
outputs=[nav_order_btn, nav_admin_btn, order_view, admin_view]
|
| 1221 |
-
)
|
| 1222 |
-
nav_admin_btn.click(
|
| 1223 |
-
fn=lambda: (gr.update(variant="secondary"), gr.update(variant="primary"), gr.update(visible=False), gr.update(visible=True)),
|
| 1224 |
-
outputs=[nav_order_btn, nav_admin_btn, order_view, admin_view]
|
| 1225 |
-
)
|
| 1226 |
-
|
| 1227 |
-
# 登出動作
|
| 1228 |
logout_btn.click(
|
| 1229 |
fn=logout,
|
| 1230 |
inputs=[],
|
| 1231 |
-
outputs=[login_container, main_container, login_acc, login_pwd, login_msg, current_user_state]
|
| 1232 |
-
)
|
| 1233 |
-
|
| 1234 |
-
customer_filter.change(
|
| 1235 |
-
fn=lambda c, t, i, d: (gr.update(value=get_orders_data(c, t, i, d)), gr.update(value=get_revenue(c, t, i, d))),
|
| 1236 |
-
inputs=[customer_filter, time_filter, item_filter, delivery_filter],
|
| 1237 |
-
outputs=[orders_table, revenue_display]
|
| 1238 |
-
)
|
| 1239 |
-
|
| 1240 |
-
time_filter.change(
|
| 1241 |
-
fn=lambda c, t, i, d: (gr.update(value=get_orders_data(c, t, i, d)), gr.update(value=get_revenue(c, t, i, d))),
|
| 1242 |
-
inputs=[customer_filter, time_filter, item_filter, delivery_filter],
|
| 1243 |
-
outputs=[orders_table, revenue_display]
|
| 1244 |
-
)
|
| 1245 |
-
|
| 1246 |
-
item_filter.change(
|
| 1247 |
-
fn=lambda c, t, i, d: (gr.update(value=get_orders_data(c, t, i, d)), gr.update(value=get_revenue(c, t, i, d))),
|
| 1248 |
-
inputs=[customer_filter, time_filter, item_filter, delivery_filter],
|
| 1249 |
-
outputs=[orders_table, revenue_display]
|
| 1250 |
-
)
|
| 1251 |
-
|
| 1252 |
-
delivery_filter.change(
|
| 1253 |
-
fn=lambda c, t, i, d: (gr.update(value=get_orders_data(c, t, i, d)), gr.update(value=get_revenue(c, t, i, d))),
|
| 1254 |
-
inputs=[customer_filter, time_filter, item_filter, delivery_filter],
|
| 1255 |
-
outputs=[orders_table, revenue_display]
|
| 1256 |
-
)
|
| 1257 |
-
|
| 1258 |
-
refresh_btn.click(
|
| 1259 |
-
fn=refresh_data,
|
| 1260 |
-
inputs=[customer_filter, time_filter, item_filter, delivery_filter],
|
| 1261 |
-
outputs=[orders_table, revenue_display, customer_filter, time_filter, item_filter, delivery_filter]
|
| 1262 |
-
)
|
| 1263 |
-
|
| 1264 |
-
restore_btn.click(
|
| 1265 |
-
fn=restore_from_backup,
|
| 1266 |
-
inputs=[customer_filter, time_filter, item_filter, delivery_filter],
|
| 1267 |
-
outputs=[admin_status_msg, orders_table, revenue_display, customer_filter, time_filter, item_filter, delivery_filter, menu_table, members_table, menu_trigger]
|
| 1268 |
-
)
|
| 1269 |
-
|
| 1270 |
-
orders_table.select(
|
| 1271 |
-
fn=autofill_delete_target,
|
| 1272 |
-
inputs=[orders_table],
|
| 1273 |
-
outputs=[delete_target]
|
| 1274 |
-
)
|
| 1275 |
-
|
| 1276 |
-
delete_single_btn.click(
|
| 1277 |
-
fn=delete_single_order,
|
| 1278 |
-
inputs=[delete_target, customer_filter, time_filter, item_filter, delivery_filter],
|
| 1279 |
-
outputs=[admin_status_msg, orders_table, revenue_display, delete_target],
|
| 1280 |
-
js="(target, c_filter, t_filter, i_filter, d_filter) => { if (!target) { return [target, c_filter, t_filter, i_filter, d_filter]; } return confirm('⚠️ 確認要刪除訂單編號 [' + target + '] 嗎?此動作無法復原!') ? [target, c_filter, t_filter, i_filter, d_filter] : ['__CANCEL__', c_filter, t_filter, i_filter, d_filter]; }"
|
| 1281 |
-
)
|
| 1282 |
-
|
| 1283 |
-
clear_btn.click(
|
| 1284 |
-
fn=clear_orders,
|
| 1285 |
-
inputs=[customer_filter],
|
| 1286 |
-
outputs=[admin_status_msg, orders_table, revenue_display, customer_filter, time_filter, item_filter, delivery_filter],
|
| 1287 |
-
js="(filter) => { return confirm('🚨 極度危險:確定要清空【所有】訂單資料嗎?此動作無法復原!') ? [filter] : ['__CANCEL__']; }"
|
| 1288 |
-
)
|
| 1289 |
-
|
| 1290 |
-
github_btn.click(fn=backup_and_push_to_github, inputs=[], outputs=[github_log_output])
|
| 1291 |
-
|
| 1292 |
-
save_menu_btn.click(
|
| 1293 |
-
fn=update_menu,
|
| 1294 |
-
inputs=[menu_table],
|
| 1295 |
-
outputs=[menu_status, menu_table, menu_trigger]
|
| 1296 |
-
)
|
| 1297 |
-
|
| 1298 |
-
save_members_btn.click(
|
| 1299 |
-
fn=update_members_list,
|
| 1300 |
-
inputs=[members_table],
|
| 1301 |
-
outputs=[members_status, members_table]
|
| 1302 |
-
)
|
| 1303 |
-
|
| 1304 |
-
update_pwd_btn.click(
|
| 1305 |
-
fn=change_password,
|
| 1306 |
-
inputs=[old_pwd_input, new_pwd_input],
|
| 1307 |
-
outputs=[pwd_update_status]
|
| 1308 |
)
|
| 1309 |
|
| 1310 |
# ----------------------------
|
|
|
|
| 57 |
MEMBERS_BACKUP_FILE = os.path.join(BASE_DIR, "members_backup.csv")
|
| 58 |
|
| 59 |
def load_orders():
|
|
|
|
| 60 |
loaded_data = []
|
|
|
|
| 61 |
if os.path.exists(ORDERS_FILE):
|
| 62 |
try:
|
| 63 |
with open(ORDERS_FILE, "r", encoding="utf-8") as f:
|
|
|
|
| 94 |
return loaded_data
|
| 95 |
|
| 96 |
def save_orders():
|
|
|
|
| 97 |
try:
|
| 98 |
with open(ORDERS_FILE, "w", encoding="utf-8") as f:
|
| 99 |
json.dump(orders_db, f, ensure_ascii=False, indent=4)
|
| 100 |
except Exception as e:
|
| 101 |
print(f"儲存訂單失敗: {e}")
|
| 102 |
|
|
|
|
| 103 |
orders_db = load_orders()
|
| 104 |
|
| 105 |
def load_menu():
|
|
|
|
| 106 |
loaded_menu = {}
|
|
|
|
| 107 |
if os.path.exists(MENU_FILE):
|
| 108 |
try:
|
| 109 |
with open(MENU_FILE, "r", encoding="utf-8") as f:
|
|
|
|
| 162 |
return loaded_menu
|
| 163 |
|
| 164 |
def load_pwd():
|
|
|
|
| 165 |
if os.path.exists(PWD_FILE):
|
| 166 |
try:
|
| 167 |
with open(PWD_FILE, "r", encoding="utf-8") as f:
|
|
|
|
| 171 |
return "0000"
|
| 172 |
|
| 173 |
def load_members():
|
|
|
|
| 174 |
loaded_members = {}
|
|
|
|
| 175 |
if os.path.exists(MEMBERS_FILE):
|
| 176 |
try:
|
| 177 |
with open(MEMBERS_FILE, "r", encoding="utf-8") as f:
|
|
|
|
| 198 |
|
| 199 |
return loaded_members
|
| 200 |
|
|
|
|
| 201 |
MENU = load_menu()
|
| 202 |
ADMIN_PASSWORD = load_pwd()
|
| 203 |
MEMBERS = load_members()
|
| 204 |
|
|
|
|
| 205 |
def get_frontend_menu_items():
|
| 206 |
enabled_items = sorted([(k, v) for k, v in MENU.items() if v.get("enable", True)], key=lambda x: x[1].get("seq", 999))
|
| 207 |
category_order = []
|
|
|
|
| 221 |
return category_order, items_by_cat, flat_list
|
| 222 |
|
| 223 |
def get_menu_df():
|
|
|
|
| 224 |
sorted_menu = sorted(MENU.items(), key=lambda x: x[1].get("seq", 999))
|
|
|
|
| 225 |
data = []
|
| 226 |
for k, v in sorted_menu:
|
| 227 |
data.append([
|
|
|
|
| 236 |
])
|
| 237 |
|
| 238 |
max_seq = max([v.get("seq", 0) for v in MENU.values()]) if MENU else 0
|
|
|
|
| 239 |
for i in range(5):
|
| 240 |
data.append([max_seq + i + 1, False, "未分類", "", "", 0, 0, ""])
|
| 241 |
|
| 242 |
return pd.DataFrame(data, columns=["流水號", "啟用", "分類", "品項", "規格", "價格", "成本", "備註"])
|
| 243 |
|
| 244 |
def get_members_df():
|
|
|
|
| 245 |
data = []
|
| 246 |
for acc, info in MEMBERS.items():
|
| 247 |
data.append([acc, info.get("password", ""), info.get("name", ""), info.get("location", "")])
|
| 248 |
|
|
|
|
| 249 |
for _ in range(5):
|
| 250 |
data.append(["", "", "", ""])
|
| 251 |
|
|
|
|
| 303 |
new_menu[item] = {"price": price, "cost": cost, "enable": enable, "seq": seq, "category": cat, "spec": spec, "note": note}
|
| 304 |
|
| 305 |
if not new_menu:
|
| 306 |
+
return gr.update(value="❌ 錯誤:菜單不能為空!"), gr.skip()
|
| 307 |
|
| 308 |
MENU.clear()
|
| 309 |
MENU.update(new_menu)
|
| 310 |
save_menu_to_file()
|
| 311 |
|
| 312 |
new_trigger = datetime.now(TAIPEI_TZ).timestamp()
|
| 313 |
+
return gr.update(value=f"✅ 菜單已成功更新!({datetime.now(TAIPEI_TZ).strftime('%H:%M:%S')})"), new_trigger
|
| 314 |
|
| 315 |
def update_members_list(df):
|
| 316 |
global MEMBERS
|
|
|
|
| 322 |
name = str(row[2]).strip() if pd.notna(row[2]) else ""
|
| 323 |
loc = str(row[3]).strip() if pd.notna(row[3]) else ""
|
| 324 |
|
| 325 |
+
if acc:
|
| 326 |
new_members[acc] = {"password": pwd, "name": name, "location": loc}
|
| 327 |
|
| 328 |
MEMBERS.clear()
|
|
|
|
| 414 |
# ----------------------------
|
| 415 |
# 💻 網頁後台邏輯
|
| 416 |
# ----------------------------
|
|
|
|
| 417 |
def get_customer_choices():
|
| 418 |
customers = []
|
| 419 |
for o in orders_db:
|
|
|
|
| 523 |
gr.update(choices=d_choices, value=current_delivery_filter)
|
| 524 |
)
|
| 525 |
|
| 526 |
+
def restore_from_backup():
|
| 527 |
global orders_db, MENU, MEMBERS
|
| 528 |
msg = ""
|
| 529 |
|
|
|
|
| 530 |
if os.path.exists(BACKUP_FILE):
|
| 531 |
if os.path.getsize(BACKUP_FILE) == 0:
|
| 532 |
+
msg = "⚠️ 警告:雲端上的 orders_backup.csv 是一個空白檔案,沒有歷史資料可以還原!"
|
| 533 |
else:
|
| 534 |
try:
|
| 535 |
df = pd.read_csv(BACKUP_FILE)
|
|
|
|
| 548 |
orders_db = loaded_data
|
| 549 |
save_orders()
|
| 550 |
msg = f"✅ 成功從備份檔強制還原了 {len(orders_db)} 筆訂單!"
|
|
|
|
|
|
|
| 551 |
except Exception as e:
|
| 552 |
msg = f"❌ 還原訂單失敗,發生錯誤:{e}"
|
| 553 |
else:
|
| 554 |
+
msg = "⚠️ 找不到 orders_backup.csv 備份檔!"
|
| 555 |
|
|
|
|
| 556 |
new_trigger = datetime.now(TAIPEI_TZ).timestamp()
|
| 557 |
if os.path.exists(MENU_BACKUP_FILE) and os.path.getsize(MENU_BACKUP_FILE) > 0:
|
| 558 |
try:
|
|
|
|
| 580 |
except Exception as e:
|
| 581 |
msg += f"\n❌ 菜單還原失敗:{e}"
|
| 582 |
|
|
|
|
| 583 |
if os.path.exists(MEMBERS_BACKUP_FILE) and os.path.getsize(MEMBERS_BACKUP_FILE) > 0:
|
| 584 |
try:
|
| 585 |
mem_df = pd.read_csv(MEMBERS_BACKUP_FILE)
|
|
|
|
| 599 |
msg += "\n✅ 會員資料已成功從備份同步還原!"
|
| 600 |
except Exception as e:
|
| 601 |
msg += f"\n❌ 會員資料還原失敗:{e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 602 |
|
| 603 |
+
return gr.update(value=msg), new_trigger
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 604 |
|
| 605 |
def add_order(c_name, p_method, d_location, d_month, d_day, d_time, nts, *qty_args):
|
| 606 |
try:
|
| 607 |
c_name = str(c_name).strip() if c_name else ""
|
| 608 |
nts = str(nts).strip() if nts else ""
|
|
|
|
| 609 |
delivery_date = f"{d_month}{d_day} {d_time}" if d_time != "盡快" else "盡快"
|
| 610 |
|
| 611 |
quantities = []
|
| 612 |
for q in qty_args:
|
| 613 |
+
try: quantities.append(int(q))
|
| 614 |
+
except: quantities.append(0)
|
|
|
|
|
|
|
| 615 |
|
|
|
|
| 616 |
_, _, flat_list = get_frontend_menu_items()
|
|
|
|
| 617 |
reset_qtys = [gr.update(value="0") for _ in range(len(flat_list))]
|
| 618 |
|
| 619 |
if not c_name:
|
|
|
|
| 633 |
spec = details.get("spec", "")
|
| 634 |
|
| 635 |
item_note = f"({spec})" if spec else ""
|
|
|
|
| 636 |
total_price = price * qty
|
| 637 |
total_cost = cost * qty
|
| 638 |
total_order_price += total_price
|
| 639 |
|
| 640 |
order_id = str(uuid.uuid4())[:6].upper()
|
| 641 |
+
final_note = f"{item_note} {nts}".strip() if item_note else nts
|
|
|
|
|
|
|
|
|
|
| 642 |
|
| 643 |
orders_db.append({
|
| 644 |
"訂單編號": order_id,
|
|
|
|
| 663 |
return [gr.update(value="❌ 錯誤:請至少選擇一項商品的數量")] + reset_qtys
|
| 664 |
|
| 665 |
save_orders()
|
|
|
|
| 666 |
msg = f"✅ 成功新增訂單:{c_name} 訂購了 {', '.join(items_desc)},總計 {total_order_price} 元。取貨方式:{p_method}"
|
| 667 |
|
| 668 |
return [gr.update(value=msg)] + reset_qtys
|
|
|
|
| 720 |
if not acc:
|
| 721 |
return (
|
| 722 |
gr.update(visible=True), gr.update(visible=False),
|
| 723 |
+
gr.update(value="❌ 請輸入帳號!"), "",
|
| 724 |
+
gr.update(value=""), gr.update(value="")
|
|
|
|
| 725 |
)
|
| 726 |
|
| 727 |
if acc == "admin":
|
| 728 |
if pwd == ADMIN_PASSWORD:
|
| 729 |
return (
|
| 730 |
+
gr.update(visible=False),
|
| 731 |
+
gr.update(visible=True),
|
| 732 |
+
gr.update(value=""),
|
| 733 |
+
"admin",
|
| 734 |
+
gr.update(value="👋 **管理員 您好!**"),
|
| 735 |
+
gr.update(value="")
|
|
|
|
|
|
|
|
|
|
| 736 |
)
|
| 737 |
else:
|
| 738 |
return (
|
| 739 |
gr.update(visible=True), gr.update(visible=False),
|
| 740 |
+
gr.update(value="❌ 管理員密碼錯誤!"), "",
|
| 741 |
+
gr.update(value=""), gr.update(value="")
|
|
|
|
| 742 |
)
|
| 743 |
|
| 744 |
else:
|
|
|
|
| 745 |
if acc in MEMBERS and MEMBERS[acc].get("password") == pwd:
|
| 746 |
user_name = MEMBERS[acc].get("name", acc)
|
| 747 |
return (
|
| 748 |
+
gr.update(visible=False),
|
| 749 |
+
gr.update(visible=True),
|
| 750 |
+
gr.update(value=""),
|
| 751 |
+
acc,
|
| 752 |
+
gr.update(value=f"👋 **會員 {user_name} 您好!**"),
|
| 753 |
+
gr.update(value="")
|
|
|
|
|
|
|
|
|
|
| 754 |
)
|
| 755 |
else:
|
| 756 |
return (
|
| 757 |
gr.update(visible=True), gr.update(visible=False),
|
| 758 |
+
gr.update(value="❌ 帳號或密碼錯誤!"), "",
|
| 759 |
+
gr.update(value=""), gr.update(value="")
|
|
|
|
| 760 |
)
|
| 761 |
|
| 762 |
def logout():
|
| 763 |
return (
|
| 764 |
+
gr.update(visible=True),
|
| 765 |
+
gr.update(visible=False),
|
| 766 |
+
gr.update(value=""),
|
| 767 |
+
gr.update(value=""),
|
| 768 |
+
gr.update(value=""),
|
| 769 |
+
"",
|
| 770 |
+
gr.update(value="")
|
| 771 |
)
|
| 772 |
|
| 773 |
def run_git_cmd(command):
|
|
|
|
| 779 |
def backup_and_push_to_github():
|
| 780 |
log_messages = ["🚀 開始備份...\n" + "-"*40]
|
| 781 |
|
|
|
|
| 782 |
if not orders_db:
|
| 783 |
df = pd.DataFrame(columns=["訂單編號", "訂單時間", "預定交期", "取貨方式", "送貨地點", "顧客姓名", "商品", "單價", "成本", "數量", "總價", "總成本", "備註"])
|
| 784 |
else:
|
|
|
|
| 805 |
df.to_csv(backup_filename, index=False, encoding="utf-8-sig")
|
| 806 |
log_messages.append(f"💾 已儲存訂單至: {backup_filename}")
|
| 807 |
|
|
|
|
| 808 |
menu_df = get_menu_df()
|
| 809 |
menu_df.to_csv(MENU_BACKUP_FILE, index=False, encoding="utf-8-sig")
|
| 810 |
log_messages.append(f"💾 已儲存菜單備份至: {MENU_BACKUP_FILE}")
|
| 811 |
|
|
|
|
| 812 |
members_df = get_members_df()
|
| 813 |
members_df.to_csv(MEMBERS_BACKUP_FILE, index=False, encoding="utf-8-sig")
|
| 814 |
log_messages.append(f"💾 已儲存會員備份至: {MEMBERS_BACKUP_FILE}")
|
|
|
|
| 924 |
login_msg = gr.Markdown(value="")
|
| 925 |
|
| 926 |
# ==========================
|
| 927 |
+
# 主系統介面 (Main View) - 透過 Render 動態渲染隔離權限
|
| 928 |
# ==========================
|
| 929 |
with gr.Column(visible=False) as main_container:
|
| 930 |
with gr.Row(elem_classes="menu-row"):
|
| 931 |
+
user_greeting = gr.Markdown(value="", scale=1)
|
| 932 |
+
global_sys_msg = gr.Markdown(value="", scale=2) # 顯示系統更新成功訊息
|
| 933 |
+
logout_btn = gr.Button("🚪 登出系統", size="sm", min_width=100, scale=0)
|
| 934 |
+
|
| 935 |
+
# 動態渲染區:只有這裡面的元件會根據權限「物理性」的產生或消失
|
| 936 |
+
@gr.render(inputs=[current_user_state, menu_trigger])
|
| 937 |
+
def render_app(current_user, m_trigger):
|
| 938 |
+
if not current_user:
|
| 939 |
+
return gr.Markdown("")
|
| 940 |
+
|
| 941 |
+
with gr.Tabs() as main_tabs:
|
| 942 |
+
# ====== 任何登入者都會產生的「訂單分頁」 ======
|
| 943 |
+
with gr.TabItem("📝 現場/網頁新增訂單"):
|
| 944 |
+
default_name = ""
|
| 945 |
+
default_loc = ""
|
| 946 |
+
if current_user != "admin" and current_user in MEMBERS:
|
| 947 |
+
default_name = MEMBERS[current_user].get("name", "")
|
| 948 |
+
default_loc = MEMBERS[current_user].get("location", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 949 |
|
| 950 |
+
default_method = "送貨" if default_loc else "自取"
|
| 951 |
+
|
| 952 |
+
with gr.Row():
|
| 953 |
+
with gr.Column():
|
| 954 |
+
customer_name = gr.Textbox(label="顧客姓名", placeholder="請輸入姓名", value=default_name)
|
| 955 |
|
| 956 |
+
gr.Markdown("#### 📦 取貨方式與地點")
|
| 957 |
+
with gr.Row():
|
| 958 |
+
pickup_method = gr.Radio(choices=["自取", "送貨"], value=default_method, label="取貨方式", interactive=True)
|
| 959 |
+
delivery_location = gr.Textbox(
|
| 960 |
+
label="送貨��點",
|
| 961 |
+
placeholder="請輸入送貨地點",
|
| 962 |
+
value=default_loc,
|
| 963 |
+
visible=(default_method == "送貨"),
|
| 964 |
+
interactive=True
|
| 965 |
+
)
|
| 966 |
|
| 967 |
+
def update_loc_vis(method):
|
| 968 |
+
return gr.update(visible=(method == "送貨"))
|
| 969 |
+
pickup_method.change(fn=update_loc_vis, inputs=[pickup_method], outputs=[delivery_location])
|
| 970 |
|
| 971 |
+
gr.Markdown("#### 🕒 預定交期")
|
| 972 |
+
with gr.Row():
|
| 973 |
+
current_month = datetime.now(TAIPEI_TZ).strftime("%m月")
|
| 974 |
+
current_day = datetime.now(TAIPEI_TZ).strftime("%d日")
|
| 975 |
+
|
| 976 |
+
delivery_month = gr.Dropdown(choices=[f"{i:02d}月" for i in range(1, 13)], label="月", value=current_month, interactive=True)
|
| 977 |
+
delivery_day = gr.Dropdown(choices=[f"{i:02d}日" for i in range(1, 32)], label="日", value=current_day, interactive=True)
|
| 978 |
+
|
| 979 |
+
time_choices = ["盡快"] + [f"{h:02d}:{m:02d}" for h in range(0, 24) for m in (0, 15, 30, 45)]
|
| 980 |
+
delivery_time = gr.Dropdown(choices=time_choices, label="時間", value="盡快", interactive=True)
|
| 981 |
+
|
| 982 |
+
gr.Markdown("#### 🛍️ 選擇商品與數量")
|
| 983 |
|
| 984 |
+
quantity_components = []
|
| 985 |
+
pic_dir = os.path.join(BASE_DIR, "pic")
|
| 986 |
+
if not os.path.exists(pic_dir):
|
| 987 |
+
os.makedirs(pic_dir, exist_ok=True)
|
| 988 |
+
|
| 989 |
+
category_order, items_by_cat, flat_list = get_frontend_menu_items()
|
| 990 |
+
|
| 991 |
+
if not category_order:
|
| 992 |
+
gr.Markdown("目前尚無提供商品,請至後台設定菜單。")
|
| 993 |
+
|
| 994 |
+
with gr.Tabs():
|
| 995 |
+
for cat in category_order:
|
| 996 |
+
with gr.TabItem(cat):
|
| 997 |
+
for item, details in items_by_cat[cat]:
|
| 998 |
+
price = details["price"]
|
| 999 |
+
spec = details.get("spec", "")
|
| 1000 |
+
|
| 1001 |
+
with gr.Row(elem_classes="menu-row"):
|
| 1002 |
+
with gr.Column(scale=0, min_width=60):
|
| 1003 |
+
found_img_path = None
|
| 1004 |
+
for ext in ['.jpg', '.jpeg', '.png', '.JPG', '.PNG']:
|
| 1005 |
+
temp_path = os.path.join(pic_dir, f"{item}{ext}")
|
| 1006 |
+
if os.path.exists(temp_path):
|
| 1007 |
+
found_img_path = temp_path
|
| 1008 |
+
break
|
| 1009 |
+
|
| 1010 |
+
if found_img_path:
|
| 1011 |
+
try:
|
| 1012 |
+
with open(found_img_path, "rb") as img_file:
|
| 1013 |
+
encoded_string = base64.b64encode(img_file.read()).decode('utf-8')
|
| 1014 |
+
mime_type = "image/png" if found_img_path.lower().endswith(".png") else "image/jpeg"
|
| 1015 |
+
|
| 1016 |
+
img_html = f"""
|
| 1017 |
+
<div style="width: 60px; height: 60px; border-radius: 8px; overflow: margin: 0 auto; pointer-events: none; background: white;">
|
| 1018 |
+
<img src="data:{mime_type};base64,{encoded_string}" style="width: 100%; height: 100%; object-fit: cover; pointer-events: none;">
|
| 1019 |
+
</div>
|
| 1020 |
+
"""
|
| 1021 |
+
gr.HTML(value=img_html)
|
| 1022 |
+
except Exception:
|
| 1023 |
+
first_char = item[0] if item else "品"
|
| 1024 |
+
placeholder_html = f"""
|
| 1025 |
+
<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; pointer-events: none;">
|
| 1026 |
+
{first_char}
|
| 1027 |
+
</div>
|
| 1028 |
+
"""
|
| 1029 |
+
gr.HTML(value=placeholder_html)
|
| 1030 |
+
else:
|
| 1031 |
first_char = item[0] if item else "品"
|
| 1032 |
placeholder_html = f"""
|
| 1033 |
<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; pointer-events: none;">
|
|
|
|
| 1035 |
</div>
|
| 1036 |
"""
|
| 1037 |
gr.HTML(value=placeholder_html)
|
| 1038 |
+
|
| 1039 |
+
with gr.Column(scale=1, min_width=60):
|
| 1040 |
+
spec_html = f"<span style='font-size: 0.85em; color: #ef4444; margin-left: 6px; padding: 2px 6px; background: #fee2e2; border-radius: 4px;'>{spec}</span>" if spec else ""
|
| 1041 |
+
gr.Markdown(f"<div style='line-height: 1.2;'><strong>{item}</strong>{spec_html}<br><span style='color: gray; font-size: 0.9em;'>NT$ {price}</span></div>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1042 |
|
| 1043 |
+
with gr.Column(scale=0, min_width=36):
|
| 1044 |
+
minus_btn = gr.Button("➖", elem_classes="action-btn", variant="secondary")
|
| 1045 |
+
with gr.Column(scale=0, min_width=45):
|
| 1046 |
+
qty_box = gr.Textbox(value="0", show_label=False, interactive=True, elem_classes="qty-input", container=False)
|
| 1047 |
+
with gr.Column(scale=0, min_width=36):
|
| 1048 |
+
plus_btn = gr.Button("➕", elem_classes="action-btn", variant="secondary")
|
| 1049 |
+
|
| 1050 |
+
minus_btn.click(
|
| 1051 |
+
fn=None, inputs=[qty_box], outputs=[qty_box],
|
| 1052 |
+
js="(v) => { let n = parseInt(v || 0); return Math.max(0, n - 1).toString(); }"
|
| 1053 |
+
)
|
| 1054 |
+
plus_btn.click(
|
| 1055 |
+
fn=None, inputs=[qty_box], outputs=[qty_box],
|
| 1056 |
+
js="(v) => { let n = parseInt(v || 0); return (n + 1).toString(); }"
|
| 1057 |
+
)
|
| 1058 |
+
|
| 1059 |
+
quantity_components.append(qty_box)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1060 |
|
| 1061 |
+
notes = gr.Textbox(label="備註", placeholder="例如:少冰微糖...")
|
| 1062 |
+
submit_btn = gr.Button("🚀 送出訂單", variant="primary", size="lg")
|
| 1063 |
+
status_msg = gr.Textbox(label="系統狀態", interactive=False)
|
| 1064 |
+
|
| 1065 |
+
inputs_list = [customer_name, pickup_method, delivery_location, delivery_month, delivery_day, delivery_time, notes] + quantity_components
|
| 1066 |
+
outputs_list = [status_msg] + quantity_components
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1067 |
|
| 1068 |
+
submit_btn.click(fn=add_order, inputs=inputs_list, outputs=outputs_list)
|
| 1069 |
+
|
| 1070 |
+
# ====== 只有 admin 登入時才會實體產生的「管理分頁」 ======
|
| 1071 |
+
if current_user == "admin":
|
| 1072 |
+
with gr.TabItem("📊 系統管理與總覽"):
|
| 1073 |
+
with gr.Accordion("☁️ 雲端備份與還原 (點擊展開/收合)", open=True):
|
| 1074 |
+
with gr.Row():
|
| 1075 |
+
github_btn = gr.Button("🔄 備份至 GitHub", variant="primary")
|
| 1076 |
+
restore_btn = gr.Button("📥 從備份還原", variant="secondary")
|
| 1077 |
+
github_log_output = gr.Textbox(label="執行日誌", interactive=False, lines=2, elem_classes="github-log")
|
| 1078 |
+
|
| 1079 |
+
with gr.Tabs():
|
| 1080 |
+
|
| 1081 |
+
with gr.TabItem("📊 訂單詳細數據"):
|
| 1082 |
+
revenue_display = gr.Markdown(value=get_revenue())
|
| 1083 |
+
with gr.Row():
|
| 1084 |
+
customer_filter = gr.Dropdown(choices=["所有顧客"], value="所有顧客", label="🔍 篩選顧客", interactive=True)
|
| 1085 |
+
time_filter = gr.Dropdown(choices=["所有時間"], value="所有時間", label="📅 篩選訂單時間", interactive=True)
|
| 1086 |
+
item_filter = gr.Dropdown(choices=["所有商品"], value="所有商品", label="🍔 篩選商品", interactive=True)
|
| 1087 |
+
delivery_filter = gr.Dropdown(choices=["所有交期"], value="所有交期", label="🕒 篩選預定交期", interactive=True)
|
| 1088 |
+
refresh_btn = gr.Button("🔄 抓取最新訂單", variant="secondary")
|
| 1089 |
+
|
| 1090 |
+
orders_table = gr.Dataframe(value=get_orders_data(), headers=["訂單編號", "訂單時間", "預定交期", "取貨方式", "送貨地點", "顧客姓名", "商品", "單價", "成本", "數量", "總價", "總成本", "備註"], interactive=False)
|
| 1091 |
+
|
| 1092 |
+
gr.Markdown("---")
|
| 1093 |
+
gr.Markdown("### 🗑️ 刪除訂單管理")
|
| 1094 |
+
with gr.Row(elem_classes="menu-row"):
|
| 1095 |
+
with gr.Column(scale=2):
|
| 1096 |
+
delete_target = gr.Textbox(label="刪除單筆", placeholder="👉 點擊上方表格中的訂單,編號會自動帶入此處")
|
| 1097 |
+
with gr.Column(scale=1):
|
| 1098 |
+
delete_single_btn = gr.Button("🗑️ 刪除單筆", variant="stop")
|
| 1099 |
+
with gr.Column(scale=1):
|
| 1100 |
+
clear_btn = gr.Button("🚨 清空所有", variant="stop")
|
| 1101 |
+
|
| 1102 |
+
admin_status_msg = gr.Textbox(label="管理員狀態提示", interactive=False)
|
| 1103 |
+
|
| 1104 |
+
with gr.TabItem("📝 菜單管理"):
|
| 1105 |
+
gr.Markdown("✅ **設定流水號**:數字越小排越前面。<br>✅ **設定啟用**:打勾代表商品在點餐區可見,不打勾則隱藏但保留紀錄。<br>✅ **規格與備註**:可以標示商品尺寸,並在最後一欄留下內部備註。<br>⚠️ 修改完成後請務必點擊 **「💾 儲存菜單並更新」**。")
|
| 1106 |
+
|
| 1107 |
+
menu_table = gr.Dataframe(
|
| 1108 |
+
value=get_menu_df(),
|
| 1109 |
+
headers=["流水號", "啟用", "分類", "品項", "規格", "價格", "成本", "備註"],
|
| 1110 |
+
datatype=["number", "bool", "str", "str", "str", "number", "number", "str"],
|
| 1111 |
+
interactive=True,
|
| 1112 |
+
column_widths=["6%", "6%", "12%", "20%", "15%", "8%", "8%", "25%"]
|
| 1113 |
+
)
|
| 1114 |
+
save_menu_btn = gr.Button("💾 儲存菜單並更新", variant="primary")
|
| 1115 |
+
|
| 1116 |
+
with gr.TabItem("👥 會員資料管理"):
|
| 1117 |
+
gr.Markdown("✅ **新增或修改會員**:直接在表格內輸入會員的帳號、密碼等資訊。若要刪除會員,請將該列清空即可。<br>⚠️ 修改完成後請務必點擊 **「💾 儲存會員資料並更新」**。")
|
| 1118 |
+
|
| 1119 |
+
members_table = gr.Dataframe(
|
| 1120 |
+
value=get_members_df(),
|
| 1121 |
+
headers=["會員登入帳號", "密碼", "顧客姓名", "送貨地點"],
|
| 1122 |
+
datatype=["str", "str", "str", "str"],
|
| 1123 |
+
interactive=True,
|
| 1124 |
+
column_widths=["20%", "20%", "25%", "35%"]
|
| 1125 |
+
)
|
| 1126 |
+
save_members_btn = gr.Button("💾 儲存會員資料並更新", variant="primary")
|
| 1127 |
+
members_status = gr.Markdown()
|
| 1128 |
+
|
| 1129 |
+
with gr.TabItem("🔑 安全性設定"):
|
| 1130 |
+
gr.Markdown("### 🔑 修改管理員密碼")
|
| 1131 |
+
with gr.Row():
|
| 1132 |
+
with gr.Column(scale=1):
|
| 1133 |
+
old_pwd_input = gr.Textbox(label="目前密碼", type="password", placeholder="請輸入舊密碼")
|
| 1134 |
+
with gr.Column(scale=1):
|
| 1135 |
+
new_pwd_input = gr.Textbox(label="新密碼", type="password", placeholder="請輸入新密碼")
|
| 1136 |
+
with gr.Column(scale=1, min_width=150):
|
| 1137 |
+
update_pwd_btn = gr.Button("💾 確認更新密碼", variant="primary")
|
| 1138 |
+
pwd_update_status = gr.Markdown()
|
| 1139 |
+
|
| 1140 |
+
# --- Admin 專屬的事件綁定必須放在這 ---
|
| 1141 |
+
customer_filter.change(
|
| 1142 |
+
fn=lambda c, t, i, d: (gr.update(value=get_orders_data(c, t, i, d)), gr.update(value=get_revenue(c, t, i, d))),
|
| 1143 |
+
inputs=[customer_filter, time_filter, item_filter, delivery_filter], outputs=[orders_table, revenue_display]
|
| 1144 |
+
)
|
| 1145 |
+
time_filter.change(
|
| 1146 |
+
fn=lambda c, t, i, d: (gr.update(value=get_orders_data(c, t, i, d)), gr.update(value=get_revenue(c, t, i, d))),
|
| 1147 |
+
inputs=[customer_filter, time_filter, item_filter, delivery_filter], outputs=[orders_table, revenue_display]
|
| 1148 |
+
)
|
| 1149 |
+
item_filter.change(
|
| 1150 |
+
fn=lambda c, t, i, d: (gr.update(value=get_orders_data(c, t, i, d)), gr.update(value=get_revenue(c, t, i, d))),
|
| 1151 |
+
inputs=[customer_filter, time_filter, item_filter, delivery_filter], outputs=[orders_table, revenue_display]
|
| 1152 |
+
)
|
| 1153 |
+
delivery_filter.change(
|
| 1154 |
+
fn=lambda c, t, i, d: (gr.update(value=get_orders_data(c, t, i, d)), gr.update(value=get_revenue(c, t, i, d))),
|
| 1155 |
+
inputs=[customer_filter, time_filter, item_filter, delivery_filter], outputs=[orders_table, revenue_display]
|
| 1156 |
+
)
|
| 1157 |
+
|
| 1158 |
+
refresh_btn.click(
|
| 1159 |
+
fn=refresh_data,
|
| 1160 |
+
inputs=[customer_filter, time_filter, item_filter, delivery_filter],
|
| 1161 |
+
outputs=[orders_table, revenue_display, customer_filter, time_filter, item_filter, delivery_filter]
|
| 1162 |
+
)
|
| 1163 |
+
|
| 1164 |
+
orders_table.select(
|
| 1165 |
+
fn=autofill_delete_target, inputs=[orders_table], outputs=[delete_target]
|
| 1166 |
+
)
|
| 1167 |
+
|
| 1168 |
+
delete_single_btn.click(
|
| 1169 |
+
fn=delete_single_order,
|
| 1170 |
+
inputs=[delete_target, customer_filter, time_filter, item_filter, delivery_filter],
|
| 1171 |
+
outputs=[admin_status_msg, orders_table, revenue_display, delete_target],
|
| 1172 |
+
js="(target, c_filter, t_filter, i_filter, d_filter) => { if (!target) { return [target, c_filter, t_filter, i_filter, d_filter]; } return confirm('⚠️ 確認要刪除訂單編號 [' + target + '] 嗎?此動作無法復原!') ? [target, c_filter, t_filter, i_filter, d_filter] : ['__CANCEL__', c_filter, t_filter, i_filter, d_filter]; }"
|
| 1173 |
+
)
|
| 1174 |
+
|
| 1175 |
+
clear_btn.click(
|
| 1176 |
+
fn=clear_orders,
|
| 1177 |
+
inputs=[customer_filter],
|
| 1178 |
+
outputs=[admin_status_msg, orders_table, revenue_display, customer_filter, time_filter, item_filter, delivery_filter],
|
| 1179 |
+
js="(filter) => { return confirm('🚨 極度危險:確定要清空【所有】訂單資料嗎?此動作無法復原!') ? [filter] : ['__CANCEL__']; }"
|
| 1180 |
+
)
|
| 1181 |
+
|
| 1182 |
+
github_btn.click(fn=backup_and_push_to_github, inputs=[], outputs=[github_log_output])
|
| 1183 |
+
|
| 1184 |
+
save_menu_btn.click(
|
| 1185 |
+
fn=update_menu, inputs=[menu_table], outputs=[global_sys_msg, menu_trigger]
|
| 1186 |
+
)
|
| 1187 |
+
|
| 1188 |
+
restore_btn.click(
|
| 1189 |
+
fn=restore_from_backup, inputs=[], outputs=[global_sys_msg, menu_trigger]
|
| 1190 |
+
)
|
| 1191 |
+
|
| 1192 |
+
save_members_btn.click(
|
| 1193 |
+
fn=update_members_list, inputs=[members_table], outputs=[members_status, members_table]
|
| 1194 |
+
)
|
| 1195 |
+
|
| 1196 |
+
update_pwd_btn.click(
|
| 1197 |
+
fn=change_password, inputs=[old_pwd_input, new_pwd_input], outputs=[pwd_update_status]
|
| 1198 |
+
)
|
| 1199 |
+
|
| 1200 |
+
# --- 全域事件綁定區 ---
|
| 1201 |
|
|
|
|
| 1202 |
login_btn.click(
|
| 1203 |
fn=do_login,
|
| 1204 |
inputs=[login_acc, login_pwd],
|
| 1205 |
+
outputs=[login_container, main_container, login_msg, current_user_state, user_greeting, global_sys_msg]
|
| 1206 |
)
|
| 1207 |
login_pwd.submit(
|
| 1208 |
fn=do_login,
|
| 1209 |
inputs=[login_acc, login_pwd],
|
| 1210 |
+
outputs=[login_container, main_container, login_msg, current_user_state, user_greeting, global_sys_msg]
|
| 1211 |
)
|
| 1212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1213 |
logout_btn.click(
|
| 1214 |
fn=logout,
|
| 1215 |
inputs=[],
|
| 1216 |
+
outputs=[login_container, main_container, login_acc, login_pwd, login_msg, current_user_state, global_sys_msg]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1217 |
)
|
| 1218 |
|
| 1219 |
# ----------------------------
|