DeepLearning101 commited on
Commit
69cabef
·
verified ·
1 Parent(s): 51e3854

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -69
app.py CHANGED
@@ -13,9 +13,10 @@ SUPABASE_URL = os.getenv("SUPABASE_URL")
13
  SUPABASE_KEY = os.getenv("SUPABASE_KEY")
14
  GAS_MAIL_URL = os.getenv("GAS_MAIL_URL")
15
  LINE_ACCESS_TOKEN = os.getenv("LINE_ACCESS_TOKEN")
 
16
  PUBLIC_SPACE_URL = "https://deeplearning101-ciecietaipei.hf.space"
17
 
18
- # 取得帳密
19
  REAL_ADMIN_USER = os.getenv("ADMIN_USER") or "Deep Learning 101"
20
  REAL_ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD") or "2016-11-11"
21
 
@@ -118,7 +119,7 @@ def send_confirmation_hybrid(booking_id):
118
  return log_msg
119
  except Exception as e: return f"❌ Error: {str(e)}"
120
 
121
- # --- 登入邏輯 ---
122
  def check_login(user, password):
123
  if user == REAL_ADMIN_USER and password == REAL_ADMIN_PASSWORD:
124
  return {
@@ -127,86 +128,52 @@ def check_login(user, password):
127
  error_msg: ""
128
  }
129
  else:
 
130
  return {
131
  error_msg: "<span style='color: red'>❌ 帳號或密碼錯誤</span>"
132
  }
133
 
134
- # --- 🔥 [最終修正 CSS] 🔥 ---
135
  custom_css = """
136
- /* 1. 殺掉外層捲軸 (綠色框框問題) */
137
- #booking_table .wrap {
138
- overflow: hidden !important;
139
- }
140
-
141
- /* 2. 保留內層捲軸 (紅色框框),這是唯一可以捲動的地方 */
142
- #booking_table .table-wrap {
143
  overflow-x: auto !important;
144
- overflow-y: hidden !important;
145
- border: 1px solid #444 !important;
146
  }
147
 
148
- /* 3. 表格本體設定
149
- min-width: 1500px -> 確保表格夠寬,強迫出現捲軸
150
- table-layout: fixed -> 強制瀏覽器聽從下方的欄位寬度設定
 
151
  */
152
- #booking_table table {
153
- table-layout: fixed !important;
154
- min-width: 1500px !important;
155
  border-collapse: collapse !important;
156
- margin: 0 !important;
157
  }
158
 
159
- /* 4. 通用儲存格設定 */
160
- #booking_table th, #booking_table td {
161
- display: table-cell !important;
162
- white-space: normal !important; /* ✅ 允許換行 */
163
- overflow-wrap: break-word !important; /* 長單字換行 */
164
- word-break: break-all !important;
 
 
 
165
 
166
- vertical-align: top !important;
167
- box-sizing: border-box !important;
168
- padding: 8px 5px !important;
169
- border: 1px solid #444 !important;
170
- font-size: 13px !important;
171
- line-height: 1.4 !important;
172
  }
173
 
174
- /* 5. 🔥【依照您的要求,固定每個欄位寬度】🔥 */
175
- /* 注意:這裡同時設定 width min-width 確保瀏覽器不會壓縮它
176
- */
177
-
178
- /* #1 id: 60px */
179
- #booking_table th:nth-child(1), #booking_table td:nth-child(1) { width: 60px !important; min-width: 60px !important; }
180
-
181
- /* #2 date: 170px */
182
- #booking_table th:nth-child(2), #booking_table td:nth-child(2) { width: 170px !important; min-width: 170px !important; }
183
-
184
- /* #3 time: 80px */
185
- #booking_table th:nth-child(3), #booking_table td:nth-child(3) { width: 80px !important; min-width: 80px !important; }
186
-
187
- /* #4 name: 120px */
188
- #booking_table th:nth-child(4), #booking_table td:nth-child(4) { width: 120px !important; min-width: 120px !important; }
189
-
190
- /* #5 tel: 120px */
191
- #booking_table th:nth-child(5), #booking_table td:nth-child(5) { width: 120px !important; min-width: 120px !important; }
192
-
193
- /* #6 email: 250px */
194
- #booking_table th:nth-child(6), #booking_table td:nth-child(6) { width: 250px !important; min-width: 250px !important; }
195
-
196
- /* #7 pax: 50px */
197
- #booking_table th:nth-child(7), #booking_table td:nth-child(7) { width: 50px !important; min-width: 50px !important; }
198
-
199
- /* #8 remarks: 180px */
200
- #booking_table th:nth-child(8), #booking_table td:nth-child(8) { width: 180px !important; min-width: 180px !important; }
201
-
202
- /* #9 status: 120px */
203
- #booking_table th:nth-child(9), #booking_table td:nth-child(9) { width: 120px !important; min-width: 120px !important; }
204
-
205
- /* #10 user_id: 320px */
206
- #booking_table th:nth-child(10), #booking_table td:nth-child(10) { width: 320px !important; min-width: 320px !important; }
207
  """
208
 
209
- # --- 介面開始 ---
210
  with gr.Blocks(title="Admin", css=custom_css) as demo:
211
 
212
  # 1. 登入介面
@@ -222,10 +189,8 @@ with gr.Blocks(title="Admin", css=custom_css) as demo:
222
  with gr.Group(visible=False) as admin_row:
223
  gr.Markdown("# 🍷 訂位管理後台 (Dashboard)")
224
  refresh_btn = gr.Button("🔄 重新整理")
225
-
226
- # elem_id 保持為 booking_table
227
- booking_table = gr.Dataframe(interactive=False, elem_id="booking_table")
228
-
229
  with gr.Row():
230
  id_input = gr.Number(label="訂單 ID", precision=0)
231
  action_btn = gr.Button("📧 發送確認信 (Hybrid)", variant="primary")
 
13
  SUPABASE_KEY = os.getenv("SUPABASE_KEY")
14
  GAS_MAIL_URL = os.getenv("GAS_MAIL_URL")
15
  LINE_ACCESS_TOKEN = os.getenv("LINE_ACCESS_TOKEN")
16
+ # ⚠️ 請確認這是您 Space A 的正確網址 (結尾不要有斜線)
17
  PUBLIC_SPACE_URL = "https://deeplearning101-ciecietaipei.hf.space"
18
 
19
+ # 取得帳密 (若沒設定則使用預設值)
20
  REAL_ADMIN_USER = os.getenv("ADMIN_USER") or "Deep Learning 101"
21
  REAL_ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD") or "2016-11-11"
22
 
 
119
  return log_msg
120
  except Exception as e: return f"❌ Error: {str(e)}"
121
 
122
+ # --- 登入邏輯 (回傳 HTML 字串來控制顏色) ---
123
  def check_login(user, password):
124
  if user == REAL_ADMIN_USER and password == REAL_ADMIN_PASSWORD:
125
  return {
 
128
  error_msg: ""
129
  }
130
  else:
131
+ # ✅ 使用 HTML span 標籤來顯示紅色,而不是在 gr.Markdown 用 style 參數
132
  return {
133
  error_msg: "<span style='color: red'>❌ 帳號或密碼錯誤</span>"
134
  }
135
 
136
+ # --- 🔥 [最終修正 CSS]:不換行 + 自動撐開 + 捲軸 ---
137
  custom_css = """
138
+ /* 1. 確保外層容器可以捲動 */
139
+ div[data-testid="dataframe"] {
 
 
 
 
 
140
  overflow-x: auto !important;
141
+ max-width: 100vw !important; /* 確保容器本身不超過螢幕寬 */
142
+ display: block !important;
143
  }
144
 
145
+ /* 2. 表格本體:
146
+ min-width: max-content 是關鍵!
147
+ 它告訴瀏覽器:表格的最小寬度 = 內容完全展開後的總長度。
148
+ 這會迫使外層容器產生捲軸,而不是壓縮表格。
149
  */
150
+ table {
151
+ min-width: max-content !important;
152
+ width: auto !important;
153
  border-collapse: collapse !important;
 
154
  }
155
 
156
+ /* 3. 欄位設定:強制不換行 */
157
+ td, th {
158
+ white-space: nowrap !important; /* 🚫 絕對禁止換行 */
159
+ overflow: visible !important;
160
+ text-overflow: clip !important; /* 移除 ... */
161
+
162
+ /* 移除寬度限制,讓內容自己決定要多寬 */
163
+ max-width: none !important;
164
+ width: auto !important;
165
 
166
+ padding: 8px 12px !important; /* 舒適間距 */
 
 
 
 
 
167
  }
168
 
169
+ /* 4. 針對 Gradio 內部的 span 也強制不換行 */
170
+ td > span, th > span {
171
+ white-space: nowrap !important;
172
+ overflow: visible !important;
173
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  """
175
 
176
+ # --- 介面開始 (加入 css 參數) ---
177
  with gr.Blocks(title="Admin", css=custom_css) as demo:
178
 
179
  # 1. 登入介面
 
189
  with gr.Group(visible=False) as admin_row:
190
  gr.Markdown("# 🍷 訂位管理後台 (Dashboard)")
191
  refresh_btn = gr.Button("🔄 重新整理")
192
+ # 表格這裡會自動套用上面的 CSS
193
+ booking_table = gr.Dataframe(interactive=False)
 
 
194
  with gr.Row():
195
  id_input = gr.Number(label="訂單 ID", precision=0)
196
  action_btn = gr.Button("📧 發送確認信 (Hybrid)", variant="primary")