From 54c6e6ade4d23e4cf23d00951309157fb9ff719c Mon Sep 17 00:00:00 2001 From: zicorn Date: Thu, 16 Jan 2025 21:40:17 +0800 Subject: [PATCH] =?UTF-8?q?[bugfix]=E4=BF=AE=E5=A4=8Dcopy=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/berry/src/utils/common.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/web/berry/src/utils/common.js b/web/berry/src/utils/common.js index bd85f8bf..a329cc56 100644 --- a/web/berry/src/utils/common.js +++ b/web/berry/src/utils/common.js @@ -236,12 +236,24 @@ export function getChannelModels(type) { } export function copy(text, name = '') { - try { - navigator.clipboard.writeText(text); - } catch (error) { - text = `复制${name}失败,请手动复制:

${text}`; - enqueueSnackbar(, getSnackbarOptions('COPY')); - return; + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(text).then(() => { + showNotice(`复制${name}成功!`, true); + }, () => { + text = `复制${name}失败,请手动复制:

${text}`; + enqueueSnackbar(, getSnackbarOptions('COPY')); + }); + } else { + const textArea = document.createElement("textarea"); + textArea.value = text; + document.body.appendChild(textArea); + textArea.select(); + try { + document.execCommand('copy'); + showNotice(`复制${name}成功!`, true); + } catch (err) { + text = `复制${name}失败,请手动复制:

${text}`; + enqueueSnackbar(, getSnackbarOptions('COPY')); + } + document.body.removeChild(textArea); } - showSuccess(`复制${name}成功!`); -}