|
@@ -2,29 +2,55 @@ import { sys } from "cc";
|
|
|
import { Config, nav_info } from "./NavInfo";
|
|
import { Config, nav_info } from "./NavInfo";
|
|
|
|
|
|
|
|
export class Utils {
|
|
export class Utils {
|
|
|
- public static copyToZone(str: string) {
|
|
|
|
|
- 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;
|
|
|
|
|
|
|
+ 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;
|
|
|
}
|
|
}
|
|
|
- input.blur();
|
|
|
|
|
- document.body.removeChild(input);
|
|
|
|
|
- currentFocus.focus();
|
|
|
|
|
- currentFocus.blur();
|
|
|
|
|
- return flag;
|
|
|
|
|
|
|
+ navigator.clipboard.writeText(str)
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ func.call(target, true);
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch((err) => {
|
|
|
|
|
+ func.call(target, false);
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static tryStartApp() {
|
|
public static tryStartApp() {
|