Utils.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { sys } from "cc";
  2. import { Config, nav_info } from "./NavInfo";
  3. export class Utils {
  4. public static copyToZone(str: string, target:any, func:Function) {
  5. // let input:any = document.createElement("input");
  6. // let currentFocus:any = document.activeElement;
  7. // document.body.appendChild(input);
  8. // input.readOnly = 'readonly';
  9. // input.value = str;
  10. // input.focus();
  11. // if (input.setSelectionRange)
  12. // input.setSelectionRange(0, input.value.length);
  13. // else
  14. // input.select();
  15. // let flag = true;
  16. // try {
  17. // document.execCommand("copy");
  18. // }
  19. // catch (eo) {
  20. // flag = false;
  21. // }
  22. // input.blur();
  23. // document.body.removeChild(input);
  24. // currentFocus.focus();
  25. // currentFocus.blur();
  26. // return flag;
  27. if (!navigator.clipboard) {
  28. // 如果当前浏览器不支持 Clipboard API,则使用 execCommand 方法
  29. var textArea = document.createElement("textarea");
  30. textArea.value = str;
  31. textArea.style.position = "fixed";
  32. document.body.appendChild(textArea);
  33. textArea.select();
  34. let flag = true;
  35. try {
  36. document.execCommand("copy");
  37. }
  38. catch (err) {
  39. flag = false;
  40. }
  41. func.call(target, flag);
  42. document.body.removeChild(textArea);
  43. return;
  44. }
  45. navigator.clipboard.writeText(str)
  46. .then(() => {
  47. func.call(target, true);
  48. })
  49. .catch((err) => {
  50. func.call(target, false);
  51. });
  52. }
  53. public static tryStartApp() {
  54. if(!sys.isMobile){
  55. // nav_info.scene.showTip("")
  56. return;
  57. }
  58. console.log("openSrc =", Config.scheme_prefix);
  59. window.location.href = Config.scheme_prefix;
  60. setTimeout(function () {
  61. if (!document.hidden) {
  62. let down_url = sys.platform == sys.Platform.IOS ? Config.download_ios_url : Config.downlaod_google_url;
  63. window.location.href = down_url;
  64. }
  65. }, 4000);
  66. }
  67. }