From 2910951c219a74361726ad5ed11ff3bccb144cf3 Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Tue, 13 May 2025 15:46:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E7=AB=AF=E5=BF=AB=E6=8D=B7=E6=8C=87=E4=BB=A4=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=A4=87=E7=94=A8=E5=A4=8D=E5=88=B6=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend/src/views/QuickCommandsView.vue | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/frontend/src/views/QuickCommandsView.vue b/packages/frontend/src/views/QuickCommandsView.vue index 8a193e3..c9e6e5c 100644 --- a/packages/frontend/src/views/QuickCommandsView.vue +++ b/packages/frontend/src/views/QuickCommandsView.vue @@ -432,8 +432,27 @@ const copyCommand = async (command: string) => { await navigator.clipboard.writeText(command); uiNotificationsStore.showSuccess(t('commandHistory.copied', '已复制到剪贴板')); } catch (err) { - console.error('复制命令失败:', err); - uiNotificationsStore.showError(t('commandHistory.copyFailed', '复制失败')); + console.error('使用Clipboard API复制命令失败:', err); + // 备用方案:使用临时文本区域和execCommand + try { + const textarea = document.createElement('textarea'); + textarea.value = command; + textarea.style.position = 'fixed'; // 避免滚动到页面底部 + textarea.style.opacity = '0'; // 隐藏文本区域 + document.body.appendChild(textarea); + textarea.focus(); + textarea.select(); + const successful = document.execCommand('copy'); + document.body.removeChild(textarea); + if (successful) { + uiNotificationsStore.showSuccess(t('commandHistory.copied', '已复制到剪贴板')); + } else { + uiNotificationsStore.showError(t('commandHistory.copyFailed', '复制失败')); + } + } catch (fallbackErr) { + console.error('备用复制方法也失败:', fallbackErr); + uiNotificationsStore.showError(t('commandHistory.copyFailed', '复制失败')); + } } };