|
@@ -231,16 +231,50 @@ const handleDownload = async (row: Media, type: 'media' | 'hash') => {
|
|
|
if (type === 'media') {
|
|
|
if (row.downUrl) {
|
|
|
url = row.downUrl;
|
|
|
+ fileName = `${row.fileName}.${row.fileFormat}` || `file_${row.id} `
|
|
|
} else {
|
|
|
// 通过接口获取URL
|
|
|
url = await downloadMedia(row.id);
|
|
|
+ fileName = url.split('/').pop() || `file_${row.id}`;
|
|
|
if (!url) {
|
|
|
ElMessage.error('获取下载链接失败');
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- fileName = `${row.fileName}.${row.fileFormat}` || url.split('/').pop() || `file_${row.id}`;
|
|
|
+
|
|
|
+ // 判断文件类型
|
|
|
+ const isMediaFile = ['0', '1', '2', 0, 1, 2].includes(row.fileType); // 0:图片, 1:视频, 2:音频
|
|
|
+ ElMessage.success('正在下载文件...')
|
|
|
+ if (isMediaFile) {
|
|
|
+ // 对于媒体文件(图片、视频、音频)使用blob下载
|
|
|
+ try {
|
|
|
+ // 使用fetch获取文件内容
|
|
|
+ const response = await fetch(url);
|
|
|
+ const blob = await response.blob();
|
|
|
+
|
|
|
+ // 创建Blob URL
|
|
|
+ const blobUrl = window.URL.createObjectURL(blob);
|
|
|
+
|
|
|
+ // 创建下载链接
|
|
|
+ const link = document.createElement('a');
|
|
|
+ link.href = blobUrl;
|
|
|
+ link.setAttribute('download', fileName);
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+
|
|
|
+ // 清理
|
|
|
+ document.body.removeChild(link);
|
|
|
+ window.URL.revokeObjectURL(blobUrl);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('媒体文件下载失败:', error);
|
|
|
+ ElMessage.error('媒体文件下载失败');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 对于其他类型文件,直接打开链接下载
|
|
|
+ window.open(url);
|
|
|
+ }
|
|
|
} else {
|
|
|
+ // Hash文件下载
|
|
|
if (row.hashUrl) {
|
|
|
url = row.hashUrl;
|
|
|
} else {
|
|
@@ -252,26 +286,32 @@ const handleDownload = async (row: Media, type: 'media' | 'hash') => {
|
|
|
}
|
|
|
}
|
|
|
fileName = `${row.fileName || 'file'}.txt`;
|
|
|
+
|
|
|
+ // Hash文件通常是文本文件,使用blob下载
|
|
|
+ try {
|
|
|
+ // 使用fetch获取文件内容
|
|
|
+ const response = await fetch(url);
|
|
|
+ const blob = await response.blob();
|
|
|
+
|
|
|
+ // 创建Blob URL
|
|
|
+ const blobUrl = window.URL.createObjectURL(blob);
|
|
|
+
|
|
|
+ // 创建下载链接
|
|
|
+ const link = document.createElement('a');
|
|
|
+ link.href = blobUrl;
|
|
|
+ link.setAttribute('download', fileName);
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+
|
|
|
+ // 清理
|
|
|
+ document.body.removeChild(link);
|
|
|
+ window.URL.revokeObjectURL(blobUrl);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Hash文件下载失败:', error);
|
|
|
+ ElMessage.error('Hash文件下载失败');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // 使用fetch获取文件内容
|
|
|
- const response = await fetch(url);
|
|
|
- const blob = await response.blob();
|
|
|
-
|
|
|
- // 创建Blob URL
|
|
|
- const blobUrl = window.URL.createObjectURL(blob);
|
|
|
-
|
|
|
- // 创建下载链接
|
|
|
- const link = document.createElement('a');
|
|
|
- link.href = blobUrl;
|
|
|
- link.setAttribute('download', fileName);
|
|
|
- document.body.appendChild(link);
|
|
|
- link.click();
|
|
|
-
|
|
|
- // 清理
|
|
|
- document.body.removeChild(link);
|
|
|
- window.URL.revokeObjectURL(blobUrl);
|
|
|
-
|
|
|
ElMessage.success(type === 'media' ? '下载成功' : 'Hash下载成功');
|
|
|
} catch (error) {
|
|
|
console.error(type === 'media' ? '下载失败:' : 'Hash下载失败:', error);
|