import React, { useState, useEffect, useRef } from 'react' import { Form, Button, Input, Row, Upload, Col, Table, DatePicker, InputNumber, message, Image, Modal, Typography, Select } from 'antd'; import { DeleteOutlined, FileWordOutlined, FilePdfOutlined, FileZipOutlined, FileExcelOutlined } from '@ant-design/icons'; import moment from 'moment' import apiurl from '../../../service/apiurl'; import PdfView from './pdfView'; // import './index.less' const FileView = ({mode, fileList, setFileList}) => { const childRef = useRef(null); const download = (params) => { let downloadLink = document.createElement("a"); downloadLink.href = process.env.REACT_APP_API_URL+apiurl.file.download+params downloadLink.download = `${params.fileName}`; downloadLink.style.display = "none"; // 将链接添加到页面中 document.body.appendChild(downloadLink); // 模拟点击事件,开始下载 downloadLink.click(); } const deleteFile = (fileId) => { let filterFile = fileList.filter(item => item.response?.data?.fileId !== fileId); setFileList(filterFile) } const viewPdf = (params) => { if (childRef.current) { childRef.current.callChildMethod(params); } } return ( <> { fileList.map(file=>(
{ (()=>{ if(file.name.indexOf('.doc') > -1){ return (
{ download(file.response?.data?.fileId) }} style={{ cursor: 'pointer' }} >
) }else if(file.name.indexOf('.pdf') > -1){ return (
{ viewPdf(file.response?.data?.fileId) }} style={{ cursor: 'pointer' }} >
) }else if(file.name.indexOf('.zip') > -1){ return (
{ download(file.response?.data?.fileId) }} style={{ cursor: 'pointer' }} >
) }else if(file.name.indexOf('.xls') > -1){ return (
{ download(file.response?.data?.fileId) }} style={{ cursor: 'pointer' }} >
) }else{ return ( ) } })() } {file.name}
{ deleteFile(file.response?.data?.fileId) }}>
)) }
) } export default FileView