import React, { useEffect,useState } from 'react'; import { Form, Upload, Button,Row, Col, Select, Badge, message,Modal } from 'antd'; import {RightOutlined,LeftOutlined,FileExcelOutlined,DeleteOutlined} from '@ant-design/icons'; import moment from 'moment'; import { createCrudService } from '../../../components/crud/_'; import apiurl from '../../../service/apiurl'; import { httppost5 } from '../../../utils/request'; import { exportFile } from '../../../utils/tools'; const { Dragger } = Upload; const ToolBar = ({ value, onChange, tm, callback,role }) => { const exportBtn = role?.rule?.find(item => item.menuName == "导入"); const [yearRange,setYearRange] = useState([]) const [monthRange,setMonthRange] = useState([]) const [form] = Form.useForm(); const [exportOPen, setExportOPen] = useState(false) const [fileList, setFileList] = useState([]) //上传文件列表 const [loading, setLoading] = useState(false) useEffect(()=>{ getDefaultValue() },[]) const deleteFile = (fileId) => { let filterFile = fileList.filter(item => item.response?.data?.fileId !== fileId); setFileList(filterFile) } const beforeUpload = (file) => { const accept = [".xlsx",".xls"] const fileType = file?.name.split("."); const fileDate = fileType.slice(-1); const isEecel = accept.includes(`.${fileDate[0]}`) if (!isEecel) { message.error('请上传.xls .xlsx格式的文件!'); } return isEecel ? true : Upload.LIST_IGNORE; }; const download = (params) => { let downloadLink = document.createElement("a"); downloadLink.href = `http://local.gunshiiot.com:18083/gunshiApp/xfflood/bzPredictionScheme/file/download/${params}`; downloadLink.download = `${params.fileName}`; downloadLink.style.display = "none"; // 将链接添加到页面中 document.body.appendChild(downloadLink); // 模拟点击事件,开始下载 downloadLink.click(); } const fileChange = (info) => { console.log(info); if (info.file.status === "done") { setLoading(false); setExportOPen(false) callback() } if (info.file.status === "uploading") { setLoading(true); } if (info.file.status === "error") { message.error("文件上传失败") setLoading(false); } setFileList(info.fileList) } const getDefaultValue = ()=>{ const tm = moment() const year = tm.year(); let linshi1 = []; for (let i = year - 5; i <= year + 1; i++) { linshi1.push(i); } setYearRange(linshi1) let linshi2 = []; for (let i = 0; i < 12; i++) { linshi2.push(i); } setMonthRange(linshi2) } const down = ()=>{ const stm = tm.format('YYYY-MM')+'-01' const etm = tm.endOf('months').format('YYYY-MM-DD') createCrudService(apiurl.informationManagement.dutyPlan.down).downLoad({ stm:stm, etm:etm, }) } const downTemplate = ()=>{ httppost5(apiurl.rcgl.zbgl.zbb.import, {}).then(res => { exportFile(`值班表.xlsx`,res.data) }) } const handleGclqdFileFileChange = async()=>{ var files = document.getElementById("gclqdFile").files; const resData = await createCrudService(apiurl.informationManagement.dutyPlan.upLoad).upLoad({file:files[0]}) console.log('resData',resData) } /** * @description 回到今天 */ const backToday = () => { const now = moment(); onChange(now); }; return ( <>
{exportBtn ? : null}
setExportOPen(false)} footer={null} > { console.log(info); }} fileList={fileList} disabled={loading} accept=".xls, .xlsx" >

点击或拖拽文件到此区域上传

支持扩展名:.xls .xlsx

{/* { loading ? 文件正在上传中,请等待 : fileList.length > 0 && fileList.map(file => { return (
{ download(file.response?.data?.fileId) }} style={{ cursor: 'pointer' }} >
{file.name}
deleteFile(file.response?.data?.fileId)} >
) }) }
*/} {/* */}
); } export default ToolBar;