44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
|
|
// 测试下载模板功能
|
||
|
|
async function testDownloadTemplate() {
|
||
|
|
try {
|
||
|
|
console.log('开始测试下载模板功能...');
|
||
|
|
|
||
|
|
// 模拟API调用
|
||
|
|
const response = await fetch('http://localhost:5350/api/iot-cattle/public/import/template');
|
||
|
|
|
||
|
|
console.log('API响应状态:', response.status);
|
||
|
|
console.log('Content-Type:', response.headers.get('content-type'));
|
||
|
|
console.log('Content-Disposition:', response.headers.get('content-disposition'));
|
||
|
|
|
||
|
|
if (!response.ok) {
|
||
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取blob
|
||
|
|
const blob = await response.blob();
|
||
|
|
console.log('Blob类型:', blob.type);
|
||
|
|
console.log('Blob大小:', blob.size, 'bytes');
|
||
|
|
|
||
|
|
// 创建下载链接
|
||
|
|
const url = window.URL.createObjectURL(blob);
|
||
|
|
const link = document.createElement('a');
|
||
|
|
link.href = url;
|
||
|
|
link.download = '牛只档案导入模板.xlsx';
|
||
|
|
document.body.appendChild(link);
|
||
|
|
link.click();
|
||
|
|
document.body.removeChild(link);
|
||
|
|
window.URL.revokeObjectURL(url);
|
||
|
|
|
||
|
|
console.log('✅ 下载成功!');
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('❌ 下载失败:', error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 在浏览器控制台中运行
|
||
|
|
if (typeof window !== 'undefined') {
|
||
|
|
window.testDownloadTemplate = testDownloadTemplate;
|
||
|
|
console.log('测试函数已加载,请在控制台运行: testDownloadTemplate()');
|
||
|
|
}
|