ichieh commited on
Commit
66f25db
·
1 Parent(s): 93359ec

修改index api

Browse files
Files changed (1) hide show
  1. templates/index.html +8 -4
templates/index.html CHANGED
@@ -147,7 +147,11 @@
147
  async function loadTables() {
148
  try {
149
  const response = await fetch('/api/tables');
150
- const tables = await response.json();
 
 
 
 
151
 
152
  const tablesContainer = document.getElementById('tables');
153
  tablesContainer.innerHTML = '';
@@ -155,7 +159,7 @@
155
  // 使用 DocumentFragment 來優化 DOM 操作
156
  const fragment = document.createDocumentFragment();
157
 
158
- tables.forEach(table => {
159
  const tableElement = document.createElement('div');
160
  tableElement.className = 'table-container';
161
 
@@ -215,8 +219,8 @@
215
 
216
  tablesContainer.appendChild(fragment);
217
  } catch (error) {
218
- console.error('載入桌次資料失敗:', error);
219
- Swal.fire('錯誤', '載入桌次資料失敗', 'error');
220
  }
221
  }
222
 
 
147
  async function loadTables() {
148
  try {
149
  const response = await fetch('/api/tables');
150
+ const data = await response.json();
151
+
152
+ if (!data.tables) {
153
+ throw new Error('無效的桌次資料');
154
+ }
155
 
156
  const tablesContainer = document.getElementById('tables');
157
  tablesContainer.innerHTML = '';
 
159
  // 使用 DocumentFragment 來優化 DOM 操作
160
  const fragment = document.createDocumentFragment();
161
 
162
+ data.tables.forEach(table => {
163
  const tableElement = document.createElement('div');
164
  tableElement.className = 'table-container';
165
 
 
219
 
220
  tablesContainer.appendChild(fragment);
221
  } catch (error) {
222
+ console.error('Error:', error);
223
+ Swal.fire('錯誤', error.message || '載入桌次失敗', 'error');
224
  }
225
  }
226