| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import { sys } from "cc";
- import { Config, nav_info } from "./NavInfo";
- export class Utils {
- public static copyToZone(str: string, target:any, func:Function) {
- // let input:any = document.createElement("input");
- // let currentFocus:any = document.activeElement;
- // document.body.appendChild(input);
- // input.readOnly = 'readonly';
- // input.value = str;
- // input.focus();
- // if (input.setSelectionRange)
- // input.setSelectionRange(0, input.value.length);
- // else
- // input.select();
- // let flag = true;
- // try {
- // document.execCommand("copy");
- // }
- // catch (eo) {
- // flag = false;
- // }
- // input.blur();
- // document.body.removeChild(input);
- // currentFocus.focus();
- // currentFocus.blur();
- // return flag;
- if (!navigator.clipboard) {
- // 如果当前浏览器不支持 Clipboard API,则使用 execCommand 方法
- var textArea = document.createElement("textarea");
- textArea.value = str;
- textArea.style.position = "fixed";
- document.body.appendChild(textArea);
- textArea.select();
- let flag = true;
- try {
- document.execCommand("copy");
- }
- catch (err) {
- flag = false;
- }
- func.call(target, flag);
- document.body.removeChild(textArea);
- return;
- }
- navigator.clipboard.writeText(str)
- .then(() => {
- func.call(target, true);
- })
- .catch((err) => {
- func.call(target, false);
- });
- }
- public static tryStartApp() {
- if(!sys.isMobile){
- // nav_info.scene.showTip("")
- return;
- }
- console.log("openSrc =", Config.scheme_prefix);
- window.location.href = Config.scheme_prefix;
- setTimeout(function () {
- if (!document.hidden) {
- let down_url = sys.platform == sys.Platform.IOS ? Config.download_ios_url : Config.downlaod_google_url;
- window.location.href = down_url;
- }
- }, 4000);
- }
- }
|