49 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-04-09 23:55:09 +08:00
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { canvasCut, downloadTextFile } from '@/utils'
const chartEditStore = useChartEditStore()
// 导出
export const exportHandle = () => {
2022-04-10 17:56:51 +08:00
// 取消选中
chartEditStore.setTargetSelectChart(undefined)
2022-04-09 23:55:09 +08:00
// 导出数据
2022-04-10 17:56:51 +08:00
downloadTextFile(
JSON.stringify(chartEditStore.getStorageInfo || [], (k, v) => {
return v === undefined ? null : v
}),
undefined,
'json'
)
2022-04-09 23:55:09 +08:00
// 导出图片
const ruler = document.getElementById('mb-ruler')
const range = document.querySelector('.go-edit-range') as HTMLElement
const watermark = document.getElementById('go-edit-watermark')
// 隐藏边距线
if (!ruler || !range || !watermark) {
window['$message'].error('导出失败!')
return
}
2022-04-10 17:56:51 +08:00
2022-04-09 23:55:09 +08:00
// 记录缩放比例
const scaleTemp = chartEditStore.getEditCanvas.scale
// 去除标尺Dom
ruler.style.display = 'none'
// 百分百展示页面
chartEditStore.setScale(1, true)
// 展示水印
watermark.style.display = 'block'
2022-04-10 17:56:51 +08:00
2022-04-09 23:55:09 +08:00
setTimeout(() => {
canvasCut(range, () => {
// 隐藏水印
if (watermark) watermark.style.display = 'none'
// 放开边距线
if (ruler) ruler.style.display = 'block'
// 还原页面大小
chartEditStore.setScale(scaleTemp, true)
})
}, 600)
}