From ccf73d764231f2ff01a23154c33b26cd49f7ca17 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期五, 08 十一月 2024 09:15:08 +0800
Subject: [PATCH] 添加导出和打印功能

---
 src/views/home/components/editDietary2.vue |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/src/views/home/components/editDietary2.vue b/src/views/home/components/editDietary2.vue
index fcb54c6..7526277 100644
--- a/src/views/home/components/editDietary2.vue
+++ b/src/views/home/components/editDietary2.vue
@@ -2,7 +2,7 @@
     <div class="dietarySurvey-item">
         <el-dialog v-model="state.dialogTableVisible" title="营养膳食调查表" :fullscreen="true" width="100%">
             <div class="container" style="width: 100%; height: 100%;overflow: auto;">
-                <div>
+                <div id='printFrom2'>
                     <div>
                         <el-form size="small">
                             <div style="width: 100%">
@@ -682,6 +682,14 @@
                     <el-button type="primary" @click="onSubmit">
                         保存
                     </el-button>
+                    <el-button v-if="state.viewInfo.id" type="primary" v-print="'#printFrom2'">
+                        <el-icon><Printer /></el-icon>
+                        打印
+                    </el-button>
+                    <el-button type="primary" v-if="state.viewInfo.id" @click="generatePDF">
+                        <el-icon><Position /></el-icon>
+                        导出
+                    </el-button>
                 </div>
             </template>
         </el-dialog>
@@ -692,6 +700,7 @@
 </template>
 
 <script setup lang="ts" name="visualizingLinkDemo2">
+import html2pdf from 'html2pdf.js';
 import { reactive, onMounted, onUnmounted, ref } from 'vue';
 import { formatDate } from '/@/utils/formatTime';
 import { NextLoading } from '/@/utils/loading';
@@ -881,6 +890,18 @@
 
 const funhui = () => {
     state.dialogTableVisible = false
+}
+const generatePDF=()=> {
+      const element = document.getElementById('printFrom2');
+      const opt = {
+        margin: 10,
+        filename: `${state.tableData.表名}.pdf`,
+        image: { type: 'jpeg', quality: 0.98 },
+        html2canvas: { scale: 2 },
+        jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
+      };
+      html2pdf().set(opt).from(element).save();
+
 }
 const onSubmit = () => {
     console.log('submit!')
@@ -1124,3 +1145,4 @@
     background-color: #ffffff;
 }
 </style>
+

--
Gitblit v1.8.0