From 71d8030c0e9468e91c12b23d245486e1cc30aead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E6=9D=B0?= Date: Wed, 23 Apr 2025 16:45:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(utils):=20=E4=BC=98=E5=8C=96=20wget?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E5=A4=8D=E5=88=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构 copyWgetCommand 函数,使用 navigator.clipboard API 替代原实现 - 添加文件名参数,使 wget 命令更加完整 - 使用全局 alertStore 显示复制成功或失败的提示信息- 在 SendFileView 中更新 wget 命令复制按钮的点击事件处理 --- src/utils/clipboard.ts | 19 +++++++++++-------- src/views/SendFileView.vue | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/utils/clipboard.ts b/src/utils/clipboard.ts index 249f097..11b1f62 100644 --- a/src/utils/clipboard.ts +++ b/src/utils/clipboard.ts @@ -3,7 +3,7 @@ */ import { useAlertStore } from '@/stores/alertStore' - +const alertStore = useAlertStore(); interface CopyOptions { successMsg?: string errorMsg?: string @@ -80,10 +80,13 @@ export const copyRetrieveCode = async (code: string): Promise => { }) } -export const copyWgetCommand = async (code: string): Promise => { - const command = `wget ${window.location.origin}/share/select?code=${code}` - return copyToClipboard(command, { - successMsg: 'wget命令已复制到剪贴板', - errorMsg: '复制失败,请手动复制wget命令' - }) -} \ No newline at end of file +const baseUrl = window.location.origin + '/#/'; + +export const copyWgetCommand = (retrieveCode: string, fileName: any) => { + const command = `wget ${baseUrl}?code=${retrieveCode} -O "${fileName}"`; + navigator.clipboard.writeText(command).then(() => { + alertStore.showAlert('wget命令已复制到剪贴板', 'success'); + }).catch(() => { + alertStore.showAlert('复制wget命令失败', 'error'); + }); +}; \ No newline at end of file diff --git a/src/views/SendFileView.vue b/src/views/SendFileView.vue index 36aa50e..7800375 100644 --- a/src/views/SendFileView.vue +++ b/src/views/SendFileView.vue @@ -339,7 +339,7 @@ wget下载 -