Procházet zdrojové kódy

下载文件名优化

Michael Wang před 4 roky
rodič
revize
a63b00d5fb
2 změnil soubory, kde provedl 16 přidání a 1 odebrání
  1. 2 1
      src/features/OfflineExam/OfflineExamHome.vue
  2. 14 0
      src/utils/util.js

+ 2 - 1
src/features/OfflineExam/OfflineExamHome.vue

@@ -61,6 +61,7 @@
 </template>
 
 <script>
+import { downloadFileURL } from "@/utils/util";
 import { mapState } from "vuex";
 import EcsOfflineList from "./OfflineExamList.vue";
 
@@ -131,7 +132,7 @@ export default {
         this.downloadUrlDisabled = false;
       }, 10 * 1000);
 
-      window.location.href = this.answerCardUrl;
+      downloadFileURL(this.answerCardUrl, "答题纸模板.zip");
     },
   },
 };

+ 14 - 0
src/utils/util.js

@@ -34,3 +34,17 @@ export function setUUID() {
 export function isElectron() {
   return typeof nodeRequire != "undefined";
 }
+
+// 下载文件
+export async function downloadFileURL(url, name) {
+  const link = document.createElement("a");
+  link.style.display = "none";
+  const fileName = name || url.split("/").pop().split("?")[0];
+  console.log(fileName);
+  link.setAttribute("download", fileName);
+
+  link.href = url;
+  document.body.appendChild(link);
+  link.click();
+  document.body.removeChild(link);
+}