feat(utils): 优化 wget命令复制功能
- 重构 copyWgetCommand 函数,使用 navigator.clipboard API 替代原实现 - 添加文件名参数,使 wget 命令更加完整 - 使用全局 alertStore 显示复制成功或失败的提示信息- 在 SendFileView 中更新 wget 命令复制按钮的点击事件处理
This commit is contained in:
+11
-8
@@ -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<boolean> => {
|
||||
})
|
||||
}
|
||||
|
||||
export const copyWgetCommand = async (code: string): Promise<boolean> => {
|
||||
const command = `wget ${window.location.origin}/share/select?code=${code}`
|
||||
return copyToClipboard(command, {
|
||||
successMsg: 'wget命令已复制到剪贴板',
|
||||
errorMsg: '复制失败,请手动复制wget命令'
|
||||
})
|
||||
}
|
||||
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');
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user