41 lines
1.5 KiB
HTML
41 lines
1.5 KiB
HTML
<div>
|
|
<a href="/template/订单导入模板.xlsx" target="_blank">模板下载</a>
|
|
<input type="file" id="fileInput"/>
|
|
</div>
|
|
<script>
|
|
const fileInput = document.getElementById('fileInput');
|
|
fileInput.addEventListener('change', function(event) {
|
|
const selectedFile = event.target.files[0]; // 获取选择的文件
|
|
console.log('Selected File:', selectedFile);
|
|
if (selectedFile.type != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
|
|
alert("请选择上传xlsx文件");
|
|
fileInput.value = null;
|
|
} else {
|
|
const formData = new FormData();
|
|
formData.append('file', selectedFile);
|
|
fetch('', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => {
|
|
if (response.ok) {
|
|
console.log('File uploaded successfully', response);
|
|
return response.json(); // 将响应解析为 JSON
|
|
} else {
|
|
console.error('File upload failed');
|
|
}
|
|
})
|
|
.then(data => {
|
|
console.log(data);
|
|
if (data && data.url) {
|
|
var win = window.open(data.url, '_blank'); // 在新标签页中打开 URL
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
fileInput.value = null;
|
|
});
|
|
}
|
|
// 在这里可以对选择的文件进行进一步处理
|
|
});
|
|
</script> |