zhangjie 1 rok temu
rodzic
commit
a29366c651

+ 15 - 0
src/api/paperAnalysisPage.ts

@@ -6,6 +6,7 @@ import {
   SASQuestion,
   SASQuestionGroup,
 } from "@/types";
+import { responseToFile } from "@/utils/utils";
 
 /** 试卷查询 */
 export function getPaper(id: number) {
@@ -59,3 +60,17 @@ export function importQuestionGroups(projectId: number, file: File) {
     f
   );
 }
+
+export function downloadPdfFromHtml(htmlContent) {
+  return httpApp
+    .post(
+      `/api/ess/sasQuestionGroup/import`,
+      { htmlContent },
+      {
+        responseType: "blob",
+      }
+    )
+    .then((res) => {
+      return responseToFile(res);
+    });
+}

+ 1 - 1
src/api/projectParamsManagementPage.ts

@@ -53,7 +53,7 @@ export function importProjectCollege(projectId: number, file: File) {
 export function exportProjectCollege(projectId: number) {
   return httpApp
     .get(
-      `/api/ess/projectCourse/college/export?` +
+      `/api/ess/projectCourse/college/template?` +
         new URLSearchParams({ projectId: projectId + "" }),
       {
         responseType: "blob",

+ 21 - 3
src/features/paperAnalysis/PaperReport.vue

@@ -6,7 +6,7 @@
       }})
     </template>
     <template #extra>
-      <a-button type="primary" @click="toDownloadReport">
+      <a-button type="primary" :loading="loading" @click="toDownloadReport">
         <template #icon>
           <svg-icon name="download" color="#fff"></svg-icon>
         </template>
@@ -26,6 +26,7 @@
   </a-card>
   <a-card title="报告预览">
     <ReportMain
+      ref="reportMainRef"
       viewType="view"
       :projectId="projectId"
       :paperId="paperId"
@@ -39,6 +40,10 @@ import { goBack } from "@/utils/utils";
 import { useMainStore } from "@/store";
 import ReportMain from "../report/ReportMain.vue";
 import { useRoute } from "vue-router";
+import useLoading from "@/hooks/loading";
+import { ref } from "vue";
+import { downloadPdfFromHtml } from "@/api/paperAnalysisPage";
+import { message } from "ant-design-vue";
 
 const store = useMainStore();
 store.currentLocation = "项目列表 / 查询结果 / 详情 / 报告预览";
@@ -51,7 +56,20 @@ const compareProjectId = (route.params.compareProjectId as string)
   .split(",")
   .map((item) => Number(item));
 
-function toDownloadReport() {
-  // TODO:下载
+const reportMainRef = ref();
+const { loading, setLoading } = useLoading();
+
+async function toDownloadReport() {
+  if (loading.value) return;
+  setLoading(true);
+
+  let err = false;
+  await downloadPdfFromHtml(reportMainRef.value?.getPreviewTemp()).catch(() => {
+    err = true;
+  });
+  setLoading(false);
+
+  if (err) return;
+  message.success("下载成功!");
 }
 </script>

+ 1 - 24
src/features/projectParamsManagement/ImportCollege.vue

@@ -30,12 +30,6 @@
           </a-button>
         </a-upload>
       </a-form-item>
-      <a-form-item label="下载模板">
-        <a-button :loading="downLoading" @click="downloadTpl">
-          <template #icon> <svg-icon name="download"></svg-icon> </template>
-          下载模板
-        </a-button>
-      </a-form-item>
     </a-form>
   </a-modal>
 </template>
@@ -46,7 +40,6 @@ import {
   exportProjectCollege,
   importProjectCollege,
 } from "@/api/projectParamsManagementPage";
-import { downloadFileURL } from "@/utils/utils";
 import { h } from "vue";
 import { message } from "ant-design-vue";
 import type { UploadProps } from "ant-design-vue";
@@ -104,7 +97,7 @@ async function handleImport() {
 /* download */
 const { loading: exportLoading, setLoading: setExportLoading } = useLoading();
 async function toExport() {
-  if (downLoading.value) return;
+  if (exportLoading.value) return;
   setExportLoading(true);
   let err = false;
   await exportProjectCollege(props.projectId).catch(() => {
@@ -115,20 +108,4 @@ async function toExport() {
 
   message.success("导出成功!");
 }
-
-const { loading: downLoading, setLoading: setDownLoading } = useLoading();
-async function downloadTpl() {
-  if (downLoading.value) return;
-  setDownLoading(true);
-  let err = false;
-  await downloadFileURL("/api/ess/projectCourse/college/template", {
-    projectId: props.projectId,
-  }).catch(() => {
-    err = true;
-  });
-  setDownLoading(false);
-  if (err) return;
-
-  message.success("下载成功!");
-}
 </script>

+ 2 - 0
src/features/report/ReportMain.vue

@@ -436,4 +436,6 @@ function getScoreGap(totalScore: number) {
     return 50;
   }
 }
+
+defineExpose({ getPreviewTemp });
 </script>

+ 6 - 0
src/styles/pages.less

@@ -165,3 +165,9 @@
     }
   }
 }
+
+.report-preview-frame {
+  position: fixed;
+  left: -9999px;
+  top: 0;
+}