Merge pull request #7791 from dataease/pr@dev@refactor_full-screen

refactor: 全屏导出视图像素优化
This commit is contained in:
王嘉豪 2024-01-24 14:44:18 +08:00 committed by GitHub
commit e405e943fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 80 additions and 13 deletions

View File

@ -106,7 +106,7 @@ export default {
}, },
computed: { computed: {
isPcTerminal() { isPcTerminal() {
return this.terminal === 'PC' return this.terminal === 'pc'
}, },
functionClass() { functionClass() {
let result = 'function-light' let result = 'function-light'

View File

@ -116,15 +116,39 @@
v-if="chartDetailsVisible" v-if="chartDetailsVisible"
style="position: absolute;right: 70px;top:15px" style="position: absolute;right: 70px;top:15px"
> >
<el-button <span v-if="showChartInfoType==='enlarge' && hasDataPermission('export',panelInfo.privileges)&& showChartInfo && showChartInfo.type !== 'symbol-map'">
v-if="showChartInfoType==='enlarge' && hasDataPermission('export',panelInfo.privileges)&& showChartInfo && showChartInfo.type !== 'symbol-map'" <span style="font-size: 12px">
class="el-icon-picture-outline" 导出分辨率
size="mini" </span>
:disabled="imageDownloading" <el-select
@click="exportViewImg" v-model="pixel"
> style="width: 120px; margin-right: 8px; margin-top: -1px"
{{ $t('chart.export_img') }} :popper-append-to-body="false"
</el-button> size="mini"
>
<el-option-group
v-for="group in pixelOptions"
:key="group.label"
:label="group.label"
>
<el-option
v-for="item in group.options"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-option-group>
</el-select>
<el-button
class="el-icon-picture-outline"
size="mini"
:disabled="imageDownloading"
@click="exportViewImg"
>
{{ $t('chart.export_img') }}
</el-button>
</span>
<el-button <el-button
v-if="showChartInfoType==='details'&& hasDataPermission('export',panelInfo.privileges)" v-if="showChartInfoType==='details'&& hasDataPermission('export',panelInfo.privileges)"
size="mini" size="mini"
@ -293,7 +317,44 @@ export default {
pdfTemplateSelectedIndex: 0, pdfTemplateSelectedIndex: 0,
pdfTemplateContent: '', pdfTemplateContent: '',
templateInfo: {}, templateInfo: {},
pdfTemplateAll: [] pdfTemplateAll: [],
pixelOptions: [
{
label: 'Windows(16:9)',
options: [
{
value: '1920 * 1080',
label: '1920 * 1080'
},
{
value: '1600 * 900',
label: '1600 * 900'
},
{
value: '1280 * 720',
label: '1280 * 720'
}
]
},
{
label: 'MacOS(16:10)',
options: [
{
value: '2560 * 1600',
label: '2560 * 1600'
},
{
value: '1920 * 1200',
label: '1920 * 1200'
},
{
value: '1680 * 1050',
label: '1680 * 1050'
}
]
}
],
pixel: '1280 * 720'
} }
}, },
computed: { computed: {
@ -764,7 +825,7 @@ export default {
}, },
exportViewImg() { exportViewImg() {
this.imageDownloading = true this.imageDownloading = true
this.$refs['userViewDialog-canvas-main'].exportViewImg(() => { this.$refs['userViewDialog-canvas-main'].exportViewImg(this.pixel, () => {
this.imageDownloading = false this.imageDownloading = false
}) })
}, },

View File

@ -5,7 +5,6 @@
> >
<de-main-container <de-main-container
v-show="showChartCanvas" v-show="showChartCanvas"
v-loading="exportLoading"
style="overflow: hidden" style="overflow: hidden"
: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"

View File

@ -226,6 +226,11 @@ export function checkViewTitle(opt, id, tile) {
export function exportImg(imgName, callback) { export function exportImg(imgName, callback) {
const canvasID = document.getElementById('chartCanvas') const canvasID = document.getElementById('chartCanvas')
const a = document.createElement('a') const a = document.createElement('a')
// 保存原始的设备像素比值
const originalDPR = window.devicePixelRatio
// 将设备像素比设置为1
window.devicePixelRatio = 1
html2canvas(canvasID).then(canvas => { html2canvas(canvasID).then(canvas => {
const dom = document.body.appendChild(canvas) const dom = document.body.appendChild(canvas)
dom.style.display = 'none' dom.style.display = 'none'
@ -238,8 +243,10 @@ export function exportImg(imgName, callback) {
a.click() a.click()
URL.revokeObjectURL(blob) URL.revokeObjectURL(blob)
document.body.removeChild(a) document.body.removeChild(a)
window.devicePixelRatio = originalDPR
callback() callback()
}).catch(() => { }).catch(() => {
window.devicePixelRatio = originalDPR
callback() callback()
}) })
} }