Ver Fonte

feat:增加报告导出功能

lupeng há 4 dias atrás
pai
commit
3e9424805d

+ 9 - 0
src/api/report/index.js

@@ -7,3 +7,12 @@ export function getData(data) {
     data,
   });
 }
+
+export function exportDataInfo(data) {
+  return request({
+    url: "/api/v1/quality/report/zip",
+    method: "post",
+    responseType: "arraybuffer",
+    data:data
+  });
+}

+ 33 - 2
src/views/statistic/report/index.vue

@@ -19,8 +19,11 @@
       <template #menu="{ row, index, type }">
         <el-button type="primary" size="small" @click="showDetail(row)"
           >查看</el-button
-        ></template
-      >
+        >
+        <el-button type="primary" size="small" @click="exportDataZip(row)"
+        >导出</el-button
+        >
+      </template>
       <template #menu-right="{}">
         <el-button
           class="ml-3"
@@ -40,6 +43,7 @@ import { ref, getCurrentInstance } from "vue";
 import { useCrud } from "@/hooks/userCrud";
 import reportTemplate from "@/components/ReportView/reportTemplate.vue";
 import ToPrintDialog from "./toPrintTables.vue";
+import {exportDataInfo} from "@/api/report";
 // 传入一个url,后面不带/
 const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
   useCrud({
@@ -63,6 +67,8 @@ const importExcelData = () => {
   }
 };
 
+
+
 const toPrintRef = ref(null);
 
 const detail = ref({});
@@ -72,6 +78,31 @@ const showDetail = (row) => {
   toPrintRef.value && toPrintRef.value.openPrintDialog(row);
 };
 
+const exportDataZip = async (row) => {
+
+    search.value=row;
+    exportData("/api/v1/quality/report/zip");
+
+};
+
+const downFile = (response) => {
+  const fileData = response.data;
+  const fileName = decodeURI(
+    response.headers["content-disposition"].split(";")[1].split("=")[1]
+  );
+  const fileType =
+    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8";
+  const blob = new Blob([fileData], { type: fileType });
+  const downloadUrl = window.URL.createObjectURL(blob);
+  const downloadLink = document.createElement("a");
+  downloadLink.href = downloadUrl;
+  downloadLink.download = fileName;
+  document.body.appendChild(downloadLink);
+  downloadLink.click();
+  document.body.removeChild(downloadLink);
+  window.URL.revokeObjectURL(downloadUrl);
+};
+
 // 设置表格列或者其他自定义的option
 option.value = Object.assign(option.value, {
   searchEnter: true,

+ 2 - 2
src/views/statistic/report/toPrintTables.vue

@@ -236,14 +236,14 @@ defineExpose({
     <template #header>
       <div class="dialog-header">
         <div>报告预览</div>
-        <el-button
+<!--        <el-button
           type="primary"
           size="small"
           @click="dialogVisible = false"
           v-print="'#print'"
         >
           打印
-        </el-button>
+        </el-button>-->
       </div>
     </template>
   </el-dialog>