From 35a85b085df4c76c38c76dfda74aa4527cea0b5b Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期五, 28 二月 2025 15:57:06 +0800
Subject: [PATCH] gx

---
 src/views/home/components/fangAn/editDietary.vue |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/views/home/components/fangAn/editDietary.vue b/src/views/home/components/fangAn/editDietary.vue
index a7c9e77..88538d8 100644
--- a/src/views/home/components/fangAn/editDietary.vue
+++ b/src/views/home/components/fangAn/editDietary.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 id="fanganprintFrom1" class="print-section">
+                <div ref="printRef" id="fanganprintFrom1" class="print-section">
                     <div>
                         <el-form size="small">
                             <div style="width: 100%">
@@ -609,18 +609,18 @@
                     <el-button type="primary" @click="onSubmit">
                         保存
                     </el-button>
-                    <el-button v-if="state.viewInfo.id" type="primary" v-print="'#fanganprintFrom1'">
+                    <el-button v-if="state.viewInfo.id" type="primary" @click="onPrint">
                         <el-icon>
                             <Printer />
                         </el-icon>
                         打印
                     </el-button>
-                    <el-button type="primary" v-if="state.viewInfo.id" @click="generatePDF">
+                    <!-- <el-button type="primary" v-if="state.viewInfo.id" @click="generatePDF">
                         <el-icon>
                             <Position />
                         </el-icon>
                         导出
-                    </el-button>
+                    </el-button> -->
 
                 </div>
             </template>
@@ -656,6 +656,7 @@
 import html2pdf from 'html2pdf.js';
 import html2canvas from 'html2canvas';
 import { jsPDF } from 'jspdf';
+import printJs from 'print-js';
 import { reactive, onMounted, onUnmounted, ref,computed} from 'vue';
 import { formatDate } from '/@/utils/formatTime';
 import { NextLoading } from '/@/utils/loading';
@@ -671,6 +672,8 @@
 const { patientsInfo } = storeToRefs(storesPat);
 const { userInfos } = storeToRefs(stores);
 const router = useRouter()
+// 定义变量内容
+const printRef = ref();
 const emit = defineEmits(["shuaxin"]);
 const state = reactive({
     centerDialogVisibleYZDBZ:false,
@@ -824,6 +827,16 @@
     }
 
 })
+// 打印
+const onPrint=()=>{
+    printJs({
+		printable: printRef.value,
+		type: 'html',
+		css: ['@/assets/css/printcss.css','//at.alicdn.com/t/c/font_2298093_rnp72ifj3ba.css', '//unpkg.com/element-plus/dist/index.css'],
+		scanStyles: false,
+		style: `@media print{}}`,
+	});
+}
 const numberPart=(str:any)=>{
     if(str){
          // 使用正则表达式匹配数字
@@ -933,10 +946,6 @@
 }
 const funhui = () => {
     state.dialogTableVisible = false
-}
-// 打印
-const onPrint = () => {
-
 }
 const generatePDF = () => {
     const element = document.getElementById('fanganprintFrom1');

--
Gitblit v1.8.0