From 867849a70abe49517a648343f8f8a684a12f73bd Mon Sep 17 00:00:00 2001
From: yuyu <1981343953@qq.com>
Date: 星期三, 30 八月 2023 11:32:31 +0800
Subject: [PATCH] 8.30提交 导出pdf功能
---
.env.staging | 2 +-
package.json | 1 +
.env.production | 2 +-
src/views/experiment/checkTheReport/index.vue | 44 ++++++++++++++++++++++++++++++++++++++++++--
src/layout/components/Sidebar/SidebarItem.vue | 1 +
src/router/index.js | 8 +-------
6 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/.env.production b/.env.production
index dd72fa5..b1d6aa4 100644
--- a/.env.production
+++ b/.env.production
@@ -3,5 +3,5 @@
# base api
# VUE_APP_BASE_API = '/prod-api'
-VUE_APP_BASE_API = 'http://localhost:1234/'
+VUE_APP_BASE_API = 'http://192.168.137.138:1234/'
diff --git a/.env.staging b/.env.staging
index 92fbe73..d975095 100644
--- a/.env.staging
+++ b/.env.staging
@@ -5,6 +5,6 @@
# base api
# VUE_APP_BASE_API = '/stage-api'
-VUE_APP_BASE_API = 'http://localhost:1234/'
+VUE_APP_BASE_API = 'http://192.168.137.138:1234/'
diff --git a/package.json b/package.json
index 0b19172..4767215 100644
--- a/package.json
+++ b/package.json
@@ -20,6 +20,7 @@
"core-js": "3.6.5",
"echarts": "^5.4.3",
"element-ui": "2.13.2",
+ "html2pdf.js": "^0.10.1",
"js-cookie": "2.2.0",
"normalize.css": "7.0.0",
"nprogress": "0.2.0",
diff --git a/src/layout/components/Sidebar/SidebarItem.vue b/src/layout/components/Sidebar/SidebarItem.vue
index 9c2d33b..3e5922c 100644
--- a/src/layout/components/Sidebar/SidebarItem.vue
+++ b/src/layout/components/Sidebar/SidebarItem.vue
@@ -6,6 +6,7 @@
<el-menu-item v-if="onlyOneChild.meta.show==false ?onlyOneChild.meta.show: true" :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
<item :show="onlyOneChild.meta.show" :icon="onlyOneChild.meta.icon||(item.meta&&item.meta.icon)" :title="onlyOneChild.meta.title" />
<span v-if="onlyOneChild.meta.title==='涓婚〉'">涓婚〉</span>
+ <span v-if="onlyOneChild.meta.title==='鍩虹鏁版嵁'">鍩虹鏁版嵁</span>
</el-menu-item>
</app-link>
</template>
diff --git a/src/router/index.js b/src/router/index.js
index da562bd..458100d 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -472,13 +472,7 @@
name: 'BasicDataMessage',
component: () => import('@/views/basicData/index'),
meta: { title: '鍩虹鏁版嵁', icon: 'el-icon-s-tools' }
- },
- {
- path: 'myBusiness',
- name: 'MyBusiness',
- component: () => import('@/views/personal/myBusiness/index'),
- meta: { title: '鎴戠殑浼佷笟', icon: 'tree', show: false }
- }
+ }
]
},
{ path: '*', redirect: '/404', hidden: true }
diff --git a/src/views/experiment/checkTheReport/index.vue b/src/views/experiment/checkTheReport/index.vue
index b4efda6..253340f 100644
--- a/src/views/experiment/checkTheReport/index.vue
+++ b/src/views/experiment/checkTheReport/index.vue
@@ -30,7 +30,7 @@
</el-form-item>
</el-form>
<el-form>
- <el-button class="rightBtn" type="primary" icon="el-icon-document"
+ <el-button @click="exportToPDF" class="rightBtn" type="primary" icon="el-icon-document"
>瀵煎嚭鎶ュ憡</el-button
>
</el-form>
@@ -61,7 +61,7 @@
</span>
<div class="printStyle">
<Preview id="printRaw" :reportData="reportData" v-if="reportType===0"></Preview>
- <TestReport id="printFinished" :reportData="reportData" v-else></TestReport>
+ <TestReport ref="testreport" id="printFinished" :reportData="reportData" v-else></TestReport>
</div>
</el-dialog>
<div class="table-box">
@@ -77,6 +77,7 @@
textAlign: 'center',
}"
:data="reportTable"
+ @selection-change="handleSelectionChange"
style="width: 100%"
>
<el-table-column type="selection" label="" min-width="5%" />
@@ -176,6 +177,19 @@
</div>
</div>
</div>
+ <Preview ref="preview" id="printRaw" :reportData="reportData" v-show="false"></Preview>
+ <TestReport ref="testreport" id="printFinished" :reportData="reportData" v-show="false"></TestReport>
+ <el-dialog
+ title="瀵煎嚭pdf"
+ :visible.sync="dialogPdfVisible"
+ width="30%"
+ :before-close="handleClose">
+ <span>纭畾寮�濮嬪鍑哄悧锛�</span>
+ <span slot="footer" class="dialog-footer">
+ <el-button @click="dialogPdfVisible = false">鍙� 娑�</el-button>
+ <el-button type="primary" @click="confirmExport">纭� 瀹�</el-button>
+ </span>
+ </el-dialog>
</div>
</template>
@@ -184,6 +198,8 @@
import Preview from "@/components/experiment/checkTheReport/index.vue";
import TestReport from "@/components/experiment/template_testReport/index.vue"
import PrintJS from 'print-js'
+import html2pdf from 'html2pdf.js'
+
export default {
data() {
return {
@@ -220,6 +236,8 @@
pageSize: 10,
checked: true,
dialogVisible: false,
+ dialogPdfVisible: false,
+ selectedRows: []
};
},
created() {
@@ -244,6 +262,28 @@
this.reportType = row.type;
this.queryReportByRCode(row.reportCode);
},
+ handleSelectionChange(selection){
+ this.selectedRows = selection;
+ },
+ // 鎵归噺瀵煎嚭鎶ュ憡
+ exportToPDF() {
+ this.dialogPdfVisible = true;
+ },
+ // 纭瀵煎嚭妯℃�佹
+ confirmExport(){
+ this.selectedRows.forEach(async row => {
+ const element = document.getElementById('printFinished');
+ console.log(element)
+ // 璁剧疆TestReport缁勪欢鐨剅eportData灞炴�т负褰撳墠琛岀殑鎶ュ憡鏁版嵁
+ const resp = await getReportData({code:row.reportCode});
+ this.$nextTick(() => {
+ this.$refs.testreport.reportData = resp.data;
+ html2pdf().from(element).save(`exported_${row.reportCode}.pdf`);
+ });
+ });
+ this.dialogPdfVisible = false;
+ this.selectedRows = [];
+ },
//鎵撳嵃鎸夐挳
printFun(){
this.dialogVisible = false;
--
Gitblit v1.9.3