export_drawingBoard.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. window.isMobile = function () {
  25. return /(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i.test(navigator.userAgent);
  26. }
  27. function refreshShareBlockSize() {
  28. // Unity画布宽高比
  29. let unityCanvasWidth = 1515;
  30. let unityCanvaslHeight = 780;
  31. let unityPanelWidth = 1150;
  32. let unityPanelHeight = 740;
  33. let unityPanelOffsetY = 0;
  34. let innerWidth = window.innerWidth;
  35. let innerHeight = window.innerHeight;
  36. let scale = (unityCanvasWidth / unityPanelHeight) >
  37. (innerWidth / innerHeight) ? (innerWidth / unityCanvasWidth) : (innerHeight / unityCanvaslHeight);
  38. saveDom.style.width = (unityPanelWidth * scale) + 'px';
  39. saveDom.style.height = (unityPanelHeight * scale) + 'px';
  40. if (unityPanelOffsetY > 0){
  41. saveDom.style.marginTop = (unityPanelOffsetY * scale * 2) + 'px';
  42. } else {
  43. saveDom.style.marginBottom = (-unityPanelOffsetY * scale * 2) + 'px';
  44. }
  45. }
  46. window.addEventListener('resize', ()=>{
  47. if (isShowSaveDom) refreshShareBlockSize();
  48. });