erp-frontend/test-api.html
2026-04-06 21:14:31 +08:00

39 lines
1.3 KiB
HTML
Executable File

<!DOCTYPE html>
<html>
<head>
<title>API Test</title>
<script src="https://unpkg.com/axios@1.6.7/dist/axios.min.js"></script>
<script src="https://unpkg.com/axios-mock-adapter@1.22.0/dist/axios-mock-adapter.js"></script>
</head>
<body>
<h1>Brand API Test</h1>
<div id="result">Loading...</div>
<script>
const instance = axios.create({
baseURL: '/api',
timeout: 10000,
});
// Setup mock
const mock = new AxiosMockAdapter(instance, { delayResponse: 300 });
mock.onGet('/brands').reply(200, {
code: 200,
data: {
list: [{id: '1', name: '测试品牌', code: 'BR001'}],
total: 1
}
});
// Test the API
instance.get('/brands')
.then(res => {
document.getElementById('result').innerHTML = '<pre style="background:#f0f0f0;padding:10px;">✅ Mock Works! Response:\n' + JSON.stringify(res.data, null, 2) + '</pre>';
})
.catch(err => {
document.getElementById('result').innerHTML = '<pre style="background:#ffe0e0;padding:10px;">❌ Error:\n' + err.message + '</pre>';
});
</script>
</body>
</html>