42 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-04-09 23:55:09 +08:00
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { canvasCut, downloadTextFile, JSONStringify } from '@/utils'
2022-04-09 23:55:09 +08:00
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(
JSONStringify(chartEditStore.getStorageInfo || []),
2022-04-10 17:56:51 +08:00
undefined,
'json'
)
2022-04-09 23:55:09 +08:00
// 导出图片
const range = document.querySelector('.go-edit-range') as HTMLElement
const watermark = document.getElementById('go-edit-watermark')
// 隐藏边距线
2022-08-21 14:42:31 +08:00
if (!range || !watermark) {
2022-04-09 23:55:09 +08:00
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
// 百分百展示页面
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'
// 还原页面大小
chartEditStore.setScale(scaleTemp, true)
})
}, 600)
}