修复下载,更改logo,优化评查详情内容的显示,修改sidebar的首页,修复文件上传合同的异步上传时序问题,首页最近文件的自动更新文件状态

This commit is contained in:
2025-05-24 23:25:04 +08:00
parent ef6994d072
commit ed3ff4c3b3
10 changed files with 801 additions and 237 deletions
+58 -17
View File
@@ -181,7 +181,7 @@ export async function action({ request }: ActionFunctionArgs) {
// 文档编辑页面组件
export default function DocumentEdit() {
const { document, documentTypes } = useLoaderData<typeof loader>();
const { document: documentData, documentTypes } = useLoaderData<typeof loader>();
const actionData = useActionData<ActionData>();
const navigate = useNavigate();
const [numPages, setNumPages] = useState(0);
@@ -190,10 +190,10 @@ export default function DocumentEdit() {
// 表单状态管理 - 使用受控组件
const [formValues, setFormValues] = useState({
documentNumber: document.documentNumber || "",
auditStatus: document.auditStatus,
isTest: document.isTest || false,
remark: document.remark || ""
documentNumber: documentData.documentNumber || "",
auditStatus: documentData.auditStatus,
isTest: documentData.isTest || false,
remark: documentData.remark || ""
});
// 表单验证错误状态
@@ -303,7 +303,7 @@ export default function DocumentEdit() {
return (
<div className="preview-content relative overflow-y-auto max-h-[1000px]">
<Document
file={DOCUMENT_URL + document.path}
file={DOCUMENT_URL + documentData.path}
onLoadSuccess={onDocumentLoadSuccess}
onLoadError={(error) => {
console.error("PDF加载错误:", error);
@@ -393,9 +393,49 @@ export default function DocumentEdit() {
);
};
// 下载文档
const downloadDocument = async () => {
try {
const downloadUrl = `${DOCUMENT_URL}${documentData.path}`;
// 使用fetch获取文件内容
const response = await fetch(downloadUrl);
if (!response.ok) {
throw new Error(`下载失败: ${response.status} ${response.statusText}`);
}
// 将响应转换为Blob
const blob = await response.blob();
// 创建Blob URL
const blobUrl = URL.createObjectURL(blob);
// 创建一个隐藏的a标签并点击它
const a = document.createElement('a');
a.style.display = 'none';
a.href = blobUrl;
// 从路径中获取文件名
const fileName = documentData.path.split('/').pop() || documentData.name;
a.download = decodeURIComponent(fileName);
document.body.appendChild(a);
a.click();
// 清理
setTimeout(() => {
document.body.removeChild(a);
URL.revokeObjectURL(blobUrl);
}, 100);
toastService.success('文件下载成功');
} catch (error) {
console.error('下载文件失败:', error);
toastService.error(`下载文件失败: ${error instanceof Error ? error.message : '未知错误'}`);
}
};
// 在新窗口打开文档预览
const openPreview = () => {
const previewUrl = `${DOCUMENT_URL}${document.path}`;
const previewUrl = `${DOCUMENT_URL}${documentData.path}`;
window.open(previewUrl, '_blank');
};
@@ -428,7 +468,7 @@ export default function DocumentEdit() {
<div className="document-info">
<div className="document-icon">
<FileTag
extension={document.fileType}
extension={documentData.fileType}
showIcon={true}
showText={false}
showBackground={false}
@@ -436,22 +476,22 @@ export default function DocumentEdit() {
/>
</div>
<div className="document-details">
<div className="document-name">{document.name}</div>
<div className="document-name">{documentData.name}</div>
<div className="document-meta">
<div className="meta-item">
<i className="ri-file-list-line"></i>
<span>{getDocumentTypeName(document.type)}</span>
<span>{getDocumentTypeName(documentData.type)}</span>
</div>
<div className="meta-item">
<i className="ri-time-line"></i>
<span>{document.uploadTime}</span>
<span>{documentData.uploadTime}</span>
</div>
<div className="meta-item">
<i className="ri-hard-drive-line"></i>
<span>{formatFileSize(document.size)}</span>
<span>{formatFileSize(documentData.size)}</span>
</div>
<div className="meta-item">
{renderStatusBadge(document.auditStatus)}
{renderStatusBadge(documentData.auditStatus)}
</div>
</div>
</div>
@@ -477,7 +517,7 @@ export default function DocumentEdit() {
id="type-id"
name="type_id"
className="form-select"
value={document.type}
value={documentData.type}
disabled={true}
required
>
@@ -566,8 +606,8 @@ export default function DocumentEdit() {
<div className="document-preview">
<div className="preview-toolbar">
<div className="flex items-center">
<i className={`ri-file-${document.fileType}-line text-${document.fileType === 'pdf' ? 'red' : 'blue'}-500 mr-1`}></i>
<span>{document.name}</span>
<i className={`ri-file-${documentData.fileType}-line text-${documentData.fileType === 'pdf' ? 'red' : 'blue'}-500 mr-1`}></i>
<span>{documentData.name}</span>
</div>
<div>
<Button
@@ -575,6 +615,7 @@ export default function DocumentEdit() {
size="small"
icon="ri-download-line"
className="mr-2"
onClick={downloadDocument}
>
</Button>
@@ -607,7 +648,7 @@ export default function DocumentEdit() {
time: "2023-10-15 15:30",
user: "系统",
action: "创建了此文档",
details: `首次上传文档,文档类型:${getDocumentTypeName(document.type)},状态:待审核`
details: `首次上传文档,文档类型:${getDocumentTypeName(documentData.type)},状态:待审核`
},
{
time: "2023-10-15 16:45",