RuntimeEnvironment.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * 检测程序运行环境
  3. * @return
  4. */
  5. const _checkAppOrWeb = function() {
  6. if (window.navigator.userAgent.match(
  7. /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
  8. )) {
  9. return "App";
  10. } else {
  11. return "Web";
  12. }
  13. }
  14. /**
  15. * 是否是运行于App
  16. * @ignore
  17. */
  18. export const isRuntimeApp = function() {
  19. if (_checkAppOrWeb() === "App") {
  20. return true;
  21. }
  22. return false;
  23. }
  24. /**
  25. * 是否是运行于App
  26. * @ignore
  27. */
  28. export const isRuntimeWeb = function() {
  29. if (_checkAppOrWeb() === "Web") {
  30. return true;
  31. }
  32. return false;
  33. }
  34. /**
  35. * @ignore
  36. * 创建操作的主容器
  37. */
  38. export function createOperationMainDom() {
  39. //创建画布
  40. let buttonDiv = document.createElement('div');
  41. buttonDiv.id = "drawButtonDiv";
  42. buttonDiv.style.width = '80px';
  43. buttonDiv.style.backgroundColor = 'rgba(5, 45, 155, 0.7)';
  44. buttonDiv.style.borderRadius = '5px';
  45. buttonDiv.style.display = 'flex';
  46. buttonDiv.style.flexDirection = 'column';
  47. buttonDiv.style.padding = '8px';
  48. buttonDiv.style.justifyContent = 'center';
  49. buttonDiv.style.position = 'absolute';
  50. buttonDiv.style.bottom = '150px';
  51. buttonDiv.style.right = '10px';
  52. let btnUndo = document.createElement('button');
  53. btnUndo.id = "btnDrawBackout";
  54. btnUndo.style.height = '30px';
  55. btnUndo.style.marginBottom = '8px';
  56. btnUndo.style.backgroundColor = 'rgba(52, 137, 255, 1.0)';
  57. btnUndo.style.color = 'rgb(255, 255, 255)';
  58. btnUndo.style.border = '0px solid red';
  59. btnUndo.style.borderRadius = '5px';
  60. btnUndo.innerHTML = '回退';
  61. btnUndo.style.fontSize = '13px';
  62. btnUndo.style.cursor = 'pointer';
  63. buttonDiv.appendChild(btnUndo);
  64. let btnCompletion = document.createElement('button');
  65. btnCompletion.id = "btnDrawComplete";
  66. btnCompletion.style.height = '30px';
  67. btnCompletion.style.backgroundColor = 'rgba(88, 185, 45, 1.0)';
  68. btnCompletion.style.color = 'rgb(255, 255, 255)';
  69. btnCompletion.style.border = '0px solid red';
  70. btnCompletion.style.borderRadius = '5px';
  71. btnCompletion.innerHTML = '完成';
  72. btnCompletion.style.fontSize = '13px';
  73. btnCompletion.style.cursor = 'pointer';
  74. buttonDiv.appendChild(btnCompletion);
  75. /* 加入到页面 */
  76. document.body.appendChild(buttonDiv);
  77. }
  78. /**
  79. * 创建顶部弹出提示消息 1秒后自动消失
  80. * @ignore
  81. * @param {String} message 消息内容
  82. */
  83. export function showTooltipMessage(message) {
  84. let msgMainDom = document.getElementById('messageMainDom');
  85. if (msgMainDom !== null && msgMainDom !== undefined) {
  86. document.body.removeChild(msgMainDom);
  87. }
  88. msgMainDom = document.createElement('div');
  89. msgMainDom.style.width = '30%';
  90. msgMainDom.style.backgroundColor = 'rgba(237, 248, 230, 1.0)';
  91. msgMainDom.style.height = '45px';
  92. msgMainDom.style.border = 'solid 2px rgb(219, 241, 208)';
  93. msgMainDom.style.borderRadius = '8px';
  94. msgMainDom.style.display = 'flex';
  95. msgMainDom.style.alignItems = 'center';
  96. msgMainDom.style.paddingLeft = '10px';
  97. msgMainDom.style.color = 'rgb(91, 188, 48)';
  98. msgMainDom.style.fontSize = '14px';
  99. msgMainDom.style.fontWeight = '600';
  100. msgMainDom.style.position = 'absolute';
  101. msgMainDom.style.left = '35%';
  102. msgMainDom.style.transition = 'transform 1s';
  103. msgMainDom.style.transform = 'translateY(-90px)';
  104. msgMainDom.style.top = '0px';
  105. msgMainDom.style.zIndex = 1000;
  106. document.body.appendChild(msgMainDom);
  107. let strHtml = '';
  108. strHtml += "<div style='"
  109. strHtml += "background-color: rgb(88, 185, 45);";
  110. strHtml += "color: rgb(255, 255, 255);";
  111. strHtml += "height: 24px;";
  112. strHtml += "width: 24px;";
  113. strHtml += "border-radius: 20px;";
  114. strHtml += "display: flex;";
  115. strHtml += "justify-content: center;";
  116. strHtml += "align-items: center;";
  117. strHtml += "font-size: 14px;";
  118. strHtml += "margin-right: 18px;";
  119. strHtml += "'>&#10003</div>";
  120. strHtml += "<div>" + message + "</div>";
  121. msgMainDom.innerHTML = strHtml;
  122. msgMainDom.addEventListener('transitionend', function() {
  123. setTimeout(function() {
  124. document.body.removeChild(msgMainDom);
  125. }, 1000);
  126. }, false);
  127. setTimeout(function() {
  128. msgMainDom.style.transform = 'translateY(50px)';
  129. }, 100)
  130. }