index.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  2. import { canvasCut, downloadTextFile, JSONStringify } from '@/utils'
  3. const chartEditStore = useChartEditStore()
  4. // 导出
  5. export const exportHandle = () => {
  6. // 取消选中
  7. chartEditStore.setTargetSelectChart(undefined)
  8. // 导出数据
  9. downloadTextFile(
  10. JSONStringify(chartEditStore.getStorageInfo || []),
  11. undefined,
  12. 'json'
  13. )
  14. // 导出图片
  15. const range = document.querySelector('.go-edit-range') as HTMLElement
  16. const watermark = document.getElementById('go-edit-watermark')
  17. // 隐藏边距线
  18. if (!range || !watermark) {
  19. window['$message'].error('导出失败!')
  20. return
  21. }
  22. // 记录缩放比例
  23. const scaleTemp = chartEditStore.getEditCanvas.scale
  24. // 百分百展示页面
  25. chartEditStore.setScale(1, true)
  26. // 展示水印
  27. watermark.style.display = 'block'
  28. setTimeout(() => {
  29. canvasCut(range, () => {
  30. // 隐藏水印
  31. if (watermark) watermark.style.display = 'none'
  32. // 还原页面大小
  33. chartEditStore.setScale(scaleTemp, true)
  34. })
  35. }, 600)
  36. }