提交 03cb1f06 authored 作者: wangjiahao's avatar wangjiahao

refactor: 仪表板支持高清PDF导出

上级 e59d5b80
...@@ -229,7 +229,7 @@ export default { ...@@ -229,7 +229,7 @@ export default {
const canvasWidth = document.getElementById('canvasInfoMain').offsetWidth const canvasWidth = document.getElementById('canvasInfoMain').offsetWidth
this.scaleWidth = (canvasWidth) * 100 / this.canvasStyleData.width // 获取宽度比 this.scaleWidth = (canvasWidth) * 100 / this.canvasStyleData.width // 获取宽度比
this.scaleHeight = canvasHeight * 100 / this.canvasStyleData.height// 获取高度比 this.scaleHeight = canvasHeight * 100 / this.canvasStyleData.height// 获取高度比
this.$store.commit('setPreviewCanvasScale', (this.scaleWidth / 100), (this.scaleHeight / 100)) this.$store.commit('setPreviewCanvasScale', { scaleWidth: (this.scaleWidth / 100), scaleHeight: (this.scaleHeight / 100) })
this.handleScaleChange() this.handleScaleChange()
}, },
resetID(data) { resetID(data) {
......
...@@ -1195,7 +1195,7 @@ export default { ...@@ -1195,7 +1195,7 @@ export default {
matrixStyleOriginWidth: this.matrixStyle.originWidth, matrixStyleOriginWidth: this.matrixStyle.originWidth,
matrixStyleOriginHeight: this.matrixStyle.originHeight matrixStyleOriginHeight: this.matrixStyle.originHeight
}) })
this.$store.commit('setPreviewCanvasScale', this.scalePointWidth, this.scalePointHeight) this.$store.commit('setPreviewCanvasScale', { scaleWidth: this.scalePointWidth, scaleHeight: this.scalePointHeight })
} }
}, },
getShapeStyleIntDeDrag(style, prop) { getShapeStyleIntDeDrag(style, prop) {
......
...@@ -316,6 +316,7 @@ export default { ...@@ -316,6 +316,7 @@ export default {
// 根据仪表板的缩放比例,修改视图内部参数 // 根据仪表板的缩放比例,修改视图内部参数
mergeScale() { mergeScale() {
const scale = Math.min(this.previewCanvasScale.scalePointWidth, this.previewCanvasScale.scalePointHeight) * this.scaleCoefficient const scale = Math.min(this.previewCanvasScale.scalePointWidth, this.previewCanvasScale.scalePointHeight) * this.scaleCoefficient
console.log('scale:' + scale + ';this.previewCanvasScale:' + JSON.stringify(this.previewCanvasScale))
const customAttrChart = JSON.parse(this.sourceCustomAttrStr) const customAttrChart = JSON.parse(this.sourceCustomAttrStr)
const customStyleChart = JSON.parse(this.sourceCustomStyleStr) const customStyleChart = JSON.parse(this.sourceCustomStyleStr)
recursionTransObj(customAttrTrans, customAttrChart, scale, this.scaleCoefficientType) recursionTransObj(customAttrTrans, customAttrChart, scale, this.scaleCoefficientType)
......
...@@ -94,8 +94,6 @@ export const customAttrTrans = { ...@@ -94,8 +94,6 @@ export const customAttrTrans = {
'barWidth', 'barWidth',
'lineWidth', 'lineWidth',
'lineSymbolSize', 'lineSymbolSize',
'pieInnerRadius',
'pieOuterRadius',
'funnelWidth', // 漏斗图 最大宽度 'funnelWidth', // 漏斗图 最大宽度
'tableTitleFontSize', 'tableTitleFontSize',
'tableItemFontSize', 'tableItemFontSize',
......
...@@ -140,12 +140,12 @@ const data = { ...@@ -140,12 +140,12 @@ const data = {
setCurCanvasScale(state, curCanvasScale) { setCurCanvasScale(state, curCanvasScale) {
state.curCanvasScale = curCanvasScale state.curCanvasScale = curCanvasScale
}, },
setPreviewCanvasScale(state, scaleWidth, scaleHeight) { setPreviewCanvasScale(state, scale) {
if (scaleWidth) { if (scale.scaleWidth) {
state.previewCanvasScale.scalePointWidth = scaleWidth state.previewCanvasScale.scalePointWidth = scale.scaleWidth
} }
if (scaleHeight) { if (scale.scaleHeight) {
state.previewCanvasScale.scalePointHeight = scaleHeight state.previewCanvasScale.scalePointHeight = scale.scaleHeight
} }
}, },
setShapeStyle({ curComponent, canvasStyleData, curCanvasScale }, { top, left, width, height, rotate }) { setShapeStyle({ curComponent, canvasStyleData, curCanvasScale }, { top, left, width, height, rotate }) {
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
style="height: 100%;width: 100%;" style="height: 100%;width: 100%;"
:element-loading-text="$t('panel.export_loading')" :element-loading-text="$t('panel.export_loading')"
element-loading-spinner="el-icon-loading" element-loading-spinner="el-icon-loading"
element-loading-background="rgba(0, 0, 0, 0.8)" element-loading-background="rgba(0, 0, 0, 1)"
> >
<el-row class="export_body_class"> <el-row class="export_body_class">
<div id="exportPdf" ref="exportPdf"> <div id="exportPdf" ref="exportPdf" :style="mainCanvasStyle">
<div class="export_body_inner_class" v-html="templateContentChange" /> <div class="export_body_inner_class" :style="templateHtmlStyle" v-html="templateContentChange" />
</div> </div>
</el-row> </el-row>
<el-row class="root_class"> <el-row class="root_class">
...@@ -26,6 +26,7 @@ import { pdfTemplateReplaceAll } from '@/utils/StringUtils.js' ...@@ -26,6 +26,7 @@ import { pdfTemplateReplaceAll } from '@/utils/StringUtils.js'
export default { export default {
name: 'PDFPreExport', name: 'PDFPreExport',
components: { },
props: { props: {
// eslint-disable-next-line vue/require-default-prop // eslint-disable-next-line vue/require-default-prop
panelName: { panelName: {
...@@ -43,6 +44,7 @@ export default { ...@@ -43,6 +44,7 @@ export default {
}, },
data() { data() {
return { return {
toExport: false,
exportLoading: false, exportLoading: false,
activeName: '', activeName: '',
templateContentChange: '', templateContentChange: '',
...@@ -60,7 +62,26 @@ export default { ...@@ -60,7 +62,26 @@ export default {
} }
}, },
computed: { computed: {
mainCanvasStyle() {
if (this.toExport) {
return {
width: '4096px'
}
} else {
return {
width: '100%'
}
}
},
templateHtmlStyle() {
if (this.toExport) {
return {
fontSize: '48px!important'
}
} else {
return {}
}
}
}, },
watch: { watch: {
templateContent(newVal, oldVla) { templateContent(newVal, oldVla) {
...@@ -92,19 +113,22 @@ export default { ...@@ -92,19 +113,22 @@ export default {
const _this = this const _this = this
_this.exportLoading = true _this.exportLoading = true
setTimeout(() => { setTimeout(() => {
html2canvas(document.getElementById('exportPdf')).then(function(canvas) { _this.toExport = true
_this.exportLoading = false setTimeout(() => {
const contentWidth = canvas.width html2canvas(document.getElementById('exportPdf')).then(function(canvas) {
const contentHeight = canvas.height _this.exportLoading = false
const pageData = canvas.toDataURL('image/jpeg', 1.0) const contentWidth = canvas.width
const lp = contentWidth > contentHeight ? 'l' : 'p' const contentHeight = canvas.height
const PDF = new JsPDF(lp, 'pt', [contentWidth, contentHeight]) const pageData = canvas.toDataURL('image/jpeg', 1.0)
PDF.addImage(pageData, 'JPEG', 0, 0, contentWidth, contentHeight) const lp = contentWidth > contentHeight ? 'l' : 'p'
PDF.save(_this.panelName + '.pdf') const PDF = new JsPDF(lp, 'pt', [contentWidth, contentHeight])
_this.$emit('closePreExport') PDF.addImage(pageData, 'JPEG', 0, 0, contentWidth, contentHeight)
} PDF.save(_this.panelName + '.pdf')
) _this.$emit('closePreExport')
}, 50) }
)
}, 1500)
}, 500)
} }
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
style="height: 100%;width: 100%;" style="height: 100%;width: 100%;"
:element-loading-text="$t('panel.data_loading')" :element-loading-text="$t('panel.data_loading')"
element-loading-spinner="el-icon-loading" element-loading-spinner="el-icon-loading"
element-loading-background="rgba(0, 0, 0, 0.8)" element-loading-background="rgba(0, 0, 0, 1)"
> >
<el-col v-if="panelInfo.name.length>0" class="panel-design"> <el-col v-if="panelInfo.name.length>0" class="panel-design">
...@@ -73,9 +73,10 @@ ...@@ -73,9 +73,10 @@
</el-row> </el-row>
<!-- 仪表板预览区域--> <!-- 仪表板预览区域-->
<el-row class="panel-design-preview"> <el-row class="panel-design-preview">
<div id="imageWrapper" ref="imageWrapper" style="width: 100%;height: 100%"> <!-- <div id="imageWrapper" ref="imageWrapper" style="width: 4096px;height: 2160px">-->
<div id="imageWrapper" ref="imageWrapper" :style="imageWrapperStyle">
<fullscreen style="height: 100%;background: #f7f8fa;overflow-y: auto" :fullscreen.sync="fullscreen"> <fullscreen style="height: 100%;background: #f7f8fa;overflow-y: auto" :fullscreen.sync="fullscreen">
<Preview v-if="showMain" :in-screen="!fullscreen" :show-type="'width'" :screen-shot="dataLoading" /> <Preview v-if="showMainFlag" :in-screen="!fullscreen" :show-type="'width'" :screen-shot="dataLoading" />
</fullscreen> </fullscreen>
</div> </div>
</el-row> </el-row>
...@@ -129,6 +130,7 @@ import { starStatus, saveEnshrine, deleteEnshrine } from '@/api/panel/enshrine' ...@@ -129,6 +130,7 @@ import { starStatus, saveEnshrine, deleteEnshrine } from '@/api/panel/enshrine'
import bus from '@/utils/bus' import bus from '@/utils/bus'
import { queryAll } from '@/api/panel/pdfTemplate' import { queryAll } from '@/api/panel/pdfTemplate'
import ShareHead from '@/views/panel/GrantAuth/ShareHead' import ShareHead from '@/views/panel/GrantAuth/ShareHead'
import JsPDF from 'jspdf'
export default { export default {
name: 'PanelViewShow', name: 'PanelViewShow',
...@@ -154,10 +156,27 @@ export default { ...@@ -154,10 +156,27 @@ export default {
pdfExportShow: false, pdfExportShow: false,
snapshotInfo: '', snapshotInfo: '',
showType: 0, showType: 0,
dataLoading: false dataLoading: false,
exporting: false
} }
}, },
computed: { computed: {
imageWrapperStyle() {
if (this.exporting) {
return {
width: '4096px',
height: '2160px'
}
} else {
return {
width: '100%',
height: '100%'
}
}
},
showMainFlag() {
return this.showMain
},
panelInfo() { panelInfo() {
return this.$store.state.panel.panelInfo return this.$store.state.panel.panelInfo
}, },
...@@ -252,17 +271,24 @@ export default { ...@@ -252,17 +271,24 @@ export default {
}, },
downloadAsPDF() { downloadAsPDF() {
// this.pdfExportShow = true
//
this.dataLoading = true this.dataLoading = true
setTimeout(() => { setTimeout(() => {
html2canvas(document.getElementById('canvasInfoTemp')).then(canvas => { this.exporting = true
const snapshot = canvas.toDataURL('image/jpeg', 1) // 是图片质量 setTimeout(() => {
this.dataLoading = false html2canvas(document.getElementById('canvasInfoTemp')).then(canvas => {
if (snapshot !== '') { const snapshot = canvas.toDataURL('image/jpeg', 1) // 是图片质量
this.snapshotInfo = snapshot this.dataLoading = false
this.pdfExportShow = true this.exporting = false
} if (snapshot !== '') {
}) this.snapshotInfo = snapshot
}, 50) this.pdfExportShow = true
}
})
}, 1500)
}, 500)
}, },
refreshTemplateInfo() { refreshTemplateInfo() {
this.templateInfo = {} this.templateInfo = {}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论