import { FC, useEffect, useState } from "react"; import { Button, Empty, Modal, ModalProps, Table, Tag } from "antd"; import { MaterialType, YES_OR_NO } from "@/types"; import { getBaseURL } from "@dage/service"; import { deleteFileApi, getFileListApi, saveManageFileApi } from "@/api"; import { downloadFile, beforeUpload } from "@/utils"; import { DageFileResponseType, DageLoading, DageTableActions, DageUpload, DageUploadConsumer, DageUploadProvider, DageUploadType, } from "@dage/pc-components"; import classNames from "classnames"; import style from "./index.module.scss"; export interface IndexDetailModalProps extends Omit { id: number; title: string; onCancel?: () => void; onOk?: (val: any) => void; } export const IndexDetailModal: FC = ({ open, id, title, onOk, onCancel, ...rest }) => { const baseUrl = getBaseURL(); const [loading, setLoading] = useState(false); const [list, setList] = useState([]); // 已上传附件映射 const [uploadedFileMap, setUploadedFileMap] = useState< Record >({}); const handleCancel = () => { onCancel?.(); }; const saveManageFile = async ( item: MaterialType, list: DageFileResponseType[] ) => { // @ts-ignore const li = list.filter((i) => i.status === "done" && !i.uploaded); for (let i = 0; i < li.length; i++) { const file = li[i]; if (!file.response) return; await saveManageFileApi({ name: file.name, fileName: file.response.fileName, filePath: file.response.filePath, level: 2, suffix: item.suffix, parentId: item.id, module: "fill-norm", moduleId: id, }); // @ts-ignore file.uploaded = true; } getList(); }; const getList = async () => { try { setLoading(true); const data = await getFileListApi(id, "norm"); setList(data.filter((i) => i.module === "norm")); const temp: typeof uploadedFileMap = {}; data .filter((i) => i.module === "fill-norm") .forEach((item) => { if (!item.parentId) return; if (Array.isArray(temp[item.parentId])) temp[item.parentId].push(item); else temp[item.parentId] = [item]; }); setUploadedFileMap(temp); } finally { setLoading(false); } }; const handleDeleteFile = async (id: number) => { await deleteFileApi(id); getList(); }; useEffect(() => { if (open) getList(); }, [open]); return ( {loading && } {!list.length && } {list.map((item) => { const isUpload = item.isUpload === YES_OR_NO.YES; return (
{isUpload ? "必填" : "选填"}

{item.name} | {item.suffix || "*"}

{(res) => ( )}
( downloadFile( baseUrl + process.env.REACT_APP_IMG_PUBLIC + item.filePath, item.fileName ) } > 下载 } showEdit={false} onDelete={handleDeleteFile.bind(undefined, val.id)} /> ), }, ]} /> ); })} ); };