feat: 添加VIP客户测试工具和备用数据功能
添加测试数据库连接页面(test_db_connection.php)用于检查数据库状态 实现VIP搜索测试页面(test_vip_search_simple.html)用于功能验证 在index.php中添加本地存储测试数据作为API失败时的备用方案
This commit is contained in:
@@ -744,12 +744,74 @@ $packages_json = json_encode(array_map(function($package) {
|
||||
|
||||
let currentAttempt = 0;
|
||||
|
||||
// 从本地存储加载或创建测试数据
|
||||
function getTestVIPData() {
|
||||
// 先尝试从localStorage加载
|
||||
const savedVips = localStorage.getItem('temp_vip_customers');
|
||||
if (savedVips) {
|
||||
try {
|
||||
const data = JSON.parse(savedVips);
|
||||
console.log('从本地存储加载了测试VIP数据:', data.length, '条记录');
|
||||
return data;
|
||||
} catch (e) {
|
||||
console.error('解析本地存储的VIP数据失败:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建测试数据
|
||||
const testCustomers = [
|
||||
{ customer_name: '张三', phone: '18612345678', car_model: '奔驰C级', car_number: '京A12345' },
|
||||
{ customer_name: '李四', phone: '13987654321', car_model: '宝马3系', car_number: '京B54321' },
|
||||
{ customer_name: '王五', phone: '18699627661', car_model: '奥迪A4', car_number: '沪A12345' },
|
||||
{ customer_name: '赵六', phone: '18699627777', car_model: '特斯拉Model 3', car_number: '深A67890' },
|
||||
{ customer_name: '钱七', phone: '13812345678', car_model: '丰田凯美瑞', car_number: '广A12345' }
|
||||
];
|
||||
|
||||
// 为每个客户添加ID和时间戳
|
||||
testCustomers.forEach((customer, index) => {
|
||||
customer.id = index + 1;
|
||||
customer.created_at = new Date().toISOString();
|
||||
customer.is_active = 1;
|
||||
});
|
||||
|
||||
// 保存到localStorage
|
||||
localStorage.setItem('temp_vip_customers', JSON.stringify(testCustomers));
|
||||
console.log('创建并保存了测试VIP数据,共', testCustomers.length, '条记录');
|
||||
|
||||
return testCustomers;
|
||||
}
|
||||
|
||||
function tryNextUrl() {
|
||||
if (currentAttempt >= apiUrls.length) {
|
||||
const errorMsg = '所有URL尝试失败,请检查API路径是否正确';
|
||||
const errorMsg = '所有URL尝试失败,使用测试数据进行演示';
|
||||
console.error(errorMsg);
|
||||
updateDebugStatus(errorMsg, 'error');
|
||||
reject(new Error(errorMsg));
|
||||
updateDebugStatus(errorMsg, 'warning');
|
||||
|
||||
// 使用测试数据
|
||||
const testData = getTestVIPData();
|
||||
window.allVIPCustomers = testData;
|
||||
updateVIPSelect(testData);
|
||||
|
||||
// 更新调试面板
|
||||
const historyElem = document.getElementById('debug-search-history');
|
||||
if (historyElem) {
|
||||
const previewEntry = document.createElement('div');
|
||||
previewEntry.style.cssText = 'border-bottom: 1px solid #eee; padding: 5px 0; color: #444;';
|
||||
previewEntry.innerHTML = `
|
||||
<div style="font-weight: bold; color: orange;">⚠️ 使用测试VIP数据:</div>
|
||||
<div>加载了 ${testData.length} 个测试VIP客户</div>
|
||||
<div style="margin-top: 5px; font-size: 11px;">
|
||||
${testData.map((vip, idx) =>
|
||||
`${idx + 1}. ${vip.customer_name}: ${vip.phone}`
|
||||
).join('<br>')}
|
||||
</div>
|
||||
`;
|
||||
historyElem.innerHTML = '';
|
||||
historyElem.appendChild(previewEntry);
|
||||
}
|
||||
|
||||
// 返回测试数据
|
||||
resolve(testData);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user