Spaces:
Sleeping
Sleeping
單一捲軸 + 定寬換行修正版
Browse files殺死外層捲軸:鎖定 #booking_table .wrap 和 gradio-container 相關層級,強制 overflow: hidden。
鎖定表格總寬度:既然我們要把欄位設死,那表格總寬度就必須是所有欄位寬度的總和(約 1500px)。我會直接設定 width: 1500px !important,這能確保只有這一個層級會產生捲動。
強制欄位行為:使用 fixed 佈局 + break-word 斷行,完全依照您指定的像素。
app.py
CHANGED
|
@@ -131,58 +131,66 @@ def check_login(user, password):
|
|
| 131 |
error_msg: "<span style='color: red'>❌ 帳號或密碼錯誤</span>"
|
| 132 |
}
|
| 133 |
|
| 134 |
-
# --- 🔥 [
|
| 135 |
custom_css = """
|
| 136 |
-
/* 1.
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
overflow-x: auto !important;
|
| 139 |
-
|
|
|
|
| 140 |
}
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
border-collapse: collapse !important;
|
| 147 |
margin: 0 !important;
|
| 148 |
}
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
display: table-cell !important;
|
| 152 |
-
white-space: normal !important;
|
| 153 |
-
|
| 154 |
-
|
| 155 |
|
|
|
|
| 156 |
box-sizing: border-box !important;
|
| 157 |
-
padding: 8px
|
| 158 |
border: 1px solid #444 !important;
|
| 159 |
-
font-size:
|
| 160 |
line-height: 1.4 !important;
|
| 161 |
}
|
| 162 |
-
|
| 163 |
-
/*
|
| 164 |
-
th:nth-child(1), td:nth-child(1) {
|
| 165 |
-
|
| 166 |
-
th:nth-child(
|
| 167 |
-
|
| 168 |
-
th:nth-child(
|
| 169 |
-
|
| 170 |
-
th:nth-child(
|
| 171 |
-
|
| 172 |
-
th:nth-child(
|
| 173 |
-
|
| 174 |
-
th:nth-child(6), td:nth-child(6) { min-width: 250px !important; width: 250px !important; }
|
| 175 |
-
/* #7 pax: 人數 (短) */
|
| 176 |
-
th:nth-child(7), td:nth-child(7) { min-width: 50px !important; width: 50px !important; }
|
| 177 |
-
/* #8 remarks: 備註 (文字多,給寬一點) */
|
| 178 |
-
th:nth-child(8), td:nth-child(8) { min-width: 180px !important; width: 180px !important; }
|
| 179 |
-
/* #9 status: 狀態 */
|
| 180 |
-
th:nth-child(9), td:nth-child(9) { min-width: 120px !important; width: 120px !important; }
|
| 181 |
-
/* #10 user_id: 亂碼 (非常長,給寬一點,反正會換行) */
|
| 182 |
-
th:nth-child(10), td:nth-child(10) { min-width: 280px !important; width: 320px !important; }
|
| 183 |
"""
|
| 184 |
|
| 185 |
-
# --- 介面開始
|
| 186 |
with gr.Blocks(title="Admin", css=custom_css) as demo:
|
| 187 |
|
| 188 |
# 1. 登入介面
|
|
@@ -198,8 +206,10 @@ with gr.Blocks(title="Admin", css=custom_css) as demo:
|
|
| 198 |
with gr.Group(visible=False) as admin_row:
|
| 199 |
gr.Markdown("# 🍷 訂位管理後台 (Dashboard)")
|
| 200 |
refresh_btn = gr.Button("🔄 重新整理")
|
| 201 |
-
|
| 202 |
-
booking_table
|
|
|
|
|
|
|
| 203 |
with gr.Row():
|
| 204 |
id_input = gr.Number(label="訂單 ID", precision=0)
|
| 205 |
action_btn = gr.Button("📧 發送確認信 (Hybrid)", variant="primary")
|
|
|
|
| 131 |
error_msg: "<span style='color: red'>❌ 帳號或密碼錯誤</span>"
|
| 132 |
}
|
| 133 |
|
| 134 |
+
# --- 🔥 [絕對定寬 + 單一捲軸 CSS] 🔥 ---
|
| 135 |
custom_css = """
|
| 136 |
+
/* 1. 殺掉外層捲軸:Gradio 的 Dataframe 外層預設會有 .wrap 導致雙重捲軸 */
|
| 137 |
+
#booking_table .wrap {
|
| 138 |
+
overflow: hidden !important;
|
| 139 |
+
border: none !important;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
/* 2. 保留內層捲軸:只允許這一層捲動 */
|
| 143 |
+
#booking_table .table-wrap,
|
| 144 |
+
#booking_table div[class*="table"] {
|
| 145 |
overflow-x: auto !important;
|
| 146 |
+
overflow-y: hidden !important;
|
| 147 |
+
border: 1px solid #444 !important;
|
| 148 |
}
|
| 149 |
+
|
| 150 |
+
/* 3. 表格設定:
|
| 151 |
+
width: 1500px -> 【關鍵】設定一個大於所有欄位總和的寬度 (60+170+80+120+120+250+50+180+120+320 = 1470px)
|
| 152 |
+
table-layout: fixed -> 強制依照下方設定的寬度渲染,不讓瀏覽器壓縮
|
| 153 |
+
*/
|
| 154 |
+
#booking_table table {
|
| 155 |
+
table-layout: fixed !important;
|
| 156 |
+
width: 1500px !important;
|
| 157 |
+
min-width: 1500px !important;
|
| 158 |
border-collapse: collapse !important;
|
| 159 |
margin: 0 !important;
|
| 160 |
}
|
| 161 |
+
|
| 162 |
+
/* 4. 通用欄位設定:
|
| 163 |
+
white-space: normal -> 【關鍵】允許換行
|
| 164 |
+
word-break: break-all -> 強制長單字(如User ID)換行
|
| 165 |
+
*/
|
| 166 |
+
#booking_table th, #booking_table td {
|
| 167 |
display: table-cell !important;
|
| 168 |
+
white-space: normal !important;
|
| 169 |
+
overflow-wrap: break-word !important;
|
| 170 |
+
word-break: break-all !important;
|
| 171 |
|
| 172 |
+
vertical-align: top !important;
|
| 173 |
box-sizing: border-box !important;
|
| 174 |
+
padding: 8px 5px !important;
|
| 175 |
border: 1px solid #444 !important;
|
| 176 |
+
font-size: 13px !important;
|
| 177 |
line-height: 1.4 !important;
|
| 178 |
}
|
| 179 |
+
|
| 180 |
+
/* 5. 🔥【絕對欄位寬度】(依照您的指定) */
|
| 181 |
+
#booking_table th:nth-child(1), #booking_table td:nth-child(1) { width: 60px !important; }
|
| 182 |
+
#booking_table th:nth-child(2), #booking_table td:nth-child(2) { width: 170px !important; }
|
| 183 |
+
#booking_table th:nth-child(3), #booking_table td:nth-child(3) { width: 80px !important; }
|
| 184 |
+
#booking_table th:nth-child(4), #booking_table td:nth-child(4) { width: 120px !important; }
|
| 185 |
+
#booking_table th:nth-child(5), #booking_table td:nth-child(5) { width: 120px !important; }
|
| 186 |
+
#booking_table th:nth-child(6), #booking_table td:nth-child(6) { width: 250px !important; }
|
| 187 |
+
#booking_table th:nth-child(7), #booking_table td:nth-child(7) { width: 50px !important; }
|
| 188 |
+
#booking_table th:nth-child(8), #booking_table td:nth-child(8) { width: 180px !important; }
|
| 189 |
+
#booking_table th:nth-child(9), #booking_table td:nth-child(9) { width: 120px !important; }
|
| 190 |
+
#booking_table th:nth-child(10), #booking_table td:nth-child(10) { width: 320px !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
"""
|
| 192 |
|
| 193 |
+
# --- 介面開始 ---
|
| 194 |
with gr.Blocks(title="Admin", css=custom_css) as demo:
|
| 195 |
|
| 196 |
# 1. 登入介面
|
|
|
|
| 206 |
with gr.Group(visible=False) as admin_row:
|
| 207 |
gr.Markdown("# 🍷 訂位管理後台 (Dashboard)")
|
| 208 |
refresh_btn = gr.Button("🔄 重新整理")
|
| 209 |
+
|
| 210 |
+
# ✅ elem_id 保持為 booking_table,這是 CSS 抓取的關鍵
|
| 211 |
+
booking_table = gr.Dataframe(interactive=False, elem_id="booking_table")
|
| 212 |
+
|
| 213 |
with gr.Row():
|
| 214 |
id_input = gr.Number(label="訂單 ID", precision=0)
|
| 215 |
action_btn = gr.Button("📧 發送確認信 (Hybrid)", variant="primary")
|