Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -114,11 +114,25 @@ def save_orders():
|
|
| 114 |
orders_db = load_orders()
|
| 115 |
|
| 116 |
def load_menu():
|
| 117 |
-
loaded_menu =
|
|
|
|
| 118 |
if os.path.exists(MENU_FILE):
|
| 119 |
try:
|
| 120 |
with open(MENU_FILE, "r", encoding="utf-8") as f:
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
except Exception as e:
|
| 123 |
print(f"讀取菜單 JSON 失敗: {e}")
|
| 124 |
|
|
@@ -147,7 +161,11 @@ def load_menu():
|
|
| 147 |
note = str(row.get("備註", "")).strip() if pd.notna(row.get("備註", "")) else ""
|
| 148 |
|
| 149 |
if item:
|
| 150 |
-
loaded_menu
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
with open(MENU_FILE, "w", encoding="utf-8") as f:
|
| 153 |
json.dump(loaded_menu, f, ensure_ascii=False, indent=4)
|
|
@@ -155,24 +173,21 @@ def load_menu():
|
|
| 155 |
print(f"從 CSV 還原菜單失敗: {e}")
|
| 156 |
|
| 157 |
if not loaded_menu:
|
| 158 |
-
loaded_menu =
|
| 159 |
-
"招牌咖啡"
|
| 160 |
-
"拿鐵咖啡"
|
| 161 |
-
"珍珠奶茶"
|
| 162 |
-
"高山青茶"
|
| 163 |
-
"手工餅乾"
|
| 164 |
-
|
| 165 |
else:
|
| 166 |
-
for i,
|
| 167 |
-
if
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
if "category" not in v: v["category"] = "未分類"
|
| 174 |
-
if "spec" not in v: v["spec"] = ""
|
| 175 |
-
if "note" not in v: v["note"] = ""
|
| 176 |
|
| 177 |
return loaded_menu
|
| 178 |
|
|
@@ -220,24 +235,25 @@ MEMBERS = load_members()
|
|
| 220 |
|
| 221 |
def get_frontend_menu_items(user_level="全部"):
|
| 222 |
enabled_items = []
|
| 223 |
-
for
|
| 224 |
-
if not
|
| 225 |
continue
|
| 226 |
-
item_lvl = str(
|
| 227 |
if user_level == "admin" or item_lvl == "全部" or item_lvl == str(user_level):
|
| 228 |
-
enabled_items.append(
|
| 229 |
|
| 230 |
-
enabled_items = sorted(enabled_items, key=lambda x: x
|
| 231 |
|
| 232 |
category_order = []
|
| 233 |
items_by_cat = {}
|
| 234 |
|
| 235 |
-
for
|
| 236 |
cat = details.get("category", "未分類")
|
| 237 |
cat = cat.strip() if cat.strip() else "未分類"
|
| 238 |
if cat not in category_order:
|
| 239 |
category_order.append(cat)
|
| 240 |
-
|
|
|
|
| 241 |
|
| 242 |
flat_list = []
|
| 243 |
for cat in category_order:
|
|
@@ -246,22 +262,22 @@ def get_frontend_menu_items(user_level="全部"):
|
|
| 246 |
return category_order, items_by_cat, flat_list
|
| 247 |
|
| 248 |
def get_menu_df():
|
| 249 |
-
sorted_menu = sorted(MENU
|
| 250 |
data = []
|
| 251 |
-
for
|
| 252 |
data.append([
|
| 253 |
v.get("seq", 999),
|
| 254 |
v.get("enable", True),
|
| 255 |
v.get("level", "全部"),
|
| 256 |
v.get("category", "未分類"),
|
| 257 |
-
|
| 258 |
v.get("spec", ""),
|
| 259 |
v.get("price", 0),
|
| 260 |
v.get("cost", 0),
|
| 261 |
v.get("note", "")
|
| 262 |
])
|
| 263 |
|
| 264 |
-
max_seq = max([v.get("seq", 0) for v in MENU
|
| 265 |
for i in range(20):
|
| 266 |
data.append([max_seq + i + 1, False, "全部", "未分類", "", "", 0, 0, ""])
|
| 267 |
|
|
@@ -307,7 +323,7 @@ def save_members_to_file():
|
|
| 307 |
def _internal_update_menu(df):
|
| 308 |
global MENU
|
| 309 |
if df is None: return False
|
| 310 |
-
new_menu =
|
| 311 |
for row in df.values.tolist():
|
| 312 |
try: seq = int(float(row[0])) if pd.notna(row[0]) and str(row[0]).strip() else 999
|
| 313 |
except: seq = 999
|
|
@@ -331,13 +347,18 @@ def _internal_update_menu(df):
|
|
| 331 |
note = str(row[8]).strip() if pd.notna(row[8]) else ""
|
| 332 |
|
| 333 |
if item:
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
|
| 336 |
if not new_menu:
|
| 337 |
return False
|
| 338 |
|
| 339 |
MENU.clear()
|
| 340 |
-
MENU.
|
| 341 |
save_menu_to_file()
|
| 342 |
return True
|
| 343 |
|
|
@@ -402,13 +423,20 @@ def handle_message(event):
|
|
| 402 |
if "我要訂" in user_msg:
|
| 403 |
try:
|
| 404 |
parts = user_msg.split()
|
| 405 |
-
|
| 406 |
quantity = int(parts[2])
|
| 407 |
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
|
| 413 |
order_note = f"來自 LINE 文字點餐"
|
| 414 |
if spec: order_note += f" ({spec})"
|
|
@@ -425,7 +453,7 @@ def handle_message(event):
|
|
| 425 |
"取貨方式": "自取",
|
| 426 |
"送貨地點": "",
|
| 427 |
"顧客姓名": f"LINE用戶({user_id[-4:]})",
|
| 428 |
-
"商品":
|
| 429 |
"單價": price,
|
| 430 |
"成本": cost,
|
| 431 |
"數量": quantity,
|
|
@@ -436,10 +464,11 @@ def handle_message(event):
|
|
| 436 |
|
| 437 |
save_orders()
|
| 438 |
|
| 439 |
-
reply_text = f"✅ 訂單成立
|
| 440 |
else:
|
| 441 |
-
|
| 442 |
-
|
|
|
|
| 443 |
except Exception:
|
| 444 |
reply_text = "❌ 點餐格式錯誤。\n請確認格式為:『我要訂 招牌咖啡 1』"
|
| 445 |
|
|
@@ -604,7 +633,7 @@ def restore_from_backup():
|
|
| 604 |
if os.path.exists(MENU_BACKUP_FILE) and os.path.getsize(MENU_BACKUP_FILE) > 0:
|
| 605 |
try:
|
| 606 |
m_df = pd.read_csv(MENU_BACKUP_FILE)
|
| 607 |
-
new_menu =
|
| 608 |
for _, row in m_df.iterrows():
|
| 609 |
seq = int(row.get("流水號", 999))
|
| 610 |
val_enable = row.get("啟用", True)
|
|
@@ -620,10 +649,14 @@ def restore_from_backup():
|
|
| 620 |
note = str(row.get("備註", "")).strip() if pd.notna(row.get("備註", "")) else ""
|
| 621 |
|
| 622 |
if item:
|
| 623 |
-
new_menu
|
|
|
|
|
|
|
|
|
|
|
|
|
| 624 |
if new_menu:
|
| 625 |
MENU.clear()
|
| 626 |
-
MENU.
|
| 627 |
save_menu_to_file()
|
| 628 |
msg += "\n✅ 菜單已成功從備份同步還原!"
|
| 629 |
except Exception as e:
|
|
@@ -684,7 +717,7 @@ def add_order(current_user, c_name, p_method, d_location, d_month, d_day, d_time
|
|
| 684 |
for i, qty in enumerate(quantities):
|
| 685 |
if qty > 0:
|
| 686 |
has_ordered_items = True
|
| 687 |
-
|
| 688 |
price = details["price"]
|
| 689 |
cost = details.get("cost", 0)
|
| 690 |
spec = details.get("spec", "")
|
|
@@ -704,7 +737,7 @@ def add_order(current_user, c_name, p_method, d_location, d_month, d_day, d_time
|
|
| 704 |
"取貨方式": p_method,
|
| 705 |
"送貨地點": d_location if p_method == "送貨" else "",
|
| 706 |
"顧客姓名": c_name,
|
| 707 |
-
"商品":
|
| 708 |
"單價": price,
|
| 709 |
"成本": cost,
|
| 710 |
"數量": qty,
|
|
@@ -713,7 +746,7 @@ def add_order(current_user, c_name, p_method, d_location, d_month, d_day, d_time
|
|
| 713 |
"備註": final_note
|
| 714 |
})
|
| 715 |
|
| 716 |
-
desc = f"{
|
| 717 |
items_desc.append(desc)
|
| 718 |
|
| 719 |
if not has_ordered_items:
|
|
@@ -1169,7 +1202,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="簡易訂單管理系統") as demo
|
|
| 1169 |
with gr.Column(scale=0, min_width=140, elem_classes="center-col"):
|
| 1170 |
gr.HTML("<div style='text-align: center; font-weight: bold; color: #64748b; font-size: 0.9em; width: 100%;'>數量</div>")
|
| 1171 |
|
| 1172 |
-
for
|
| 1173 |
price = details["price"]
|
| 1174 |
spec = details.get("spec", "")
|
| 1175 |
|
|
@@ -1177,7 +1210,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="簡易訂單管理系統") as demo
|
|
| 1177 |
with gr.Column(scale=0, min_width=60, elem_classes="center-col"):
|
| 1178 |
found_img_path = None
|
| 1179 |
for ext in ['.jpg', '.jpeg', '.png', '.JPG', '.PNG']:
|
| 1180 |
-
temp_path = os.path.join(pic_dir, f"{
|
| 1181 |
if os.path.exists(temp_path):
|
| 1182 |
found_img_path = temp_path
|
| 1183 |
break
|
|
@@ -1195,7 +1228,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="簡易訂單管理系統") as demo
|
|
| 1195 |
"""
|
| 1196 |
gr.HTML(value=img_html)
|
| 1197 |
except Exception:
|
| 1198 |
-
first_char =
|
| 1199 |
placeholder_html = f"""
|
| 1200 |
<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;">
|
| 1201 |
{first_char}
|
|
@@ -1203,7 +1236,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="簡易訂單管理系統") as demo
|
|
| 1203 |
"""
|
| 1204 |
gr.HTML(value=placeholder_html)
|
| 1205 |
else:
|
| 1206 |
-
first_char =
|
| 1207 |
placeholder_html = f"""
|
| 1208 |
<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;">
|
| 1209 |
{first_char}
|
|
@@ -1215,7 +1248,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="簡易訂單管理系統") as demo
|
|
| 1215 |
spec_html = f"<span style='font-size: 0.85em; color: #ef4444; padding: 2px 6px; background: #fee2e2; border-radius: 4px;'>{spec}</span>" if spec else ""
|
| 1216 |
info_html = f"""
|
| 1217 |
<div style='display: flex; width: 100%; align-items: center; text-align: center; margin: auto 0;'>
|
| 1218 |
-
<div style='flex: 1; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;'>{
|
| 1219 |
<div style='flex: 1;'>{spec_html}</div>
|
| 1220 |
<div style='flex: 1; color: gray; font-size: 0.9em; white-space: nowrap;'>NT$ {price}</div>
|
| 1221 |
</div>
|
|
|
|
| 114 |
orders_db = load_orders()
|
| 115 |
|
| 116 |
def load_menu():
|
| 117 |
+
loaded_menu = []
|
| 118 |
+
# 支援讀取舊版的 Dictionary 格式,並自動轉換成可容許重複品項的 List 格式
|
| 119 |
if os.path.exists(MENU_FILE):
|
| 120 |
try:
|
| 121 |
with open(MENU_FILE, "r", encoding="utf-8") as f:
|
| 122 |
+
data = json.load(f)
|
| 123 |
+
if isinstance(data, dict):
|
| 124 |
+
for k, v in data.items():
|
| 125 |
+
if isinstance(v, dict):
|
| 126 |
+
v["name"] = k
|
| 127 |
+
loaded_menu.append(v)
|
| 128 |
+
else:
|
| 129 |
+
loaded_menu.append({
|
| 130 |
+
"name": k, "price": int(v), "cost": 0,
|
| 131 |
+
"enable": True, "level": "全部", "seq": 999,
|
| 132 |
+
"category": "未分類", "spec": "", "note": ""
|
| 133 |
+
})
|
| 134 |
+
elif isinstance(data, list):
|
| 135 |
+
loaded_menu = data
|
| 136 |
except Exception as e:
|
| 137 |
print(f"讀取菜單 JSON 失敗: {e}")
|
| 138 |
|
|
|
|
| 161 |
note = str(row.get("備註", "")).strip() if pd.notna(row.get("備註", "")) else ""
|
| 162 |
|
| 163 |
if item:
|
| 164 |
+
loaded_menu.append({
|
| 165 |
+
"name": item, "price": price, "cost": cost,
|
| 166 |
+
"enable": enable, "level": level, "seq": seq,
|
| 167 |
+
"category": cat, "spec": spec, "note": note
|
| 168 |
+
})
|
| 169 |
|
| 170 |
with open(MENU_FILE, "w", encoding="utf-8") as f:
|
| 171 |
json.dump(loaded_menu, f, ensure_ascii=False, indent=4)
|
|
|
|
| 173 |
print(f"從 CSV 還原菜單失敗: {e}")
|
| 174 |
|
| 175 |
if not loaded_menu:
|
| 176 |
+
loaded_menu = [
|
| 177 |
+
{"name": "招牌咖啡", "price": 80, "cost": 30, "enable": True, "level": "全部", "seq": 1, "category": "☕ 咖啡飲品", "spec": "中杯", "note": ""},
|
| 178 |
+
{"name": "拿鐵咖啡", "price": 100, "cost": 40, "enable": True, "level": "全部", "seq": 2, "category": "☕ 咖啡飲品", "spec": "中杯", "note": ""},
|
| 179 |
+
{"name": "珍珠奶茶", "price": 60, "cost": 20, "enable": True, "level": "全部", "seq": 3, "category": "🧋 特調茶飲", "spec": "大杯", "note": ""},
|
| 180 |
+
{"name": "高山青茶", "price": 40, "cost": 15, "enable": True, "level": "全部", "seq": 4, "category": "🧋 特調茶飲", "spec": "大杯", "note": ""},
|
| 181 |
+
{"name": "手工餅乾", "price": 50, "cost": 20, "enable": True, "level": "全部", "seq": 5, "category": "🍪 美味點心", "spec": "一份", "note": ""}
|
| 182 |
+
]
|
| 183 |
else:
|
| 184 |
+
for i, v in enumerate(loaded_menu):
|
| 185 |
+
if "enable" not in v: v["enable"] = True
|
| 186 |
+
if "level" not in v: v["level"] = "全部"
|
| 187 |
+
if "seq" not in v: v["seq"] = i + 1
|
| 188 |
+
if "category" not in v: v["category"] = "未分類"
|
| 189 |
+
if "spec" not in v: v["spec"] = ""
|
| 190 |
+
if "note" not in v: v["note"] = ""
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
return loaded_menu
|
| 193 |
|
|
|
|
| 235 |
|
| 236 |
def get_frontend_menu_items(user_level="全部"):
|
| 237 |
enabled_items = []
|
| 238 |
+
for item_dict in MENU:
|
| 239 |
+
if not item_dict.get("enable", True):
|
| 240 |
continue
|
| 241 |
+
item_lvl = str(item_dict.get("level", "全部")).strip()
|
| 242 |
if user_level == "admin" or item_lvl == "全部" or item_lvl == str(user_level):
|
| 243 |
+
enabled_items.append(item_dict)
|
| 244 |
|
| 245 |
+
enabled_items = sorted(enabled_items, key=lambda x: x.get("seq", 999))
|
| 246 |
|
| 247 |
category_order = []
|
| 248 |
items_by_cat = {}
|
| 249 |
|
| 250 |
+
for details in enabled_items:
|
| 251 |
cat = details.get("category", "未分類")
|
| 252 |
cat = cat.strip() if cat.strip() else "未分類"
|
| 253 |
if cat not in category_order:
|
| 254 |
category_order.append(cat)
|
| 255 |
+
# 提取名稱並附上原本的字典資料
|
| 256 |
+
items_by_cat.setdefault(cat, []).append((details.get("name", "未命名"), details))
|
| 257 |
|
| 258 |
flat_list = []
|
| 259 |
for cat in category_order:
|
|
|
|
| 262 |
return category_order, items_by_cat, flat_list
|
| 263 |
|
| 264 |
def get_menu_df():
|
| 265 |
+
sorted_menu = sorted(MENU, key=lambda x: x.get("seq", 999))
|
| 266 |
data = []
|
| 267 |
+
for v in sorted_menu:
|
| 268 |
data.append([
|
| 269 |
v.get("seq", 999),
|
| 270 |
v.get("enable", True),
|
| 271 |
v.get("level", "全部"),
|
| 272 |
v.get("category", "未分類"),
|
| 273 |
+
v.get("name", ""),
|
| 274 |
v.get("spec", ""),
|
| 275 |
v.get("price", 0),
|
| 276 |
v.get("cost", 0),
|
| 277 |
v.get("note", "")
|
| 278 |
])
|
| 279 |
|
| 280 |
+
max_seq = max([v.get("seq", 0) for v in MENU]) if MENU else 0
|
| 281 |
for i in range(20):
|
| 282 |
data.append([max_seq + i + 1, False, "全部", "未分類", "", "", 0, 0, ""])
|
| 283 |
|
|
|
|
| 323 |
def _internal_update_menu(df):
|
| 324 |
global MENU
|
| 325 |
if df is None: return False
|
| 326 |
+
new_menu = []
|
| 327 |
for row in df.values.tolist():
|
| 328 |
try: seq = int(float(row[0])) if pd.notna(row[0]) and str(row[0]).strip() else 999
|
| 329 |
except: seq = 999
|
|
|
|
| 347 |
note = str(row[8]).strip() if pd.notna(row[8]) else ""
|
| 348 |
|
| 349 |
if item:
|
| 350 |
+
# 改為 Append 到 List,完美解決同名品項會被覆蓋的問題
|
| 351 |
+
new_menu.append({
|
| 352 |
+
"name": item, "price": price, "cost": cost,
|
| 353 |
+
"enable": enable, "level": target_lvl, "seq": seq,
|
| 354 |
+
"category": cat, "spec": spec, "note": note
|
| 355 |
+
})
|
| 356 |
|
| 357 |
if not new_menu:
|
| 358 |
return False
|
| 359 |
|
| 360 |
MENU.clear()
|
| 361 |
+
MENU.extend(new_menu)
|
| 362 |
save_menu_to_file()
|
| 363 |
return True
|
| 364 |
|
|
|
|
| 423 |
if "我要訂" in user_msg:
|
| 424 |
try:
|
| 425 |
parts = user_msg.split()
|
| 426 |
+
item_name = parts[1]
|
| 427 |
quantity = int(parts[2])
|
| 428 |
|
| 429 |
+
# 從 List 中尋找第一個匹配名稱且啟用的品項
|
| 430 |
+
matched_item = None
|
| 431 |
+
for menu_item in MENU:
|
| 432 |
+
if menu_item.get("name") == item_name and menu_item.get("enable", True):
|
| 433 |
+
matched_item = menu_item
|
| 434 |
+
break
|
| 435 |
+
|
| 436 |
+
if matched_item:
|
| 437 |
+
price = matched_item["price"]
|
| 438 |
+
cost = matched_item.get("cost", 0)
|
| 439 |
+
spec = matched_item.get("spec", "")
|
| 440 |
|
| 441 |
order_note = f"來自 LINE 文字點餐"
|
| 442 |
if spec: order_note += f" ({spec})"
|
|
|
|
| 453 |
"取貨方式": "自取",
|
| 454 |
"送貨地點": "",
|
| 455 |
"顧客姓名": f"LINE用戶({user_id[-4:]})",
|
| 456 |
+
"商品": item_name,
|
| 457 |
"單價": price,
|
| 458 |
"成本": cost,
|
| 459 |
"數量": quantity,
|
|
|
|
| 464 |
|
| 465 |
save_orders()
|
| 466 |
|
| 467 |
+
reply_text = f"✅ 訂單成立���\n您訂購了 {item_name} x {quantity}。\n總金額為 {total} 元,請稍候為您準備!"
|
| 468 |
else:
|
| 469 |
+
# 產出過濾重複名稱的清單供用戶參考
|
| 470 |
+
active_item_names = list(dict.fromkeys([v.get("name") for v in MENU if v.get("enable", True)]))
|
| 471 |
+
reply_text = f"❌ 找不到商品『{item_name}』,或該商品目前未提供!\n目前供應:{', '.join(active_item_names)}"
|
| 472 |
except Exception:
|
| 473 |
reply_text = "❌ 點餐格式錯誤。\n請確認格式為:『我要訂 招牌咖啡 1』"
|
| 474 |
|
|
|
|
| 633 |
if os.path.exists(MENU_BACKUP_FILE) and os.path.getsize(MENU_BACKUP_FILE) > 0:
|
| 634 |
try:
|
| 635 |
m_df = pd.read_csv(MENU_BACKUP_FILE)
|
| 636 |
+
new_menu = []
|
| 637 |
for _, row in m_df.iterrows():
|
| 638 |
seq = int(row.get("流水號", 999))
|
| 639 |
val_enable = row.get("啟用", True)
|
|
|
|
| 649 |
note = str(row.get("備註", "")).strip() if pd.notna(row.get("備註", "")) else ""
|
| 650 |
|
| 651 |
if item:
|
| 652 |
+
new_menu.append({
|
| 653 |
+
"name": item, "price": price, "cost": cost,
|
| 654 |
+
"enable": enable, "level": level, "seq": seq,
|
| 655 |
+
"category": cat, "spec": spec, "note": note
|
| 656 |
+
})
|
| 657 |
if new_menu:
|
| 658 |
MENU.clear()
|
| 659 |
+
MENU.extend(new_menu)
|
| 660 |
save_menu_to_file()
|
| 661 |
msg += "\n✅ 菜單已成功從備份同步還原!"
|
| 662 |
except Exception as e:
|
|
|
|
| 717 |
for i, qty in enumerate(quantities):
|
| 718 |
if qty > 0:
|
| 719 |
has_ordered_items = True
|
| 720 |
+
item_name, details = flat_list[i]
|
| 721 |
price = details["price"]
|
| 722 |
cost = details.get("cost", 0)
|
| 723 |
spec = details.get("spec", "")
|
|
|
|
| 737 |
"取貨方式": p_method,
|
| 738 |
"送貨地點": d_location if p_method == "送貨" else "",
|
| 739 |
"顧客姓名": c_name,
|
| 740 |
+
"商品": item_name,
|
| 741 |
"單價": price,
|
| 742 |
"成本": cost,
|
| 743 |
"數量": qty,
|
|
|
|
| 746 |
"備註": final_note
|
| 747 |
})
|
| 748 |
|
| 749 |
+
desc = f"{item_name}{item_note}x{qty}"
|
| 750 |
items_desc.append(desc)
|
| 751 |
|
| 752 |
if not has_ordered_items:
|
|
|
|
| 1202 |
with gr.Column(scale=0, min_width=140, elem_classes="center-col"):
|
| 1203 |
gr.HTML("<div style='text-align: center; font-weight: bold; color: #64748b; font-size: 0.9em; width: 100%;'>數量</div>")
|
| 1204 |
|
| 1205 |
+
for item_name, details in items_by_cat[cat]:
|
| 1206 |
price = details["price"]
|
| 1207 |
spec = details.get("spec", "")
|
| 1208 |
|
|
|
|
| 1210 |
with gr.Column(scale=0, min_width=60, elem_classes="center-col"):
|
| 1211 |
found_img_path = None
|
| 1212 |
for ext in ['.jpg', '.jpeg', '.png', '.JPG', '.PNG']:
|
| 1213 |
+
temp_path = os.path.join(pic_dir, f"{item_name}{ext}")
|
| 1214 |
if os.path.exists(temp_path):
|
| 1215 |
found_img_path = temp_path
|
| 1216 |
break
|
|
|
|
| 1228 |
"""
|
| 1229 |
gr.HTML(value=img_html)
|
| 1230 |
except Exception:
|
| 1231 |
+
first_char = item_name[0] if item_name else "品"
|
| 1232 |
placeholder_html = f"""
|
| 1233 |
<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;">
|
| 1234 |
{first_char}
|
|
|
|
| 1236 |
"""
|
| 1237 |
gr.HTML(value=placeholder_html)
|
| 1238 |
else:
|
| 1239 |
+
first_char = item_name[0] if item_name else "品"
|
| 1240 |
placeholder_html = f"""
|
| 1241 |
<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;">
|
| 1242 |
{first_char}
|
|
|
|
| 1248 |
spec_html = f"<span style='font-size: 0.85em; color: #ef4444; padding: 2px 6px; background: #fee2e2; border-radius: 4px;'>{spec}</span>" if spec else ""
|
| 1249 |
info_html = f"""
|
| 1250 |
<div style='display: flex; width: 100%; align-items: center; text-align: center; margin: auto 0;'>
|
| 1251 |
+
<div style='flex: 1; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;'>{item_name}</div>
|
| 1252 |
<div style='flex: 1;'>{spec_html}</div>
|
| 1253 |
<div style='flex: 1; color: gray; font-size: 0.9em; white-space: nowrap;'>NT$ {price}</div>
|
| 1254 |
</div>
|