fix: 1.将合同模板和交叉评查中的文件下载改用通过后端api进行转发获取文件来下载。 2.修复登录过程中token认证的代码问题。 3.完善api-config文件中不同端口号不同的回调地址配置。
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
// import { useState } from 'react';
|
||||
import { useNavigate } from '@remix-run/react';
|
||||
// 导入统一的下载方法和提示服务
|
||||
import { downloadFile } from '~/api/axios-client';
|
||||
import { toastService } from '~/components/ui/Toast';
|
||||
|
||||
interface Template {
|
||||
id: string;
|
||||
@@ -29,56 +32,49 @@ export function TemplateCard({ template, onClick }: TemplateCardProps) {
|
||||
setIsFavorited(!isFavorited);
|
||||
}; */
|
||||
|
||||
// MinIO下载URL构建函数
|
||||
const buildDownloadUrl = (filePath: string): string => {
|
||||
// 使用实际的MinIO配置
|
||||
const minioHost = 'http://nas.7bm.co:9000';
|
||||
const bucketName = 'docauditai';
|
||||
|
||||
// 确保文件路径不以/开头
|
||||
const cleanPath = filePath.startsWith('/') ? filePath.substring(1) : filePath;
|
||||
|
||||
return `${minioHost}/${bucketName}/${cleanPath}`;
|
||||
};
|
||||
|
||||
// 下载文件函数
|
||||
const downloadFile = async (filePath: string, fileName: string) => {
|
||||
// 使用统一的下载方法(与 rules-files.tsx 相同)
|
||||
const handleDownloadFile = async (filePath: string, fileName: string) => {
|
||||
try {
|
||||
const downloadUrl = buildDownloadUrl(filePath);
|
||||
|
||||
// 使用axios封装的下载方法
|
||||
const blob = await downloadFile(filePath);
|
||||
|
||||
// 创建Blob URL
|
||||
const blobUrl = URL.createObjectURL(blob);
|
||||
|
||||
// 清理文件名,移除可能导致问题的字符
|
||||
const cleanFileName = fileName.replace(/[<>:"/\\|?*]/g, '_');
|
||||
|
||||
// 创建临时下载链接
|
||||
const link = document.createElement('a');
|
||||
link.href = downloadUrl;
|
||||
link.download = cleanFileName;
|
||||
link.target = '_blank';
|
||||
|
||||
// 触发下载
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
// console.log('开始下载文件:', cleanFileName);
|
||||
|
||||
// 创建一个隐藏的a标签并点击它
|
||||
const a = document.createElement('a');
|
||||
a.style.display = 'none';
|
||||
a.href = blobUrl;
|
||||
a.download = cleanFileName;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// 清理
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(blobUrl);
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
console.error('下载文件失败:', error);
|
||||
alert('下载失败,请稍后重试');
|
||||
toastService.error(`下载文件失败: ${error instanceof Error ? error.message : '未知错误'}`);
|
||||
}
|
||||
};
|
||||
|
||||
const handleActionClick = (e: React.MouseEvent, action: string) => {
|
||||
e.stopPropagation();
|
||||
|
||||
|
||||
switch (action) {
|
||||
case '立即下载':
|
||||
if (template.file_path) {
|
||||
// 构建文件名,使用模板标题和文件格式
|
||||
const fileExtension = template.file_format || 'docx';
|
||||
const fileName = `${template.title}.${fileExtension}`;
|
||||
downloadFile(template.file_path, fileName);
|
||||
handleDownloadFile(template.file_path, fileName);
|
||||
} else {
|
||||
alert('文件路径不存在,无法下载');
|
||||
toastService.error('文件路径不存在,无法下载');
|
||||
}
|
||||
break;
|
||||
case '预览':
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
* 交叉评查文件信息组件
|
||||
*/
|
||||
|
||||
// 导入统一的下载方法和提示服务
|
||||
import { downloadFile } from '~/api/axios-client';
|
||||
import { toastService } from '~/components/ui/Toast';
|
||||
|
||||
interface FileInfoProps {
|
||||
fileInfo: {
|
||||
fileName: string;
|
||||
contractNumber: string;
|
||||
fileSize?: string;
|
||||
fileSize?: string;
|
||||
fileFormat?: string;
|
||||
pageCount?: number;
|
||||
uploadTime?: string;
|
||||
@@ -21,17 +25,36 @@ interface FileInfoProps {
|
||||
|
||||
export function FileInfo({ fileInfo, onConfirmResults }: FileInfoProps) {
|
||||
|
||||
const handleDownloadFile = () => {
|
||||
if (fileInfo.path) {
|
||||
// 创建一个隐藏的下载链接
|
||||
const link = document.createElement('a');
|
||||
link.href = fileInfo.path;
|
||||
link.download = fileInfo.fileName;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
} else {
|
||||
alert('文件路径不存在,无法下载');
|
||||
// 使用统一的下载方法(与 rules-files.tsx 相同)
|
||||
const handleDownloadFile = async () => {
|
||||
if (!fileInfo.path) {
|
||||
toastService.error('文件路径不存在,无法下载');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 使用axios封装的下载方法
|
||||
const blob = await downloadFile(fileInfo.path);
|
||||
|
||||
// 创建Blob URL
|
||||
const blobUrl = URL.createObjectURL(blob);
|
||||
|
||||
// 创建一个隐藏的a标签并点击它
|
||||
const a = document.createElement('a');
|
||||
a.style.display = 'none';
|
||||
a.href = blobUrl;
|
||||
a.download = fileInfo.fileName || 'document';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// 清理
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(blobUrl);
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
console.error('下载文件失败:', error);
|
||||
toastService.error(`下载文件失败: ${error instanceof Error ? error.message : '未知错误'}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user