zhangjie 2 жил өмнө
parent
commit
9e40254b44

+ 5 - 3
src/features/report/ReportBatchDownload.vue

@@ -10,7 +10,7 @@
 
   <a-modal
     v-model:visible="loadModalVisible"
-    dialogClass="report-load-modal"
+    class="report-load-modal"
     centered
     :closable="false"
     :keyboard="false"
@@ -49,6 +49,7 @@ import {
 } from "@/api/allAnalysisPage";
 import { useRouter } from "vue-router";
 import { onBeforeMount, onMounted } from "vue";
+import { downloadByLink } from "@/utils/utils";
 const router = useRouter();
 
 interface ProgressItemType {
@@ -126,7 +127,7 @@ async function projectSelected(projectId: number) {
   taskId = res.data.taskId;
   paperIds = res.data.paperIds;
   totalTaskCount = paperIds.length;
-  console.log(paperIds, totalTaskCount);
+  // console.log(paperIds, totalTaskCount);
 
   if (!paperIds.length) {
     closeLoadModal();
@@ -181,7 +182,8 @@ async function finishTask() {
     updateProgress(100);
     closeLoadModal();
     void message.info("开始下载报告!");
-    window.open(res.data.filePath);
+    downloadByLink(res.data.filePath);
+    // window.open(res.data.filePath);
     return;
   }
   if (res.data.status === "FAILED") {

+ 5 - 5
src/features/report/ReportMain.vue

@@ -84,10 +84,10 @@ import { useMainStore } from "@/store";
 const store = useMainStore();
 
 const props = defineProps<{
-  paperId: number;
-  projectId: number;
+  paperId?: number;
+  projectId?: number;
   compareProjectId?: number;
-  viewType: string;
+  viewType?: string;
 }>();
 
 const route = useRoute();
@@ -127,10 +127,10 @@ const hasCompareProject = computed(
 onMounted(async () => {
   try {
     if (props.paperId) {
-      projectId = props.projectId;
+      projectId = props.projectId as number;
       paperId = props.paperId;
       compareProjectId = props.compareProjectId as number;
-      viewType = props.viewType;
+      viewType = props.viewType as string;
     } else {
       projectId = +route.params.projectId;
       paperId = +route.params.paperId;

+ 17 - 2
src/utils/utils.ts

@@ -3,9 +3,12 @@ import router from "@/router";
 import { AxiosResponse } from "axios";
 
 // 下载文件
-export async function downloadFileURL(url: string,data: Record<string, any> = {}) {
+export async function downloadFileURL(
+  url: string,
+  data: Record<string, any> = {}
+) {
   return httpApp
-    .get(url, { responseType: "blob" ,params:data})
+    .get(url, { responseType: "blob", params: data })
     .then((res) => {
       return responseToFile(res);
     })
@@ -33,6 +36,18 @@ export async function responseToFile(response: AxiosResponse) {
     window.URL.revokeObjectURL(url);
   });
 }
+
+export function downloadByLink(url: string) {
+  const dom = document.createElement("a");
+  dom.href = url;
+  let filename = url.split("/").slice(-1)[0];
+  dom.download = decodeURI(filename);
+  dom.style.display = "none";
+  document.body.appendChild(dom);
+  dom.click();
+  dom.parentNode?.removeChild(dom);
+}
+
 // 返回
 export function goBack() {
   router.back();

+ 2 - 2
vite.config.ts

@@ -3,9 +3,9 @@ import vue from "@vitejs/plugin-vue";
 import ViteComponents from "unplugin-vue-components/vite";
 import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
 
-const SERVER_URL = "http://192.168.10.108:7180";
+// const SERVER_URL = "http://192.168.10.108:7180";
 // const SERVER_URL = "http://192.168.10.138:13800";
-// const SERVER_URL = "http://192.168.10.39:7180";
+const SERVER_URL = "http://192.168.10.39:7100";
 // const SERVER_URL = "http://192.168.10.54:8001";
 const path = require("path");