zero hai 1 mes
pai
achega
17f4ee30a6
Modificáronse 3 ficheiros con 66 adicións e 1 borrados
  1. 12 0
      src/services/api.ts
  2. 48 1
      src/views/ReportDetail.vue
  3. 6 0
      vite.config.ts

+ 12 - 0
src/services/api.ts

@@ -344,4 +344,16 @@ export const reportApi = {
       throw error
     }
   },
+
+  //导出报告
+  exportReportInfo: async (params: Record<string, any>): Promise<unknown> => {
+    try {
+      const url = `/xiaoshi/ppa/report/exportReport`
+      const response = await apiClient.get<unknown>(url, {params})
+      return response
+    } catch (error) {
+      console.error(`Error from export report:`, error)
+      throw error
+    }
+  },
 }

+ 48 - 1
src/views/ReportDetail.vue

@@ -5,6 +5,7 @@
         <div class="card-header">
           <span class="header-title">报告详情</span>
           <div class="header-actions">
+            <el-button @click="exportReportInfo" type="primary">导出报告</el-button>
             <el-button @click="goBack" type="primary">返回</el-button>
           </div>
         </div>
@@ -160,7 +161,7 @@ const fetchReport = async () => {
     const reportId = parseInt(route.params.id as string)
 
     const response = await reportApi.getReport({ reportId: reportId })
-    report.value = response.data.data
+    report.value = response.data
   } catch (error) {
     ElMessage.error('获取报告信息失败')
   }
@@ -225,6 +226,52 @@ const saveEdit = async () => {
   }
 }
 
+const exportReportInfo = async () => {
+  try {
+    const reportId = parseInt(route.params.id as string)
+    const response = await reportApi.exportReportInfo({ reportId: reportId })
+    ElMessage.success('导出报告成功')
+    if(response.code == 200){
+      const guid = response.data
+      //执行下载
+      downLoad2(guid,report.value.reportName)
+    }
+    
+  } catch (error) {
+    ElMessage.error('导出报告失败')
+  }
+}
+
+//获取下载地址
+const getDownloadPath = (guid:string)=>{
+  if(!guid){
+      return ''
+  }
+  return `/api/fileManager/downloadFile?fileId=${guid}`
+}
+
+const downLoad2 = (guid:string,fileName="download") => {
+  //获取下载地址
+  const href = getDownloadPath(guid)
+  if(!href){
+    return
+  }
+  const anchor = document.createElement('a');
+  if ('download' in anchor) {
+    anchor.href = href;
+    anchor.setAttribute("download", fileName);
+    anchor.className = "download-js-link";
+    anchor.innerHTML = "downloading...";
+    anchor.style.display = "none";
+    document.body.appendChild(anchor);
+    setTimeout(function () {
+      anchor.click();
+      document.body.removeChild(anchor);
+    }, 66);
+    return true;
+  }
+}
+
 const cancelEdit = () => {
   editingNewsId.value = null
   originalNews.value = null

+ 6 - 0
vite.config.ts

@@ -14,6 +14,12 @@ export default defineConfig({
   },
   server: {
     proxy: {
+      '/fileManager': {
+        target: 'http://192.168.2.24:8803',
+        ws: true,
+        changeOrigin: true,
+        rewrite: (path) => path.replace(/^\/api/, ''),
+      },
       '/api': {
         target: 'http://192.168.2.107:8099',
         changeOrigin: true,