Files
xs_system/frontend/js/api.js
T

49 lines
1.3 KiB
JavaScript
Raw Normal View History

2026-09-22 20:18:44 +08:00
const BASE_URL = 'http://127.0.0.1:12345';
async function request(path, params = {}) {
const url = new URL(BASE_URL + path);
Object.keys(params).forEach(key => {
if (params[key] !== undefined && params[key] !== null && params[key] !== '') {
url.searchParams.append(key, params[key]);
}
});
try {
const res = await fetch(url.toString());
if (!res.ok) throw new Error('HTTP ' + res.status);
const data = await res.json();
return data;
} catch (e) {
console.error('请求失败:', url.toString(), e);
throw e;
}
}
const API = {
getStudentsByAgeRange: (n, m, minAge, maxAge) =>
request('/basic-information', { n, m, min_age: minAge, max_age: maxAge }),
getClassInfo: (classId) =>
request('/basic-information/' + classId),
getAllClassStats: () =>
request('/class-stats'),
getStudentsByScore: (n, m, score) =>
request('/scores', { n, m, score }),
getNoPassStudents: (n, m, failCount) =>
request('/scores_no_pass', { n, m, fail_count: failCount }),
getClassExamAvg: (n, m) =>
request('/scores_avg', { n, m }),
getSalaryTop: (m = 5) =>
request('/salary_top', { m }),
getTimeSize: (n, m) =>
request('/time_size', { n, m }),
getClassAvgTimeSize: (n, m) =>
request('/class_avg_time_size', { n, m })
};