修复更多内容

This commit is contained in:
Alex Yang
2025-11-25 23:37:22 +08:00
parent 4d53b13220
commit d6e9cc990b
6 changed files with 709 additions and 56 deletions

View File

@@ -60,7 +60,27 @@ async function apiRequest(endpoint, method = 'GET', data = null) {
// 尝试解析JSON
const parsedData = JSON.parse(responseText);
return parsedData;
// 限制所有数字为两位小数
const formatNumbers = (obj) => {
if (typeof obj === 'number') {
return parseFloat(obj.toFixed(2));
} else if (Array.isArray(obj)) {
return obj.map(formatNumbers);
} else if (obj && typeof obj === 'object') {
const formattedObj = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
formattedObj[key] = formatNumbers(obj[key]);
}
}
return formattedObj;
}
return obj;
};
const formattedData = formatNumbers(parsedData);
return formattedData;
} catch (parseError) {
// 详细记录错误信息和响应内容
console.error('JSON解析错误:', parseError);