|
|
@ -1,17 +1,17 @@ |
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<div class="statistic"> |
|
|
|
<div class="statistic"> |
|
|
|
<el-button type="primary">导出数据统计</el-button> |
|
|
|
<el-button type="primary" @click="exportToWord">导出数据统计</el-button> |
|
|
|
<div class="contentContainer"> |
|
|
|
<div class="contentContainer" id="table" ref="pdfContent"> |
|
|
|
<div class="section" v-for="(item,index) in list" :key="index"> |
|
|
|
<div class="section" style=" display: flex;align-items: center;margin: 40px 0;" v-for="(item,index) in list" :key="index"> |
|
|
|
<div class="sectionTitle">{{item.title}}</div> |
|
|
|
<div class="sectionTitle" style=" font-size: 18px;font-weight: bold;width: 160px;flex-shrink: 0;">{{item.title}}</div> |
|
|
|
<div class="content"> |
|
|
|
<div class="content" style="display: flex;"> |
|
|
|
<div v-for="(p,i) in item.data" class="sectionDesc"> |
|
|
|
<div v-for="(p,i) in item.data" class="sectionDesc" style="width:200px;"> |
|
|
|
<div class="item">{{p.name}}</div> |
|
|
|
<div class="item">{{p.name}}</div> |
|
|
|
<div class="num" v-if="index==0">{{huitong[p.countText]}}</div> |
|
|
|
<div class="num" style="font-size: 24px;margin-top: 8px;" v-if="index==0">{{huitong[p.countText]}}</div> |
|
|
|
<div class="num" v-if="index==1">{{welfare[p.countText]}}</div> |
|
|
|
<div class="num" style="font-size: 24px;margin-top: 8px;" v-if="index==1">{{welfare[p.countText]}}</div> |
|
|
|
<div class="num" v-if="index==2">{{consume[p.countText]}}</div> |
|
|
|
<div class="num" style="font-size: 24px;margin-top: 8px;" v-if="index==2">{{consume[p.countText]}}</div> |
|
|
|
<div class="num" v-if="index==3">{{contribution[p.countText]}}</div> |
|
|
|
<div class="num" style="font-size: 24px;margin-top: 8px;" v-if="index==3">{{contribution[p.countText]}}</div> |
|
|
|
<div class="num" v-if="index==4">{{share_point[p.countText]}}</div> |
|
|
|
<div class="num" style="font-size: 24px;margin-top: 8px;" v-if="index==4">{{share_point[p.countText]}}</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -19,7 +19,12 @@ |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
<script> |
|
|
|
<script> |
|
|
|
import {getStatisticList} from '@/api/statistic' |
|
|
|
import {getStatisticList} from '@/api/statistic'; |
|
|
|
|
|
|
|
import htmlDocx from 'html-docx-js/dist/html-docx'; |
|
|
|
|
|
|
|
import FileSaver from 'file-saver'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// import html2canvas from 'html2canvas'; |
|
|
|
|
|
|
|
// import jsPDF from 'jspdf'; |
|
|
|
export default{ |
|
|
|
export default{ |
|
|
|
data(){ |
|
|
|
data(){ |
|
|
|
return{ |
|
|
|
return{ |
|
|
@ -111,6 +116,37 @@ export default{ |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
methods:{ |
|
|
|
methods:{ |
|
|
|
|
|
|
|
exportToWord() { |
|
|
|
|
|
|
|
// 获取需要转换的HTML内容 |
|
|
|
|
|
|
|
const htmlContent = document.querySelector('#table').outerHTML; |
|
|
|
|
|
|
|
// // 转换HTML为Docx文档 |
|
|
|
|
|
|
|
// const docxContent = htmlDocx.asBlob(htmlContent); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 创建下载链接 |
|
|
|
|
|
|
|
// const downloadLink = document.createElement('a'); |
|
|
|
|
|
|
|
// downloadLink.href = URL.createObjectURL(docxContent); |
|
|
|
|
|
|
|
// downloadLink.download = '数据统计.docx'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 触发下载 |
|
|
|
|
|
|
|
// downloadLink.click(); |
|
|
|
|
|
|
|
const fullHtmlContent = ` |
|
|
|
|
|
|
|
<!DOCTYPE html> |
|
|
|
|
|
|
|
<html> |
|
|
|
|
|
|
|
<head> |
|
|
|
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
|
|
|
|
|
|
|
</head> |
|
|
|
|
|
|
|
<body> |
|
|
|
|
|
|
|
${htmlContent} |
|
|
|
|
|
|
|
</body> |
|
|
|
|
|
|
|
</html> |
|
|
|
|
|
|
|
`; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 使用 html-docx-js 将 HTML 转换为 Word 文档的 Blob 对象 |
|
|
|
|
|
|
|
const converted = htmlDocx.asBlob(fullHtmlContent); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 使用 file-saver 保存 Blob 对象为 Word 文档文件 |
|
|
|
|
|
|
|
FileSaver.saveAs(converted, '数据统计.docx'); |
|
|
|
|
|
|
|
}, |
|
|
|
getStatisticListHandle(){ |
|
|
|
getStatisticListHandle(){ |
|
|
|
getStatisticList().then(res=>{ |
|
|
|
getStatisticList().then(res=>{ |
|
|
|
|
|
|
|
|
|
|
@ -121,7 +157,29 @@ export default{ |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// exportPDF() { |
|
|
|
|
|
|
|
// const title = 'PDF导出示例'; |
|
|
|
|
|
|
|
// const content = this.$refs.pdfContent; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 使用html2canvas将DOM元素转换为画布 |
|
|
|
|
|
|
|
// html2canvas(content).then(canvas => { |
|
|
|
|
|
|
|
// // 新建一个jspdf实例 |
|
|
|
|
|
|
|
// const pdf = new jsPDF(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 将canvas转换为图片 |
|
|
|
|
|
|
|
// const imgData = canvas.toDataURL('image/png'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 添加图像到PDF |
|
|
|
|
|
|
|
// const imgProps= pdf.getImageProperties(imgData); |
|
|
|
|
|
|
|
// const pdfWidth = pdf.internal.pageSize.getWidth(); |
|
|
|
|
|
|
|
// const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; |
|
|
|
|
|
|
|
// pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 保存生成的PDF |
|
|
|
|
|
|
|
// pdf.save(title + '.pdf'); |
|
|
|
|
|
|
|
// }); |
|
|
|
|
|
|
|
// } |
|
|
|
}, |
|
|
|
}, |
|
|
|
created(){ |
|
|
|
created(){ |
|
|
|
this.getStatisticListHandle() |
|
|
|
this.getStatisticListHandle() |
|
|
|