人生啊人生 3 周之前
父节点
当前提交
b1f26bfe4c
共有 1 个文件被更改,包括 28 次插入3 次删除
  1. 28 3
      user_web/src/view/admin/components/ManageSchool/ModelManageStudent.vue

+ 28 - 3
user_web/src/view/admin/components/ManageSchool/ModelManageStudent.vue

@@ -1134,13 +1134,38 @@ onMounted(function() {
     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 = () => {
-    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");
     
 }