DeepLearning101 commited on
Commit
a93e4cc
·
verified ·
1 Parent(s): 076de50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -18
app.py CHANGED
@@ -13,6 +13,7 @@ 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
  # 取得帳密
@@ -131,42 +132,84 @@ def check_login(user, password):
131
  error_msg: "<span style='color: red'>❌ 帳號或密碼錯誤</span>"
132
  }
133
 
134
- # --- 🔥 [最終簡化版 CSS]:不破壞結構,只控制寬度和捲軸 ---
135
  custom_css = """
136
- /* 1. 隱藏元件最外層多餘的捲軸,解決雙重捲軸問題 */
137
  #booking_table .wrap {
138
- overflow: visible !important;
139
  }
140
 
141
- /* 2. 針對負責捲動的容器設定水平捲軸 */
142
  #booking_table .table-wrap {
143
  overflow-x: auto !important;
144
  overflow-y: hidden !important;
145
  }
146
 
147
- /* 3. 表格設定
148
- width: max-content -> 讓表格寬度等於內容總寬度 (實現自動撐開)
149
- table-layout: auto -> 讓瀏覽器依照文字長自動計算每一欄寬度
 
150
  */
151
  #booking_table table {
 
152
  width: max-content !important;
153
- table-layout: auto !important;
154
  border-collapse: collapse !important;
 
155
  }
156
 
157
- /* 4. 欄位設定:
158
- white-space: nowrap -> 禁止換行,確保寬度是「撐開」而不是「擠高」
159
- width: auto -> 自動寬度
 
160
  */
161
- #booking_table td, #booking_table th {
162
- white-space: nowrap !important;
163
- width: auto !important;
164
- max-width: none !important;
165
- padding: 8px 12px !important;
 
 
 
 
 
 
 
166
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  """
168
 
169
- # --- 介面開始 (加入 css 參數) ---
170
  with gr.Blocks(title="Admin", css=custom_css) as demo:
171
 
172
  # 1. 登入介面
@@ -183,7 +226,7 @@ with gr.Blocks(title="Admin", css=custom_css) as demo:
183
  gr.Markdown("# 🍷 訂位管理後台 (Dashboard)")
184
  refresh_btn = gr.Button("🔄 重新整理")
185
 
186
- # ✅ 保持 elem_id 以便 CSS 抓取
187
  booking_table = gr.Dataframe(interactive=False, elem_id="booking_table")
188
 
189
  with gr.Row():
 
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
  # 取得帳密
 
132
  error_msg: "<span style='color: red'>❌ 帳號或密碼錯誤</span>"
133
  }
134
 
135
+ # --- 🔥 [絕對控制版 CSS] ---
136
  custom_css = """
137
+ /* 1. 隱藏 Gradio 外層多餘的捲軸,只留內部一個 */
138
  #booking_table .wrap {
139
+ overflow: hidden !important;
140
  }
141
 
142
+ /* 2. 表格容器:強制開啟 X 軸捲軸 */
143
  #booking_table .table-wrap {
144
  overflow-x: auto !important;
145
  overflow-y: hidden !important;
146
  }
147
 
148
+ /* 3. 表格本體
149
+ table-layout: fixed -> 絕對尊重每個欄位的寬度設定
150
+ width: max-content -> 表格總寬等於所有寬度總和 (約1500px)
151
+ 這樣在手機上一定會超出螢幕,觸發水平捲軸
152
  */
153
  #booking_table table {
154
+ table-layout: fixed !important;
155
  width: max-content !important;
 
156
  border-collapse: collapse !important;
157
+ margin: 0 !important;
158
  }
159
 
160
+ /* 4. 欄位通用設定:
161
+ white-space: normal -> 允許換行 (您現在的要求)
162
+ word-break: break-all -> 強制換行 (避免長字串撐開)
163
+ vertical-align: top -> 對齊上方 (換行後比較好看)
164
  */
165
+ #booking_table th, #booking_table td {
166
+ display: table-cell !important;
167
+ white-space: normal !important;
168
+ word-break: break-word !important;
169
+ overflow-wrap: break-word !important;
170
+ vertical-align: top !important;
171
+
172
+ box-sizing: border-box !important;
173
+ padding: 8px 10px !important;
174
+ border: 1px solid #444 !important;
175
+ font-size: 14px !important;
176
+ line-height: 1.4 !important;
177
  }
178
+
179
+ /* 5. 🔥【依照您的要求,固定每個欄位寬度】🔥 */
180
+
181
+ /* #1 id */
182
+ #booking_table th:nth-child(1), #booking_table td:nth-child(1) { min-width: 60px !important; width: 60px !important; }
183
+
184
+ /* #2 date */
185
+ #booking_table th:nth-child(2), #booking_table td:nth-child(2) { min-width: 170px !important; width: 170px !important; }
186
+
187
+ /* #3 time */
188
+ #booking_table th:nth-child(3), #booking_table td:nth-child(3) { min-width: 80px !important; width: 80px !important; }
189
+
190
+ /* #4 name */
191
+ #booking_table th:nth-child(4), #booking_table td:nth-child(4) { min-width: 120px !important; width: 120px !important; }
192
+
193
+ /* #5 tel */
194
+ #booking_table th:nth-child(5), #booking_table td:nth-child(5) { min-width: 120px !important; width: 120px !important; }
195
+
196
+ /* #6 email */
197
+ #booking_table th:nth-child(6), #booking_table td:nth-child(6) { min-width: 250px !important; width: 250px !important; }
198
+
199
+ /* #7 pax */
200
+ #booking_table th:nth-child(7), #booking_table td:nth-child(7) { min-width: 50px !important; width: 50px !important; }
201
+
202
+ /* #8 remarks */
203
+ #booking_table th:nth-child(8), #booking_table td:nth-child(8) { min-width: 180px !important; width: 180px !important; }
204
+
205
+ /* #9 status */
206
+ #booking_table th:nth-child(9), #booking_table td:nth-child(9) { min-width: 120px !important; width: 120px !important; }
207
+
208
+ /* #10 user_id */
209
+ #booking_table th:nth-child(10), #booking_table td:nth-child(10) { min-width: 280px !important; width: 320px !important; }
210
  """
211
 
212
+ # --- 介面開始 ---
213
  with gr.Blocks(title="Admin", css=custom_css) as demo:
214
 
215
  # 1. 登入介面
 
226
  gr.Markdown("# 🍷 訂位管理後台 (Dashboard)")
227
  refresh_btn = gr.Button("🔄 重新整理")
228
 
229
+ # ✅ elem_id 保持 booking_table
230
  booking_table = gr.Dataframe(interactive=False, elem_id="booking_table")
231
 
232
  with gr.Row():