Spaces:
Sleeping
Sleeping
ichieh commited on
Commit ·
63a8f38
1
Parent(s): aa381d8
Update page title and add Facebook event link
Browse files
.history/templates/index_20250117181206.html
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="zh-TW">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>活動座位選擇</title>
|
| 7 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 8 |
+
<link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.0/dist/sweetalert2.min.css" rel="stylesheet">
|
| 9 |
+
<style>
|
| 10 |
+
.main-container {
|
| 11 |
+
display: flex;
|
| 12 |
+
justify-content: space-between;
|
| 13 |
+
padding: 20px;
|
| 14 |
+
gap: 20px;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
.tables-section {
|
| 18 |
+
flex: 2;
|
| 19 |
+
display: flex;
|
| 20 |
+
flex-wrap: wrap;
|
| 21 |
+
gap: 20px;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.registration-section {
|
| 25 |
+
flex: 1;
|
| 26 |
+
min-width: 300px;
|
| 27 |
+
max-width: 400px;
|
| 28 |
+
padding: 20px;
|
| 29 |
+
background-color: #f8f9fa;
|
| 30 |
+
border-radius: 8px;
|
| 31 |
+
position: sticky;
|
| 32 |
+
top: 20px;
|
| 33 |
+
height: fit-content;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.table-circle {
|
| 37 |
+
width: 180px;
|
| 38 |
+
height: 180px;
|
| 39 |
+
border-radius: 50%;
|
| 40 |
+
border: 2px solid #ddd;
|
| 41 |
+
display: flex;
|
| 42 |
+
flex-direction: column;
|
| 43 |
+
align-items: center;
|
| 44 |
+
justify-content: center;
|
| 45 |
+
cursor: pointer;
|
| 46 |
+
transition: all 0.3s ease;
|
| 47 |
+
background-color: white;
|
| 48 |
+
margin: 15px;
|
| 49 |
+
position: relative;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.table-circle:hover {
|
| 53 |
+
border-color: #007bff;
|
| 54 |
+
background-color: #f8f9fa;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.table-circle.selected {
|
| 58 |
+
border-color: #007bff;
|
| 59 |
+
background-color: #e7f1ff;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
.table-circle.full {
|
| 63 |
+
cursor: not-allowed;
|
| 64 |
+
opacity: 0.7;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.table-name {
|
| 68 |
+
font-size: 1.5rem;
|
| 69 |
+
font-weight: bold;
|
| 70 |
+
margin-bottom: 5px;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.seats-info {
|
| 74 |
+
font-size: 1rem;
|
| 75 |
+
color: #666;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.table-leader {
|
| 79 |
+
background-color: #28a745;
|
| 80 |
+
color: white;
|
| 81 |
+
padding: 2px 8px;
|
| 82 |
+
border-radius: 4px;
|
| 83 |
+
margin-bottom: 4px;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.participant {
|
| 87 |
+
padding: 2px 8px;
|
| 88 |
+
margin-bottom: 2px;
|
| 89 |
+
border-radius: 4px;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
.table-container {
|
| 93 |
+
display: inline-block;
|
| 94 |
+
margin: 15px;
|
| 95 |
+
text-align: center;
|
| 96 |
+
}
|
| 97 |
+
</style>
|
| 98 |
+
</head>
|
| 99 |
+
<body>
|
| 100 |
+
<div class="container">
|
| 101 |
+
<h1 class="text-center my-4">活動座位選擇</h1>
|
| 102 |
+
|
| 103 |
+
<div class="main-container">
|
| 104 |
+
<div class="tables-section" id="tables">
|
| 105 |
+
<!-- 桌子將由 JavaScript 動態生成 -->
|
| 106 |
+
</div>
|
| 107 |
+
|
| 108 |
+
<div class="registration-section">
|
| 109 |
+
<h4 class="mb-3">登記資料</h4>
|
| 110 |
+
<div class="mb-3">
|
| 111 |
+
<label for="nickname" class="form-label">暱稱 <span class="text-danger">*</span></label>
|
| 112 |
+
<input type="text" class="form-control" id="nickname" required>
|
| 113 |
+
</div>
|
| 114 |
+
<div class="mb-3">
|
| 115 |
+
<label for="email" class="form-label">Email <span class="text-danger">*</span></label>
|
| 116 |
+
<input type="email" class="form-control" id="email" required>
|
| 117 |
+
</div>
|
| 118 |
+
<div class="mb-3">
|
| 119 |
+
<label for="fb_link" class="form-label">FB個人連結 <small class="text-muted">(選填)</small></label>
|
| 120 |
+
<input type="url" class="form-control" id="fb_link">
|
| 121 |
+
</div>
|
| 122 |
+
<div class="mb-3">
|
| 123 |
+
<label for="introduction" class="form-label">自我介紹 <small class="text-muted">(選填,300字元內)</small></label>
|
| 124 |
+
<textarea class="form-control" id="introduction" rows="3" maxlength="300"></textarea>
|
| 125 |
+
<div class="form-text text-end"><span id="charCount">0</span>/300</div>
|
| 126 |
+
</div>
|
| 127 |
+
<button class="btn btn-primary w-100" id="confirmBtn" disabled onclick="submitRegistration()">
|
| 128 |
+
確認選位
|
| 129 |
+
</button>
|
| 130 |
+
</div>
|
| 131 |
+
</div>
|
| 132 |
+
</div>
|
| 133 |
+
|
| 134 |
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
| 135 |
+
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.0/dist/sweetalert2.all.min.js"></script>
|
| 136 |
+
<script>
|
| 137 |
+
let selectedTableId = null;
|
| 138 |
+
|
| 139 |
+
function selectTable(tableId) {
|
| 140 |
+
if (!tableId) return;
|
| 141 |
+
|
| 142 |
+
// 移除之前選擇的桌子的選中狀態
|
| 143 |
+
const previousSelected = document.querySelector('.table-circle.selected');
|
| 144 |
+
if (previousSelected) {
|
| 145 |
+
previousSelected.classList.remove('selected');
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// 設置新選擇的桌子
|
| 149 |
+
const selectedTable = document.querySelector(`.table-circle[data-table-id="${tableId}"]`);
|
| 150 |
+
if (selectedTable) {
|
| 151 |
+
selectedTable.classList.add('selected');
|
| 152 |
+
// 啟用確認按鈕
|
| 153 |
+
document.getElementById('confirmBtn').disabled = false;
|
| 154 |
+
// 儲存選擇的桌號
|
| 155 |
+
selectedTableId = tableId;
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
async function loadTables() {
|
| 160 |
+
try {
|
| 161 |
+
const response = await fetch('/api/tables');
|
| 162 |
+
const tables = await response.json();
|
| 163 |
+
|
| 164 |
+
const tablesContainer = document.getElementById('tables');
|
| 165 |
+
tablesContainer.innerHTML = '';
|
| 166 |
+
|
| 167 |
+
tables.forEach(table => {
|
| 168 |
+
const tableElement = document.createElement('div');
|
| 169 |
+
tableElement.className = 'table-container';
|
| 170 |
+
|
| 171 |
+
// 計算已坐人數
|
| 172 |
+
const participantsCount = table.participants.length;
|
| 173 |
+
const isFull = participantsCount >= table.capacity;
|
| 174 |
+
|
| 175 |
+
// 創建桌次元素
|
| 176 |
+
const circle = document.createElement('div');
|
| 177 |
+
circle.className = `table-circle${isFull ? ' full' : ''}`;
|
| 178 |
+
circle.setAttribute('data-table-id', table.id);
|
| 179 |
+
circle.onclick = isFull ? null : () => selectTable(table.id);
|
| 180 |
+
|
| 181 |
+
// 桌次名稱
|
| 182 |
+
const tableName = document.createElement('div');
|
| 183 |
+
tableName.className = 'table-name';
|
| 184 |
+
tableName.textContent = table.name;
|
| 185 |
+
|
| 186 |
+
// 座位資訊
|
| 187 |
+
const seatsInfo = document.createElement('div');
|
| 188 |
+
seatsInfo.className = 'seats-info';
|
| 189 |
+
seatsInfo.textContent = `${participantsCount}/${table.capacity} 個座位`;
|
| 190 |
+
|
| 191 |
+
// 參與者列表
|
| 192 |
+
const participantsList = document.createElement('div');
|
| 193 |
+
participantsList.className = 'participants-list';
|
| 194 |
+
|
| 195 |
+
// 先顯示桌長(如果有)
|
| 196 |
+
table.participants.forEach(participant => {
|
| 197 |
+
const participantDiv = document.createElement('div');
|
| 198 |
+
if (participant.is_table_leader) {
|
| 199 |
+
participantDiv.className = 'table-leader';
|
| 200 |
+
participantDiv.textContent = `桌長:${participant.nickname}`;
|
| 201 |
+
} else {
|
| 202 |
+
participantDiv.className = 'participant';
|
| 203 |
+
participantDiv.textContent = participant.nickname;
|
| 204 |
+
}
|
| 205 |
+
participantsList.appendChild(participantDiv);
|
| 206 |
+
});
|
| 207 |
+
|
| 208 |
+
circle.appendChild(tableName);
|
| 209 |
+
circle.appendChild(seatsInfo);
|
| 210 |
+
circle.appendChild(participantsList);
|
| 211 |
+
tableElement.appendChild(circle);
|
| 212 |
+
tablesContainer.appendChild(tableElement);
|
| 213 |
+
});
|
| 214 |
+
} catch (error) {
|
| 215 |
+
console.error('Error:', error);
|
| 216 |
+
Swal.fire('錯誤', '載入桌次資料失敗', 'error');
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
// 初始化頁面
|
| 221 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 222 |
+
loadTables();
|
| 223 |
+
});
|
| 224 |
+
|
| 225 |
+
// 字數計數器
|
| 226 |
+
document.getElementById('introduction').addEventListener('input', function() {
|
| 227 |
+
const currentLength = this.value.length;
|
| 228 |
+
document.getElementById('charCount').textContent = currentLength;
|
| 229 |
+
});
|
| 230 |
+
|
| 231 |
+
async function submitRegistration() {
|
| 232 |
+
// 檢查是否已選擇座位
|
| 233 |
+
if (!selectedTableId) {
|
| 234 |
+
Swal.fire({
|
| 235 |
+
icon: 'error',
|
| 236 |
+
title: '無法報名',
|
| 237 |
+
text: '請先選擇座位',
|
| 238 |
+
confirmButtonText: '確定'
|
| 239 |
+
});
|
| 240 |
+
return;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
const nickname = document.getElementById('nickname').value.trim();
|
| 244 |
+
const email = document.getElementById('email').value.trim();
|
| 245 |
+
const fb_link = document.getElementById('fb_link').value.trim();
|
| 246 |
+
const introduction = document.getElementById('introduction').value.trim();
|
| 247 |
+
|
| 248 |
+
// 檢查必填欄位
|
| 249 |
+
if (!nickname || !email) {
|
| 250 |
+
Swal.fire({
|
| 251 |
+
icon: 'error',
|
| 252 |
+
title: '無法報名',
|
| 253 |
+
text: '請填寫必要欄位(暱稱和Email)',
|
| 254 |
+
confirmButtonText: '確定'
|
| 255 |
+
});
|
| 256 |
+
return;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
// 禁用提交按鈕,避免重複送出
|
| 260 |
+
const confirmBtn = document.getElementById('confirmBtn');
|
| 261 |
+
confirmBtn.disabled = true;
|
| 262 |
+
|
| 263 |
+
// 顯示等待畫面
|
| 264 |
+
const loadingSwal = Swal.fire({
|
| 265 |
+
title: '處理中...',
|
| 266 |
+
text: '正在為您報名,請稍候',
|
| 267 |
+
allowOutsideClick: false,
|
| 268 |
+
allowEscapeKey: false,
|
| 269 |
+
allowEnterKey: false,
|
| 270 |
+
showConfirmButton: false,
|
| 271 |
+
didOpen: () => {
|
| 272 |
+
Swal.showLoading();
|
| 273 |
+
}
|
| 274 |
+
});
|
| 275 |
+
|
| 276 |
+
try {
|
| 277 |
+
const response = await fetch('/api/register', {
|
| 278 |
+
method: 'POST',
|
| 279 |
+
headers: {
|
| 280 |
+
'Content-Type': 'application/json',
|
| 281 |
+
},
|
| 282 |
+
body: JSON.stringify({
|
| 283 |
+
nickname,
|
| 284 |
+
email,
|
| 285 |
+
fb_link,
|
| 286 |
+
introduction,
|
| 287 |
+
table_id: selectedTableId
|
| 288 |
+
})
|
| 289 |
+
});
|
| 290 |
+
|
| 291 |
+
const result = await response.json();
|
| 292 |
+
|
| 293 |
+
// 關閉等待畫面
|
| 294 |
+
await loadingSwal.close();
|
| 295 |
+
|
| 296 |
+
if (response.ok) {
|
| 297 |
+
await Swal.fire({
|
| 298 |
+
icon: 'success',
|
| 299 |
+
title: '報名成功',
|
| 300 |
+
text: result.message || '您已成功報名座位',
|
| 301 |
+
confirmButtonText: '確定'
|
| 302 |
+
});
|
| 303 |
+
|
| 304 |
+
// 清除表單
|
| 305 |
+
document.getElementById('nickname').value = '';
|
| 306 |
+
document.getElementById('email').value = '';
|
| 307 |
+
document.getElementById('fb_link').value = '';
|
| 308 |
+
document.getElementById('introduction').value = '';
|
| 309 |
+
document.getElementById('charCount').textContent = '0';
|
| 310 |
+
|
| 311 |
+
// 清除選擇的桌號
|
| 312 |
+
selectedTableId = null;
|
| 313 |
+
|
| 314 |
+
// 重新載入桌次資料
|
| 315 |
+
await loadTables();
|
| 316 |
+
} else {
|
| 317 |
+
Swal.fire({
|
| 318 |
+
icon: 'error',
|
| 319 |
+
title: '報名失敗',
|
| 320 |
+
text: result.error || '該座位可能已被其他人選走,請重新選擇',
|
| 321 |
+
confirmButtonText: '確定'
|
| 322 |
+
});
|
| 323 |
+
// 重新載入桌次資料以顯示最新狀態
|
| 324 |
+
await loadTables();
|
| 325 |
+
}
|
| 326 |
+
} catch (error) {
|
| 327 |
+
// 關閉等待畫面
|
| 328 |
+
await loadingSwal.close();
|
| 329 |
+
|
| 330 |
+
console.error('Error:', error);
|
| 331 |
+
Swal.fire({
|
| 332 |
+
icon: 'error',
|
| 333 |
+
title: '報名失敗',
|
| 334 |
+
text: '系統發生錯誤,請稍後再試',
|
| 335 |
+
confirmButtonText: '確定'
|
| 336 |
+
});
|
| 337 |
+
// 重新載入桌次資料以顯示最新狀態
|
| 338 |
+
await loadTables();
|
| 339 |
+
} finally {
|
| 340 |
+
// 無論成功或失敗,都重新啟用提交按鈕
|
| 341 |
+
confirmBtn.disabled = false;
|
| 342 |
+
}
|
| 343 |
+
}
|
| 344 |
+
</script>
|
| 345 |
+
</body>
|
| 346 |
+
</html>
|
.history/templates/index_20250117194613.html
ADDED
|
@@ -0,0 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="zh-TW">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>蛇來蛇去 - 辦桌春酒大亂鬥暨天公生慶生祝願</title>
|
| 7 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 8 |
+
<link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.0/dist/sweetalert2.min.css" rel="stylesheet">
|
| 9 |
+
<style>
|
| 10 |
+
.main-container {
|
| 11 |
+
display: flex;
|
| 12 |
+
justify-content: space-between;
|
| 13 |
+
padding: 20px;
|
| 14 |
+
gap: 20px;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
.tables-section {
|
| 18 |
+
flex: 2;
|
| 19 |
+
display: flex;
|
| 20 |
+
flex-wrap: wrap;
|
| 21 |
+
gap: 20px;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.registration-section {
|
| 25 |
+
flex: 1;
|
| 26 |
+
min-width: 300px;
|
| 27 |
+
max-width: 400px;
|
| 28 |
+
padding: 20px;
|
| 29 |
+
background-color: #f8f9fa;
|
| 30 |
+
border-radius: 8px;
|
| 31 |
+
position: sticky;
|
| 32 |
+
top: 20px;
|
| 33 |
+
height: fit-content;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.table-circle {
|
| 37 |
+
width: 180px;
|
| 38 |
+
height: 180px;
|
| 39 |
+
border-radius: 50%;
|
| 40 |
+
border: 2px solid #ddd;
|
| 41 |
+
display: flex;
|
| 42 |
+
flex-direction: column;
|
| 43 |
+
align-items: center;
|
| 44 |
+
justify-content: center;
|
| 45 |
+
cursor: pointer;
|
| 46 |
+
transition: all 0.3s ease;
|
| 47 |
+
background-color: white;
|
| 48 |
+
margin: 15px;
|
| 49 |
+
position: relative;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.table-circle:hover {
|
| 53 |
+
border-color: #007bff;
|
| 54 |
+
background-color: #f8f9fa;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.table-circle.selected {
|
| 58 |
+
border-color: #007bff;
|
| 59 |
+
background-color: #e7f1ff;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
.table-circle.full {
|
| 63 |
+
cursor: not-allowed;
|
| 64 |
+
opacity: 0.7;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.table-name {
|
| 68 |
+
font-size: 1.5rem;
|
| 69 |
+
font-weight: bold;
|
| 70 |
+
margin-bottom: 5px;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.seats-info {
|
| 74 |
+
font-size: 1rem;
|
| 75 |
+
color: #666;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.table-leader {
|
| 79 |
+
background-color: #28a745;
|
| 80 |
+
color: white;
|
| 81 |
+
padding: 2px 8px;
|
| 82 |
+
border-radius: 4px;
|
| 83 |
+
margin-bottom: 4px;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.participant {
|
| 87 |
+
padding: 2px 8px;
|
| 88 |
+
margin-bottom: 2px;
|
| 89 |
+
border-radius: 4px;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
.table-container {
|
| 93 |
+
display: inline-block;
|
| 94 |
+
margin: 15px;
|
| 95 |
+
text-align: center;
|
| 96 |
+
}
|
| 97 |
+
</style>
|
| 98 |
+
</head>
|
| 99 |
+
<body>
|
| 100 |
+
<div class="container">
|
| 101 |
+
<h1 class="text-center my-4">活動座位選擇</h1>
|
| 102 |
+
|
| 103 |
+
<div class="main-container">
|
| 104 |
+
<div class="tables-section" id="tables">
|
| 105 |
+
<!-- 桌子將由 JavaScript 動態生成 -->
|
| 106 |
+
</div>
|
| 107 |
+
|
| 108 |
+
<div class="registration-section">
|
| 109 |
+
<h4 class="mb-3">登記資料</h4>
|
| 110 |
+
<div class="mb-3">
|
| 111 |
+
<label for="nickname" class="form-label">暱稱 <span class="text-danger">*</span></label>
|
| 112 |
+
<input type="text" class="form-control" id="nickname" required>
|
| 113 |
+
</div>
|
| 114 |
+
<div class="mb-3">
|
| 115 |
+
<label for="email" class="form-label">Email <span class="text-danger">*</span></label>
|
| 116 |
+
<input type="email" class="form-control" id="email" required>
|
| 117 |
+
</div>
|
| 118 |
+
<div class="mb-3">
|
| 119 |
+
<label for="fb_link" class="form-label">FB個人連結 <small class="text-muted">(選填)</small></label>
|
| 120 |
+
<input type="url" class="form-control" id="fb_link">
|
| 121 |
+
</div>
|
| 122 |
+
<div class="mb-3">
|
| 123 |
+
<label for="introduction" class="form-label">自我介紹 <small class="text-muted">(選填,300字元內)</small></label>
|
| 124 |
+
<textarea class="form-control" id="introduction" rows="3" maxlength="300"></textarea>
|
| 125 |
+
<div class="form-text text-end"><span id="charCount">0</span>/300</div>
|
| 126 |
+
</div>
|
| 127 |
+
<button class="btn btn-primary w-100" id="confirmBtn" disabled onclick="submitRegistration()">
|
| 128 |
+
確認選位
|
| 129 |
+
</button>
|
| 130 |
+
</div>
|
| 131 |
+
</div>
|
| 132 |
+
</div>
|
| 133 |
+
|
| 134 |
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
| 135 |
+
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.0/dist/sweetalert2.all.min.js"></script>
|
| 136 |
+
<script>
|
| 137 |
+
let selectedTableId = null;
|
| 138 |
+
|
| 139 |
+
function selectTable(tableId) {
|
| 140 |
+
if (!tableId) return;
|
| 141 |
+
|
| 142 |
+
// 移除之前選擇的桌子的選中狀態
|
| 143 |
+
const previousSelected = document.querySelector('.table-circle.selected');
|
| 144 |
+
if (previousSelected) {
|
| 145 |
+
previousSelected.classList.remove('selected');
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// 設置新選擇的桌子
|
| 149 |
+
const selectedTable = document.querySelector(`.table-circle[data-table-id="${tableId}"]`);
|
| 150 |
+
if (selectedTable) {
|
| 151 |
+
selectedTable.classList.add('selected');
|
| 152 |
+
// 啟用確認按鈕
|
| 153 |
+
document.getElementById('confirmBtn').disabled = false;
|
| 154 |
+
// 儲存選擇的桌號
|
| 155 |
+
selectedTableId = tableId;
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
async function loadTables() {
|
| 160 |
+
try {
|
| 161 |
+
const response = await fetch('/api/tables');
|
| 162 |
+
const tables = await response.json();
|
| 163 |
+
|
| 164 |
+
const tablesContainer = document.getElementById('tables');
|
| 165 |
+
tablesContainer.innerHTML = '';
|
| 166 |
+
|
| 167 |
+
tables.forEach(table => {
|
| 168 |
+
const tableElement = document.createElement('div');
|
| 169 |
+
tableElement.className = 'table-container';
|
| 170 |
+
|
| 171 |
+
// 計算已坐人數
|
| 172 |
+
const participantsCount = table.participants.length;
|
| 173 |
+
const isFull = participantsCount >= table.capacity;
|
| 174 |
+
|
| 175 |
+
// 創建桌次元素
|
| 176 |
+
const circle = document.createElement('div');
|
| 177 |
+
circle.className = `table-circle${isFull ? ' full' : ''}`;
|
| 178 |
+
circle.setAttribute('data-table-id', table.id);
|
| 179 |
+
circle.onclick = isFull ? null : () => selectTable(table.id);
|
| 180 |
+
|
| 181 |
+
// 桌次名稱
|
| 182 |
+
const tableName = document.createElement('div');
|
| 183 |
+
tableName.className = 'table-name';
|
| 184 |
+
tableName.textContent = table.name;
|
| 185 |
+
|
| 186 |
+
// 座位資訊
|
| 187 |
+
const seatsInfo = document.createElement('div');
|
| 188 |
+
seatsInfo.className = 'seats-info';
|
| 189 |
+
seatsInfo.textContent = `${participantsCount}/${table.capacity} 個座位`;
|
| 190 |
+
|
| 191 |
+
// 參與者列表
|
| 192 |
+
const participantsList = document.createElement('div');
|
| 193 |
+
participantsList.className = 'participants-list';
|
| 194 |
+
|
| 195 |
+
// 先顯示桌長(如果有)
|
| 196 |
+
table.participants.forEach(participant => {
|
| 197 |
+
const participantDiv = document.createElement('div');
|
| 198 |
+
if (participant.is_table_leader) {
|
| 199 |
+
participantDiv.className = 'table-leader';
|
| 200 |
+
participantDiv.textContent = `桌長:${participant.nickname}`;
|
| 201 |
+
} else {
|
| 202 |
+
participantDiv.className = 'participant';
|
| 203 |
+
participantDiv.textContent = participant.nickname;
|
| 204 |
+
}
|
| 205 |
+
participantsList.appendChild(participantDiv);
|
| 206 |
+
});
|
| 207 |
+
|
| 208 |
+
circle.appendChild(tableName);
|
| 209 |
+
circle.appendChild(seatsInfo);
|
| 210 |
+
circle.appendChild(participantsList);
|
| 211 |
+
tableElement.appendChild(circle);
|
| 212 |
+
tablesContainer.appendChild(tableElement);
|
| 213 |
+
});
|
| 214 |
+
} catch (error) {
|
| 215 |
+
console.error('Error:', error);
|
| 216 |
+
Swal.fire('錯誤', '載入桌次資料失敗', 'error');
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
// 初始化頁面
|
| 221 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 222 |
+
loadTables();
|
| 223 |
+
});
|
| 224 |
+
|
| 225 |
+
// 字數計數器
|
| 226 |
+
document.getElementById('introduction').addEventListener('input', function() {
|
| 227 |
+
const currentLength = this.value.length;
|
| 228 |
+
document.getElementById('charCount').textContent = currentLength;
|
| 229 |
+
});
|
| 230 |
+
|
| 231 |
+
async function submitRegistration() {
|
| 232 |
+
// 檢查是否已選擇座位
|
| 233 |
+
if (!selectedTableId) {
|
| 234 |
+
Swal.fire({
|
| 235 |
+
icon: 'error',
|
| 236 |
+
title: '無法報名',
|
| 237 |
+
text: '請先選擇座位',
|
| 238 |
+
confirmButtonText: '確定'
|
| 239 |
+
});
|
| 240 |
+
return;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
const nickname = document.getElementById('nickname').value.trim();
|
| 244 |
+
const email = document.getElementById('email').value.trim();
|
| 245 |
+
const fb_link = document.getElementById('fb_link').value.trim();
|
| 246 |
+
const introduction = document.getElementById('introduction').value.trim();
|
| 247 |
+
|
| 248 |
+
// 檢查必填欄位
|
| 249 |
+
if (!nickname || !email) {
|
| 250 |
+
Swal.fire({
|
| 251 |
+
icon: 'error',
|
| 252 |
+
title: '無法報名',
|
| 253 |
+
text: '請填寫必要欄位(暱稱和Email)',
|
| 254 |
+
confirmButtonText: '確定'
|
| 255 |
+
});
|
| 256 |
+
return;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
// 禁用提交按鈕,避免重複送出
|
| 260 |
+
const confirmBtn = document.getElementById('confirmBtn');
|
| 261 |
+
confirmBtn.disabled = true;
|
| 262 |
+
|
| 263 |
+
// 顯示等待畫面
|
| 264 |
+
const loadingSwal = Swal.fire({
|
| 265 |
+
title: '處理中...',
|
| 266 |
+
text: '正在為您報名,請稍候',
|
| 267 |
+
allowOutsideClick: false,
|
| 268 |
+
allowEscapeKey: false,
|
| 269 |
+
allowEnterKey: false,
|
| 270 |
+
showConfirmButton: false,
|
| 271 |
+
didOpen: () => {
|
| 272 |
+
Swal.showLoading();
|
| 273 |
+
}
|
| 274 |
+
});
|
| 275 |
+
|
| 276 |
+
try {
|
| 277 |
+
const response = await fetch('/api/register', {
|
| 278 |
+
method: 'POST',
|
| 279 |
+
headers: {
|
| 280 |
+
'Content-Type': 'application/json',
|
| 281 |
+
},
|
| 282 |
+
body: JSON.stringify({
|
| 283 |
+
nickname,
|
| 284 |
+
email,
|
| 285 |
+
fb_link,
|
| 286 |
+
introduction,
|
| 287 |
+
table_id: selectedTableId
|
| 288 |
+
})
|
| 289 |
+
});
|
| 290 |
+
|
| 291 |
+
const result = await response.json();
|
| 292 |
+
|
| 293 |
+
// 關閉等待畫面
|
| 294 |
+
await loadingSwal.close();
|
| 295 |
+
|
| 296 |
+
if (response.ok) {
|
| 297 |
+
await Swal.fire({
|
| 298 |
+
icon: 'success',
|
| 299 |
+
title: '報名成功',
|
| 300 |
+
text: result.message || '您已成功報名座位',
|
| 301 |
+
confirmButtonText: '確定'
|
| 302 |
+
});
|
| 303 |
+
|
| 304 |
+
// 清除表單
|
| 305 |
+
document.getElementById('nickname').value = '';
|
| 306 |
+
document.getElementById('email').value = '';
|
| 307 |
+
document.getElementById('fb_link').value = '';
|
| 308 |
+
document.getElementById('introduction').value = '';
|
| 309 |
+
document.getElementById('charCount').textContent = '0';
|
| 310 |
+
|
| 311 |
+
// 清除選擇的桌號
|
| 312 |
+
selectedTableId = null;
|
| 313 |
+
|
| 314 |
+
// 重新載入桌次資料
|
| 315 |
+
await loadTables();
|
| 316 |
+
} else {
|
| 317 |
+
Swal.fire({
|
| 318 |
+
icon: 'error',
|
| 319 |
+
title: '報名失敗',
|
| 320 |
+
text: result.error || '該座位可能已被其他人選走,請重新選擇',
|
| 321 |
+
confirmButtonText: '確定'
|
| 322 |
+
});
|
| 323 |
+
// 重新載入桌次資料以顯示最新狀態
|
| 324 |
+
await loadTables();
|
| 325 |
+
}
|
| 326 |
+
} catch (error) {
|
| 327 |
+
// 關閉等待畫面
|
| 328 |
+
await loadingSwal.close();
|
| 329 |
+
|
| 330 |
+
console.error('Error:', error);
|
| 331 |
+
Swal.fire({
|
| 332 |
+
icon: 'error',
|
| 333 |
+
title: '報名失敗',
|
| 334 |
+
text: '系統發生錯誤,請稍後再試',
|
| 335 |
+
confirmButtonText: '確定'
|
| 336 |
+
});
|
| 337 |
+
// 重新載入桌次資料以顯示最新狀態
|
| 338 |
+
await loadTables();
|
| 339 |
+
} finally {
|
| 340 |
+
// 無論成功或失敗,都重新啟用提交按鈕
|
| 341 |
+
confirmBtn.disabled = false;
|
| 342 |
+
}
|
| 343 |
+
}
|
| 344 |
+
</script>
|
| 345 |
+
</body>
|
| 346 |
+
</html>
|
templates/index.html
CHANGED
|
@@ -3,9 +3,10 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>
|
| 7 |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 8 |
<link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.0/dist/sweetalert2.min.css" rel="stylesheet">
|
|
|
|
| 9 |
<style>
|
| 10 |
.main-container {
|
| 11 |
display: flex;
|
|
@@ -98,7 +99,11 @@
|
|
| 98 |
</head>
|
| 99 |
<body>
|
| 100 |
<div class="container">
|
| 101 |
-
<h1 class="text-center my-4">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
<div class="main-container">
|
| 104 |
<div class="tables-section" id="tables">
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>蛇來蛇去 - 辦桌春酒大亂鬥暨天公生慶生祝願</title>
|
| 7 |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 8 |
<link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.0/dist/sweetalert2.min.css" rel="stylesheet">
|
| 9 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css">
|
| 10 |
<style>
|
| 11 |
.main-container {
|
| 12 |
display: flex;
|
|
|
|
| 99 |
</head>
|
| 100 |
<body>
|
| 101 |
<div class="container">
|
| 102 |
+
<h1 class="text-center my-4">蛇來蛇去 - 辦桌春酒大亂鬥暨天公生慶生祝願
|
| 103 |
+
<a href="https://fb.me/1LHAts3TlfxyvhM" target="_blank" class="btn btn-outline-primary btn-sm">
|
| 104 |
+
<i class="bi bi-facebook"></i> 活動詳情
|
| 105 |
+
</a>
|
| 106 |
+
</h1>
|
| 107 |
|
| 108 |
<div class="main-container">
|
| 109 |
<div class="tables-section" id="tables">
|