Files
nxxmdata/backend/test-error-fix.js
2025-09-22 19:09:45 +08:00

92 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 测试错误修复
* @file test-error-fix.js
* @description 测试修复后的智能项圈预警页面
*/
const axios = require('axios');
const BASE_URL = 'http://localhost:5350/api/smart-alerts/public';
async function testErrorFix() {
console.log('🔧 测试错误修复...\n');
try {
// 获取预警列表数据
const response = await axios.get(`${BASE_URL}/collar`, {
params: { page: 1, limit: 3 }
});
if (response.data.success) {
const data = response.data.data || [];
const stats = response.data.stats || {};
console.log('✅ API调用成功');
console.log(`数据条数: ${data.length}`);
console.log('统计数据:', stats);
// 模拟前端数据转换逻辑
console.log('\n🔄 模拟前端数据转换...');
data.forEach((item, index) => {
console.log(`\n处理第${index + 1}条数据:`);
console.log('原始数据:', {
id: item.id,
alertType: item.alertType,
alertLevel: item.alertLevel,
collarNumber: item.collarNumber,
battery: item.battery,
temperature: item.temperature
});
// 模拟前端转换逻辑
let alertTypeText = '正常'
let alertLevel = 'low'
let determinedAlertType = null
if (item.alertType) {
const alertTypeMap = {
'battery': '低电量预警',
'offline': '离线预警',
'temperature': '温度预警',
'temperature_low': '温度过低预警',
'temperature_high': '温度过高预警',
'movement': '异常运动预警',
'wear': '佩戴异常预警'
}
alertTypeText = alertTypeMap[item.alertType] || item.alertType
determinedAlertType = item.alertType
const alertLevelMap = {
'high': '高级',
'medium': '中级',
'low': '低级',
'critical': '紧急'
}
alertLevel = alertLevelMap[item.alertLevel] || item.alertLevel
}
console.log('转换结果:', {
alertTypeText,
alertLevel,
determinedAlertType
});
});
console.log('\n✅ 数据转换测试通过没有ReferenceError');
} else {
console.log('❌ API调用失败:', response.data.message);
}
} catch (error) {
console.error('❌ 测试失败:', error.message);
if (error.response) {
console.error('响应状态:', error.response.status);
}
}
}
// 运行测试
testErrorFix().catch(console.error);