From 2b7ea0754d4f627a7811917b0a832555e34814e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=BA=A2=E5=85=B5?= <374362909@qq.com> Date: Sun, 15 Mar 2026 14:27:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=90=86=E6=9C=BA?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/purchase/purchaseagent/index.vue | 43 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/src/views/purchase/purchaseagent/index.vue b/src/views/purchase/purchaseagent/index.vue index ca54c22..92f70ca 100644 --- a/src/views/purchase/purchaseagent/index.vue +++ b/src/views/purchase/purchaseagent/index.vue @@ -362,13 +362,8 @@ const handleResetPassword = async (row: any) => { type: 'success', beforeClose: (action, instance, done) => { if (action === 'confirm') { - navigator.clipboard.writeText(copyText).then(() => { - useMessage().success('已复制到剪贴板'); - done(); - }).catch(() => { - useMessage().error('复制失败,请手动复制'); - done(); - }); + copyToClipboard(copyText); + done(); } else { done(); } @@ -379,6 +374,40 @@ const handleResetPassword = async (row: any) => { useMessage().error(err?.msg || err?.message || '重置密码失败'); } }; + +/** + * 复制文本到剪贴板(兼容HTTP环境) + */ +const copyToClipboard = (text: string) => { + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(text).then(() => { + useMessage().success('已复制到剪贴板'); + }).catch(() => { + fallbackCopy(text); + }); + } else { + fallbackCopy(text); + } +}; + +/** + * 降级复制方法 + */ +const fallbackCopy = (text: string) => { + const textarea = document.createElement('textarea'); + textarea.value = text; + textarea.style.position = 'fixed'; + textarea.style.left = '-9999px'; + document.body.appendChild(textarea); + textarea.select(); + try { + document.execCommand('copy'); + useMessage().success('已复制到剪贴板'); + } catch { + useMessage().error('复制失败,请手动复制'); + } + document.body.removeChild(textarea); +};