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');
|
||||
});
|
||||
};
|
||||
@@ -339,7 +339,7 @@
|
||||
<TerminalIcon class="w-4 h-4 sm:w-5 sm:h-5 mr-1.5 sm:mr-2 text-indigo-500 flex-shrink-0" />
|
||||
<span class="truncate">wget下载</span>
|
||||
</h4>
|
||||
<button @click="copyWgetCommand(selectedRecord.retrieveCode)"
|
||||
<button @click="copyWgetCommand(selectedRecord.retrieveCode,selectedRecord.filename)"
|
||||
class="p-1.5 sm:p-2 rounded-full hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors flex-shrink-0">
|
||||
<ClipboardCopyIcon class="w-4 h-4 sm:w-5 sm:h-5"
|
||||
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']" />
|
||||
|
||||
Reference in New Issue
Block a user