|
@@ -11,12 +11,13 @@ function lt(obj) {
|
|
function deepClone(obj) {
|
|
function deepClone(obj) {
|
|
return JSON.parse(JSON.stringify(obj))
|
|
return JSON.parse(JSON.stringify(obj))
|
|
}
|
|
}
|
|
|
|
+
|
|
function debounce(fn, wait = 50) {
|
|
function debounce(fn, wait = 50) {
|
|
// 通过闭包缓存一个定时器 id
|
|
// 通过闭包缓存一个定时器 id
|
|
let timer = null
|
|
let timer = null
|
|
// 将 debounce 处理结果当作函数返回
|
|
// 将 debounce 处理结果当作函数返回
|
|
// 触发事件回调时执行这个返回函数
|
|
// 触发事件回调时执行这个返回函数
|
|
- return function(...args) {
|
|
|
|
|
|
+ return function (...args) {
|
|
// 如果已经设定过定时器就清空上一次的定时器
|
|
// 如果已经设定过定时器就清空上一次的定时器
|
|
if (timer) clearTimeout(timer)
|
|
if (timer) clearTimeout(timer)
|
|
|
|
|
|
@@ -363,6 +364,36 @@ const copyUtil = {
|
|
} catch (err) {
|
|
} catch (err) {
|
|
console.error('复制失败', err);
|
|
console.error('复制失败', err);
|
|
}
|
|
}
|
|
|
|
+ },
|
|
|
|
+ copyText: async function (text) {
|
|
|
|
+ if (navigator.clipboard) {
|
|
|
|
+ // clipboard api 复制
|
|
|
|
+ await navigator.clipboard.writeText(text);
|
|
|
|
+ } else {
|
|
|
|
+ const textarea = document.createElement('textarea');
|
|
|
|
+ document.body.appendChild(textarea);
|
|
|
|
+ // 隐藏此输入框
|
|
|
|
+ textarea.style.position = 'fixed';
|
|
|
|
+ textarea.style.clip = 'rect(0 0 0 0)';
|
|
|
|
+ textarea.style.top = '10px';
|
|
|
|
+ // 赋值
|
|
|
|
+ textarea.value = text;
|
|
|
|
+ // 选中
|
|
|
|
+ textarea.select();
|
|
|
|
+ // 复制
|
|
|
|
+ document.execCommand('copy', true);
|
|
|
|
+ // 移除输入框
|
|
|
|
+ document.body.removeChild(textarea);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ getClipboardText: async function () {
|
|
|
|
+ try {
|
|
|
|
+ const text = await navigator.clipboard.readText();
|
|
|
|
+ console.log("剪贴板内容:", text);
|
|
|
|
+ return text;
|
|
|
|
+ } catch (err) {
|
|
|
|
+ console.error("无法读取剪贴板内容:", err);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -399,14 +430,16 @@ async function convertToWebPAsync(base64Image) {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-function closeWindow(){
|
|
|
|
|
|
+function closeWindow() {
|
|
const userAgent = navigator.userAgent;
|
|
const userAgent = navigator.userAgent;
|
|
- if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1) {
|
|
|
|
- window.location.href="about:blank";
|
|
|
|
|
|
+ if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") != -1) {
|
|
|
|
+ window.location.href = "about:blank";
|
|
window.close();
|
|
window.close();
|
|
} else {
|
|
} else {
|
|
window.opener = null;
|
|
window.opener = null;
|
|
window.open("", "_self");
|
|
window.open("", "_self");
|
|
window.close();
|
|
window.close();
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|