|
@@ -1134,13 +1134,38 @@ onMounted(function() {
|
|
optionsUpdate();
|
|
optionsUpdate();
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+const downloadFile = async (url, fileName) => {
|
|
|
|
+ try {
|
|
|
|
+ // 发起请求获取文件
|
|
|
|
+ const response = await fetch(url);
|
|
|
|
+ // 转换为blob对象
|
|
|
|
+ const blob = await response.blob();
|
|
|
|
+ // 创建临时URL
|
|
|
|
+ const objectUrl = URL.createObjectURL(blob);
|
|
|
|
+
|
|
|
|
+ // 创建a标签并触发下载
|
|
|
|
+ const a = document.createElement('a');
|
|
|
|
+ a.href = objectUrl;
|
|
|
|
+ a.download = fileName || 'download';
|
|
|
|
+ document.body.appendChild(a);
|
|
|
|
+ a.click();
|
|
|
|
+
|
|
|
|
+ // 清理
|
|
|
|
+ document.body.removeChild(a);
|
|
|
|
+ // 释放URL对象
|
|
|
|
+ URL.revokeObjectURL(objectUrl);
|
|
|
|
+
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error('下载失败:', error);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
// 模板下载
|
|
// 模板下载
|
|
const downTemplateEvent = () => {
|
|
const downTemplateEvent = () => {
|
|
- let url = new URL("../../../../assets/template/student_template.xlsx", import.meta.url).href;
|
|
|
|
- console.log("模板下载", url);
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
+ let url = new URL("../../../../assets/template/student_template.xlsx", import.meta.url).href;
|
|
|
|
+ // console.log("模板下载", url);
|
|
|
|
+ downloadFile(url, "批量导入学生模板.xlsx");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|