From 83e4f017e9966903903ad9d24a74080b85f01a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E6=9D=B0?= Date: Thu, 24 Apr 2025 09:17:16 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E6=B7=BB=E5=8A=A0=20Vite=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 vite.config.ts 文件 - 配置 Vue、TailwindCSS 和 Autoprefixer插件 - 设置别名路径和 CSS 处理方式 --- src/utils/clipboard.ts | 47 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/utils/clipboard.ts b/src/utils/clipboard.ts index 11b1f62..426cc06 100644 --- a/src/utils/clipboard.ts +++ b/src/utils/clipboard.ts @@ -82,11 +82,52 @@ export const copyRetrieveCode = async (code: string): Promise => { const baseUrl = window.location.origin + '/#/'; -export const copyWgetCommand = (retrieveCode: string, fileName: any) => { - const command = `wget ${baseUrl}?code=${retrieveCode} -O "${fileName}"`; +/*export const copyWgetCommand = (retrieveCode: string, fileName: any) => { + //wget https://share.lanol.cn/share/select?code=17634 + const command = `wget ${baseUrl}share/select?code=${retrieveCode} -O "${fileName}"`; navigator.clipboard.writeText(command).then(() => { alertStore.showAlert('wget命令已复制到剪贴板', 'success'); }).catch(() => { alertStore.showAlert('复制wget命令失败', 'error'); }); -}; \ No newline at end of file +};*/ + +export const copyWgetCommand = (retrieveCode: string, fileName: string) => { + // const command = `wget ${window.location.origin}/download/${retrieveCode} -O ${filename}`; + const command = `wget ${baseUrl}share/select?code=${retrieveCode} -O "${fileName}"`; + + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(command) + .then(() => { + console.log("命令已复制到剪贴板!"); + }) + .catch((err) => { + console.error("复制失败,使用回退方法:", err); + fallbackCopyTextToClipboard(command); + }); + } else { + console.warn("Clipboard API 不可用,使用回退方法。"); + fallbackCopyTextToClipboard(command); + } +}; +function fallbackCopyTextToClipboard(text:string) { + const textArea = document.createElement("textarea"); + textArea.value = text; + textArea.style.position = "fixed"; // 避免滚动 + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + try { + const successful = document.execCommand("copy"); + console.log("回退复制操作成功:", successful); + } catch (err) { + console.error("回退复制操作失败:", err); + } + document.body.removeChild(textArea); +} + +if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText("要复制的文本"); +} else { + fallbackCopyTextToClipboard("要复制的文本"); +} \ No newline at end of file