export_drawingBoard.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. let saveDom = null;
  2. let isShowSaveDom = false;
  3. window.onDownload = function (base64string) {
  4. if (window.isMobile()){
  5. saveDom = document.querySelector('.save-image-background');
  6. saveDom.src = 'data:image/png;base64,' + base64string;
  7. saveDom.style.pointerEvents = 'auto';
  8. isShowSaveDom = true;
  9. refreshShareBlockSize();
  10. } else {
  11. let link = document.createElement('a');
  12. link.href = 'data:image/png;base64,' + base64string;
  13. link.download = 'image';
  14. link.click();
  15. }
  16. }
  17. window.onCancelDownload = function() {
  18. if (isShowSaveDom){
  19. saveDom.src = '';
  20. saveDom.style.pointerEvents = 'none';
  21. isShowSaveDom = false;
  22. }
  23. }
  24. function refreshShareBlockSize() {
  25. // Unity画布宽高比
  26. let unityCanvasWidth = 1515;
  27. let unityCanvaslHeight = 780;
  28. let unityPanelWidth = 1150;
  29. let unityPanelHeight = 740;
  30. let unityPanelOffsetY = 0;
  31. let innerWidth = window.innerWidth;
  32. let innerHeight = window.innerHeight;
  33. let scale = (unityCanvasWidth / unityPanelHeight) >
  34. (innerWidth / innerHeight) ? (innerWidth / unityCanvasWidth) : (innerHeight / unityCanvaslHeight);
  35. saveDom.style.width = (unityPanelWidth * scale) + 'px';
  36. saveDom.style.height = (unityPanelHeight * scale) + 'px';
  37. if (unityPanelOffsetY > 0){
  38. saveDom.style.marginTop = (unityPanelOffsetY * scale * 2) + 'px';
  39. } else {
  40. saveDom.style.marginBottom = (-unityPanelOffsetY * scale * 2) + 'px';
  41. }
  42. }
  43. window.addEventListener('resize', ()=>{
  44. if (isShowSaveDom) refreshShareBlockSize();
  45. });