mirror of
https://github.com/woodchen-ink/aimodels-prices.git
synced 2025-07-18 13:41:59 +08:00
Improve price table rendering with robust error handling and logging
This commit is contained in:
parent
fe48d1af9e
commit
fa9ac6789d
30
main.ts
30
main.ts
@ -552,10 +552,9 @@ const html = `<!DOCTYPE html>
|
||||
|
||||
tbody.innerHTML = '<tr><td colspan="11" class="text-center">加载中...</td></tr>';
|
||||
|
||||
// 直接使用相对路径
|
||||
fetch('/api/prices')
|
||||
fetch(API_BASE_URL + '/api/prices')
|
||||
.then(response => {
|
||||
console.log('Response status:', response.status);
|
||||
console.log('Response:', response);
|
||||
if (!response.ok) {
|
||||
throw new Error('HTTP error! status: ' + response.status);
|
||||
}
|
||||
@ -566,11 +565,19 @@ const html = `<!DOCTYPE html>
|
||||
tbody.innerHTML = '';
|
||||
|
||||
if (!data || !Array.isArray(data)) {
|
||||
tbody.innerHTML = '<tr><td colspan="11" class="text-center">加载失败</td></tr>';
|
||||
console.error('Invalid data format:', data);
|
||||
tbody.innerHTML = '<tr><td colspan="11" class="text-center">数据格式错误</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
data.forEach(price => {
|
||||
if (data.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="11" class="text-center">暂无数据</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Processing', data.length, 'price records');
|
||||
data.forEach((price, index) => {
|
||||
try {
|
||||
const tr = document.createElement('tr');
|
||||
const safePrice = {
|
||||
...price,
|
||||
@ -579,8 +586,7 @@ const html = `<!DOCTYPE html>
|
||||
status: price.status || 'pending'
|
||||
};
|
||||
|
||||
const vendorData = vendors[String(safePrice.channel_type)];
|
||||
const currentUser = localStorage.getItem('username');
|
||||
console.log('Processing price record', index + 1, ':', safePrice);
|
||||
|
||||
// 创建单元格
|
||||
const modelCell = document.createElement('td');
|
||||
@ -593,7 +599,8 @@ const html = `<!DOCTYPE html>
|
||||
billingTypeCell.appendChild(billingTypeBadge);
|
||||
|
||||
const vendorCell = document.createElement('td');
|
||||
if (vendorData) {
|
||||
if (vendors && vendors[String(safePrice.channel_type)]) {
|
||||
const vendorData = vendors[String(safePrice.channel_type)];
|
||||
const vendorIcon = document.createElement('img');
|
||||
vendorIcon.src = vendorData.icon;
|
||||
vendorIcon.className = 'vendor-icon';
|
||||
@ -651,7 +658,7 @@ const html = `<!DOCTYPE html>
|
||||
const operationCell = document.createElement('td');
|
||||
|
||||
const approveButton = document.createElement('button');
|
||||
approveButton.className = 'btn btn-success btn-sm';
|
||||
approveButton.className = 'btn btn-success btn-sm me-2';
|
||||
approveButton.textContent = '通过';
|
||||
approveButton.onclick = () => reviewPrice(safePrice.id || '', 'approved');
|
||||
|
||||
@ -666,11 +673,16 @@ const html = `<!DOCTYPE html>
|
||||
}
|
||||
|
||||
tbody.appendChild(tr);
|
||||
} catch (error) {
|
||||
console.error('Error processing price record', index + 1, ':', error);
|
||||
}
|
||||
});
|
||||
console.log('Finished loading price table');
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('加载价格数据失败:', error);
|
||||
tbody.innerHTML = '<tr><td colspan="11" class="text-center">加载失败: ' + error.message + '</td></tr>';
|
||||
showToast('加载价格数据失败', 'danger');
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user