From 8f5f2e96b391ad5040728d2b5641bce613645397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=89=E5=B8=86?= <1048766504@qq.com> Date: Fri, 12 Dec 2025 08:47:29 +0000 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E3=80=91=E6=96=87=E4=BB=B6=E5=88=97=E8=A1=A8:=20=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E9=93=BE=E6=8E=A5=E5=8A=9F=E8=83=BD=E5=9C=A8=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=B5=8F=E8=A7=88=E5=99=A8=E7=8E=AF=E5=A2=83=E4=B8=8B?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98=20=E5=9C=A8=20nav?= =?UTF-8?q?igator.clipboard=20=E4=B8=BA=20undefined=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=97=A0=E6=B3=95=E8=AF=BB=E5=8F=96=20writeText=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E6=B5=8F=E8=A7=88=E5=99=A8=E6=8A=9B?= =?UTF-8?q?=E5=87=BA=E5=BC=82=E5=B8=B8=EF=BC=9A=20Uncaught=20TypeError:=20?= =?UTF-8?q?Cannot=20read=20properties=20of=20undefined=20(reading=20'write?= =?UTF-8?q?Text')?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 光帆 <1048766504@qq.com> --- src/views/infra/file/index.vue | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/views/infra/file/index.vue b/src/views/infra/file/index.vue index 901139180..a0c9e258b 100644 --- a/src/views/infra/file/index.vue +++ b/src/views/infra/file/index.vue @@ -187,9 +187,29 @@ const openForm = () => { /** 复制到剪贴板方法 */ const copyToClipboard = (text: string) => { - navigator.clipboard.writeText(text).then(() => { - message.success('复制成功') - }) + if (navigator.clipboard && window.isSecureContext) { + navigator.clipboard + .writeText(text) + .then(() => { + message.success('复制成功') + }) + .catch(() => { + message.error('复制失败') + }) + } else { + // 兼容不支持 clipboard 的情况 + try { + const textarea = document.createElement('textarea') + textarea.value = text + document.body.appendChild(textarea) + textarea.select() + document.execCommand('copy') + document.body.removeChild(textarea) + message.success('复制成功') + } catch (error) { + message.error('复制失败') + } + } } /** 删除按钮操作 */ -- Gitee