zhangjie %!s(int64=4) %!d(string=hai) anos
pai
achega
f11f7d88a9

+ 5 - 3
src/modules/exam/components/ApplyContent.vue

@@ -188,7 +188,6 @@ const initTaskApply = {
   cardId: "",
   cardRuleId: "",
   makeMethod: "",
-  refCardId: "",
   remark: "",
   courseCode: "",
   courseName: "",
@@ -401,12 +400,15 @@ export default {
         return;
       }
 
-      if (!this.curTaskApply.cardId && !this.curTaskApply.refCardId) {
+      if (!this.curTaskApply.cardId) {
         this.$message.error("请选择题卡创建方式!");
         return;
       }
 
-      if (this.curTaskApply.status !== "SUBMIT") {
+      if (
+        this.curTaskApply.makeMethod !== "SELECT" &&
+        this.curTaskApply.status !== "SUBMIT"
+      ) {
         this.$message.error("请先提交题卡!");
         return;
       }

+ 8 - 10
src/modules/exam/components/CardOptionDialog.vue

@@ -36,9 +36,9 @@
             :rules="rules"
             label-width="90px"
           >
-            <el-form-item prop="refCardId" label="已选题卡:">
+            <el-form-item prop="cardId" label="已选题卡:">
               <el-select
-                v-model="modalForm.refCardId"
+                v-model="modalForm.cardId"
                 style="width: 300px;"
                 placeholder="请选择"
                 clearable
@@ -113,8 +113,7 @@ const initModalForm = {
   courseName: "",
   cardRuleId: "",
   cardId: "",
-  makeMethod: "",
-  refCardId: ""
+  makeMethod: ""
 };
 
 export default {
@@ -134,7 +133,7 @@ export default {
       isSubmit: false,
       modalForm: { ...initModalForm },
       rules: {
-        refCardId: [
+        cardId: [
           {
             required: true,
             message: "请选择已选题卡",
@@ -281,21 +280,20 @@ export default {
 
       // 选择已有题卡
       if (this.modalForm.makeMethod === "SELECT") {
-        if (!this.modalForm.refCardId) {
+        if (!this.modalForm.cardId) {
           this.$message.error("请选择已有的题卡!");
           return;
         }
 
         this.$emit("confirm", {
           cardId: this.modalForm.cardId,
-          makeMethod: this.modalForm.makeMethod,
-          refCardId: this.modalForm.refCardId
+          makeMethod: this.modalForm.makeMethod
         });
         this.cancel();
       }
     },
     toPreview() {
-      if (!this.modalForm.refCardId) {
+      if (!this.modalForm.cardId) {
         this.$message.error("请先选择题卡!");
         return;
       }
@@ -303,7 +301,7 @@ export default {
         this.getRouterPath({
           name: "CardPreview",
           params: {
-            cardId: this.modalForm.refCardId,
+            cardId: this.modalForm.cardId,
             viewType: "view"
           }
         })

+ 33 - 10
src/modules/exam/views/DataTaskManage.vue

@@ -129,7 +129,7 @@ import {
 } from "@/constants/enumerate";
 import { dataTaskList, removeDataTask } from "../api";
 import { attachmentDownload } from "../../login/api";
-import { downloadBlob } from "@/plugins/utils";
+import { downloadFileURL } from "@/plugins/utils";
 
 export default {
   name: "data-task-manage",
@@ -207,13 +207,25 @@ export default {
       if (this.loading) return;
 
       this.loading = true;
-      const res = await downloadBlob(() => {
-        return attachmentDownload({ id: row.id, type: "REPORT" });
-      }, `${row.printPlanName}-日志文件.txt`).catch(() => {});
+      const res = await attachmentDownload({
+        id: row.id,
+        type: "REPORT"
+      }).catch(() => {});
 
+      if (!res) {
+        this.loading = false;
+        this.$message.error("文件下载失败,请重新尝试!");
+        return;
+      }
+
+      const url = res.url;
+      let result = true;
+      await downloadFileURL(url).catch(() => {
+        result = false;
+      });
       this.loading = false;
 
-      if (res) {
+      if (result) {
         this.$message.success("文件下载成功!");
       } else {
         this.$message.error("文件下载失败,请重新尝试!");
@@ -224,14 +236,25 @@ export default {
 
       this.loading = true;
       const type = row.hasResultFile ? "RESULT" : "IMPORT_FILE";
-      const typeName = row.hasResultFile ? "导出文件" : "导入文件";
-      const res = await downloadBlob(() => {
-        return attachmentDownload({ id: row.id, type });
-      }, `${row.printPlanName}-${typeName}.txt`).catch(() => {});
+      const res = await attachmentDownload({
+        id: row.id,
+        type
+      }).catch(() => {});
+
+      if (!res) {
+        this.loading = false;
+        this.$message.error("文件下载失败,请重新尝试!");
+        return;
+      }
 
+      const url = res.url;
+      let result = true;
+      await downloadFileURL(url).catch(() => {
+        result = false;
+      });
       this.loading = false;
 
-      if (res) {
+      if (result) {
         this.$message.success("文件下载成功!");
       } else {
         this.$message.error("文件下载失败,请重新尝试!");

+ 5 - 11
src/modules/print/views/BusinessDataExport.vue

@@ -166,11 +166,7 @@ import {
 } from "../api";
 import UploadButton from "@/components/UploadButton";
 import PreviewBusinessDetail from "../components/PreviewBusinessDetail";
-import {
-  downloadBlob,
-  parseTimeRangeDateAndTime,
-  randomCode
-} from "@/plugins/utils";
+import { downloadBlob, parseTimeRangeDateAndTime } from "@/plugins/utils";
 
 export default {
   name: "business-data-export",
@@ -253,19 +249,17 @@ export default {
       this.getList();
     },
     async toExport() {
+      // 异步导出
       if (this.loading) return;
 
       this.loading = true;
-      const res = await downloadBlob(() => {
-        return businessDataExport({ ...this.filter });
-      }, `${randomCode()}-查询结果.xlsx`).catch(() => {});
-
+      const res = await businessDataExport({ ...this.filter }).catch(() => {});
       this.loading = false;
 
       if (res) {
-        this.$message.success("文件下载成功!");
+        this.$message.success("导出任务已提交,请在任务管理中下载文件!");
       } else {
-        this.$message.error("文件下载失败,请重新尝试!");
+        this.$message.error("导出任务提交失败,请重新尝试!");
       }
     },
     async toDownloadTemplate() {

+ 39 - 0
src/plugins/utils.js

@@ -128,6 +128,45 @@ export async function downloadBlob(fetchFunc, fileName) {
   return true;
 }
 
+function toDataURL(url) {
+  return fetch(url)
+    .then(response => {
+      return response.blob();
+    })
+    .then(blob => {
+      return URL.createObjectURL(blob);
+    });
+}
+
+/**
+ *
+ * @param {String} url 下载链接
+ * @param {String} name 文件名称
+ */
+export async function downloadFileURL(url, name) {
+  const link = document.createElement("a");
+  link.style.display = "none";
+  const fileName =
+    name ||
+    url
+      .split("/")
+      .pop()
+      .split("?")[0];
+  link.setAttribute("download", fileName);
+
+  // txt 文件会直接在浏览器里面打开,这时候只能修改服务器设置,加上 Content-Disposition: attachment
+  if ([".txt"].some(v => fileName.endsWith(v))) {
+    // const urlObj = new URL(url);
+    // link.href = await toDataURL(url.replace(urlObj.origin));
+    link.href = await toDataURL(url);
+  } else {
+    link.href = url;
+  }
+  document.body.appendChild(link);
+  link.click();
+  document.body.removeChild(link);
+}
+
 /**
  * 构建图表btn
  * @param {Function} h createElement