refactor(仪表板): 超长仪表板导出PDF、图片优化
This commit is contained in:
parent
2063f42c04
commit
950735cd16
@ -443,6 +443,9 @@ export default {
|
|||||||
bus.$off('trigger-reset-button', this.triggerResetButton)
|
bus.$off('trigger-reset-button', this.triggerResetButton)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getCanvasHeight() {
|
||||||
|
return this.mainHeightCount
|
||||||
|
},
|
||||||
openChartDetailsDialog(paramInfo) {
|
openChartDetailsDialog(paramInfo) {
|
||||||
if (this.canvasId === 'canvas-main') {
|
if (this.canvasId === 'canvas-main') {
|
||||||
this.showChartInfo = paramInfo.showChartInfo
|
this.showChartInfo = paramInfo.showChartInfo
|
||||||
|
|||||||
@ -82,7 +82,7 @@ export default {
|
|||||||
mainCanvasStyle() {
|
mainCanvasStyle() {
|
||||||
if (this.toExport) {
|
if (this.toExport) {
|
||||||
return {
|
return {
|
||||||
width: '4096px'
|
width: '1280px'
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
@ -93,7 +93,7 @@ export default {
|
|||||||
templateHtmlStyle() {
|
templateHtmlStyle() {
|
||||||
if (this.toExport) {
|
if (this.toExport) {
|
||||||
return {
|
return {
|
||||||
fontSize: '48px!important'
|
fontSize: '14px!important'
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return {}
|
return {}
|
||||||
@ -133,17 +133,16 @@ export default {
|
|||||||
_this.toExport = true
|
_this.toExport = true
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
html2canvas(document.getElementById('exportPdf')).then(function(canvas) {
|
html2canvas(document.getElementById('exportPdf')).then(function(canvas) {
|
||||||
_this.exportLoading = false
|
_this.exportLoading = false
|
||||||
const contentWidth = canvas.width / 4
|
const contentWidth = canvas.width / 2
|
||||||
const contentHeight = canvas.height / 4
|
const contentHeight = canvas.height / 2
|
||||||
const pageData = canvas.toDataURL('image/jpeg', 1.0)
|
const pageData = canvas.toDataURL('image/jpeg', 1.0)
|
||||||
const lp = contentWidth > contentHeight ? 'l' : 'p'
|
const lp = contentWidth > contentHeight ? 'l' : 'p'
|
||||||
const PDF = new JsPDF(lp, 'pt', [contentWidth, contentHeight])
|
const PDF = new JsPDF(lp, 'pt', [contentWidth, contentHeight])
|
||||||
PDF.addImage(pageData, 'JPEG', 0, 0, contentWidth, contentHeight)
|
PDF.addImage(pageData, 'JPEG', 0, 0, contentWidth, contentHeight)
|
||||||
PDF.save(_this.panelName + '.pdf')
|
PDF.save(_this.panelName + '.pdf')
|
||||||
_this.$emit('closePreExport')
|
_this.$emit('closePreExport')
|
||||||
}
|
})
|
||||||
)
|
|
||||||
}, 1500)
|
}, 1500)
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
style="border-bottom: 1px solid;border-bottom-color:#E6E6E6;"
|
style="border-bottom: 1px solid;border-bottom-color:#E6E6E6;"
|
||||||
>
|
>
|
||||||
<div style="height: 100%;">
|
<div style="height: 100%;">
|
||||||
<share-head />
|
<share-head/>
|
||||||
</div>
|
</div>
|
||||||
</el-row>
|
</el-row>
|
||||||
<el-row
|
<el-row
|
||||||
@ -45,7 +45,7 @@
|
|||||||
width="400"
|
width="400"
|
||||||
trigger="click"
|
trigger="click"
|
||||||
>
|
>
|
||||||
<panel-detail-info />
|
<panel-detail-info/>
|
||||||
<i
|
<i
|
||||||
slot="reference"
|
slot="reference"
|
||||||
class="el-icon-warning icon-class"
|
class="el-icon-warning icon-class"
|
||||||
@ -209,6 +209,7 @@
|
|||||||
>
|
>
|
||||||
<Preview
|
<Preview
|
||||||
v-if="showMainFlag"
|
v-if="showMainFlag"
|
||||||
|
ref="paneViewPreviewRef"
|
||||||
:component-data="mainCanvasComponentData"
|
:component-data="mainCanvasComponentData"
|
||||||
:canvas-style-data="canvasStyleData"
|
:canvas-style-data="canvasStyleData"
|
||||||
:active-tab="activeTab"
|
:active-tab="activeTab"
|
||||||
@ -378,8 +379,8 @@ export default {
|
|||||||
imageWrapperStyle() {
|
imageWrapperStyle() {
|
||||||
if (this.exporting) {
|
if (this.exporting) {
|
||||||
return {
|
return {
|
||||||
width: '2560px',
|
width: '1280px',
|
||||||
height: '1440px'
|
height: '720px'
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
@ -429,6 +430,16 @@ export default {
|
|||||||
bus.$off('set-panel-share-user', this.setPanelShareUser)
|
bus.$off('set-panel-share-user', this.setPanelShareUser)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// 画布高度大于6000px 自动使用原尺寸导出 减小浏览器再渲染压力
|
||||||
|
changeExportingState() {
|
||||||
|
const canvasHeight = this.$refs.paneViewPreviewRef.getCanvasHeight()
|
||||||
|
if (canvasHeight && canvasHeight > 6000) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
downLoadApp(appAttachInfo) {
|
downLoadApp(appAttachInfo) {
|
||||||
this.downLoadToApp(appAttachInfo)
|
this.downLoadToApp(appAttachInfo)
|
||||||
},
|
},
|
||||||
@ -597,7 +608,7 @@ export default {
|
|||||||
downloadAsImage() {
|
downloadAsImage() {
|
||||||
this.dataLoading = true
|
this.dataLoading = true
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.exporting = true
|
this.exporting = this.changeExportingState()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const canvasID = document.getElementById(this.canvasInfoTemp)
|
const canvasID = document.getElementById(this.canvasInfoTemp)
|
||||||
const a = document.createElement('a')
|
const a = document.createElement('a')
|
||||||
@ -628,7 +639,7 @@ export default {
|
|||||||
this.dataLoading = true
|
this.dataLoading = true
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.exporting = true
|
this.exporting = this.changeExportingState()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
html2canvas(document.getElementById(this.canvasInfoTemp)).then(canvas => {
|
html2canvas(document.getElementById(this.canvasInfoTemp)).then(canvas => {
|
||||||
const snapshot = canvas.toDataURL('image/jpeg', 1) // 是图片质量
|
const snapshot = canvas.toDataURL('image/jpeg', 1) // 是图片质量
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user