소스 검색

fix: 创建 clipboard.ts 工具函数文件

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
mengboxin137-blip 7 시간 전
부모
커밋
200df6e383
1개의 변경된 파일17개의 추가작업 그리고 0개의 파일을 삭제
  1. 17 0
      frontend/utils/clipboard.ts

+ 17 - 0
frontend/utils/clipboard.ts

@@ -0,0 +1,17 @@
+export async function copyToClipboard(text: string): Promise<boolean> {
+  try {
+    if (navigator.clipboard?.writeText) {
+      await navigator.clipboard.writeText(text);
+      return true;
+    }
+  } catch {}
+  const textarea = document.createElement('textarea');
+  textarea.value = text;
+  textarea.style.position = 'fixed';
+  textarea.style.opacity = '0';
+  document.body.appendChild(textarea);
+  textarea.select();
+  const ok = document.execCommand('copy');
+  document.body.removeChild(textarea);
+  return ok;
+}