提交修改

This commit is contained in:
zlwu committed 2025-08-03 17:38:03 +08:00
1 parent 1e361a44ca
commit ac8a58386c
10 files changed
+765 -33

No files matched your search

+64 -3
View File
@@ -33,11 +33,12 @@
<!-- 文件列表 -->
<transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul">
<li v-for="(file, index) in fileList" :key="file.uid" class="el-upload-list__item ele-upload-list__item-content">
<el-link :href="`${file.url}`" :underline="false" target="_blank">
<span class="el-icon-document"> {{ getFileName(file.name) }} </span>
</el-link>
<!-- <el-link :href="`${file.url}`" :underline="false" target="_blank"> -->
<span class="el-icon-document"> {{ getFileName(file.name) }} </span>
<!-- </el-link> -->
<div class="ele-upload-list__item-content-action">
<el-button type="danger" v-if="!disabled" link @click="handleDelete(index)">删除</el-button>
<el-button type="danger" v-if="!disabled" link @click="handleDownloadAttachment(file)">下载</el-button>
</div>
</li>
</transition-group>
@@ -48,6 +49,8 @@
import { propTypes } from '@/utils/propTypes';
import { delOss, listByIds } from '@/api/system/oss';
import { globalHeaders } from '@/utils/request';
import request from '@/utils/request';
import { vLoading, ElLoading } from 'element-plus';
const props = defineProps({
modelValue: {
@@ -116,6 +119,64 @@ watch(
{ deep: true, immediate: true }
);
/** 下载附件 */
const handleDownloadAttachment = async (file: any) => {
let downloadUrl = file.ossId;
let fileName = file.name || 'attachment';
if (!downloadUrl) {
proxy?.$modal.msgError('无法获取文件下载地址');
return;
}
// 对于服务器文件,使用fetch获取内容强制下载
try {
const loading = ElLoading.service({
text: '正在下载文件...',
target: document.body
});
// const response = await fetch(downloadUrl);
// if (!response.ok) {
// throw new Error(`HTTP error! status: ${response.status}`);
// }
// 通过fetch获取文件内容,强制下载
// const response = await req('/resource/oss/download/' + attachment.filePath);
const response = await request({
url: '/resource/oss/download/' + downloadUrl,
method: 'get',
responseType: 'blob',
timeout: 300000 // 300秒超时
});
// 由于axios响应拦截器对blob类型响应直接返回blob数据
// 这里response直接就是blob对象,而不是包含data属性的响应对象
const blob = response;
// 验证响应数据
if (!blob) {
throw new Error('响应数据为空');
}
// const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = fileName;
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
loading?.close();
console.log('下载服务器文件成功:', fileName);
} catch (error) {
console.error('下载文件失败:', error);
proxy?.$modal.msgError('下载文件失败,请稍后重试');
}
};
// 上传前校检格式和大小
const handleBeforeUpload = (file: any) => {
// 校检文件类型
+1 -1
View File
@@ -160,7 +160,7 @@ const getPreviewImageBlobUrl = async (imageUrl: string): Promise<string> => {
url: imageUrl,
method: 'get',
responseType: 'blob',
timeout: 30000 // 30秒超时
timeout: 300000 // 300秒超时
});
// 由于request响应拦截器对blob类型响应直接返回blob数据
@@ -44,7 +44,7 @@
<el-table-column prop="originalName" width="202" :show-overflow-tooltip="true" label="附件名称"></el-table-column>
<el-table-column prop="name" width="80" align="center" :show-overflow-tooltip="true" label="操作">
<template #default="tool">
<el-button type="text" @click="handleDownload(tool.row.ossId)">下载</el-button>
<el-button type="text" @click="handleDownload(tool.row.ossId, tool.row.originalName)">下载</el-button>
</template>
</el-table-column>
</el-table>
@@ -106,8 +106,9 @@ const getIds = async (ids: string | number) => {
};
/** 下载按钮操作 */
const handleDownload = (ossId: string) => {
proxy?.$download.oss(ossId);
const handleDownload = (ossId: string, originalName: string) => {
console.log(ossId);
proxy?.$download.secureOss(ossId, originalName);
};
/**