From 5ccfe04a1dccb1d360685f61cfc2a4931bf555d5 Mon Sep 17 00:00:00 2001 From: Lan Date: Fri, 4 Jul 2025 23:45:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=9B=E5=85=A5=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=81=9A=E7=84=A6=E8=BE=93=E5=85=A5=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/clipboard.ts | 9 ++---- src/views/RetrievewFileView.vue | 57 +++------------------------------ 2 files changed, 7 insertions(+), 59 deletions(-) diff --git a/src/utils/clipboard.ts b/src/utils/clipboard.ts index 7c03a94..fdc9ca2 100644 --- a/src/utils/clipboard.ts +++ b/src/utils/clipboard.ts @@ -3,7 +3,6 @@ */ import { useAlertStore } from '@/stores/alertStore' -const alertStore = useAlertStore(); interface CopyOptions { successMsg?: string errorMsg?: string @@ -21,17 +20,14 @@ export const copyToClipboard = async ( options: CopyOptions = {} ): Promise => { const { successMsg = '复制成功', errorMsg = '复制失败,请手动复制', showMsg = true } = options - const alertStore = useAlertStore() - try { // 优先使用 Clipboard API - if (navigator.clipboard && navigator.clipboard.writeText) { + if (document.hasFocus() && navigator.clipboard && navigator.clipboard.writeText) { await navigator.clipboard.writeText(text) if (showMsg) alertStore.showAlert(successMsg, 'success') return true } - // 后备方案:使用传统的复制方法 const textarea = document.createElement('textarea') textarea.value = text @@ -41,7 +37,6 @@ export const copyToClipboard = async ( textarea.select() const success = document.execCommand('copy') document.body.removeChild(textarea) - if (success) { if (showMsg) alertStore.showAlert(successMsg, 'success') return true @@ -115,7 +110,7 @@ function fallbackCopyTextToClipboard(text:string) { document.body.removeChild(textArea); } -if (navigator.clipboard && navigator.clipboard.writeText) { +if (document.hasFocus() && navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText("要复制的文本"); } else { fallbackCopyTextToClipboard("要复制的文本"); diff --git a/src/views/RetrievewFileView.vue b/src/views/RetrievewFileView.vue index 13a9575..5c2d8b5 100644 --- a/src/views/RetrievewFileView.vue +++ b/src/views/RetrievewFileView.vue @@ -26,8 +26,8 @@
- 文件内容:

-
+