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'
|
import { useAlertStore } from '@/stores/alertStore'
|
||||||
|
const alertStore = useAlertStore();
|
||||||
interface CopyOptions {
|
interface CopyOptions {
|
||||||
successMsg?: string
|
successMsg?: string
|
||||||
errorMsg?: string
|
errorMsg?: string
|
||||||
@@ -80,10 +80,13 @@ export const copyRetrieveCode = async (code: string): Promise<boolean> => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const copyWgetCommand = async (code: string): Promise<boolean> => {
|
const baseUrl = window.location.origin + '/#/';
|
||||||
const command = `wget ${window.location.origin}/share/select?code=${code}`
|
|
||||||
return copyToClipboard(command, {
|
export const copyWgetCommand = (retrieveCode: string, fileName: any) => {
|
||||||
successMsg: 'wget命令已复制到剪贴板',
|
const command = `wget ${baseUrl}?code=${retrieveCode} -O "${fileName}"`;
|
||||||
errorMsg: '复制失败,请手动复制wget命令'
|
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" />
|
<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>
|
<span class="truncate">wget下载</span>
|
||||||
</h4>
|
</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">
|
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"
|
<ClipboardCopyIcon class="w-4 h-4 sm:w-5 sm:h-5"
|
||||||
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']" />
|
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']" />
|
||||||
|
|||||||
Reference in New Issue
Block a user