import React from 'react'; import { Drawer, message, Modal } from 'kts-xui'; import { Space, Upload } from 'kts-components-antd-x4'; import agent from '../../Server'; import { CloudDownloadOutlined, CloudUploadOutlined } from '@ant-design/icons'; import DigitalAssets from '..'; interface IProps { onClose: () => void; onSuccess?: () => void; data: { url: string, downloadurl: string, } type: number; } export default class Component extends React.Component{ private list: any[] = []; constructor(props: any) { super(props); this.state = { downloadUrl: '', data: this.props.data, excel: true, errorModal: false, errorInfo: '', downloadFilePath: '', fileList: [], uploadConfig: DigitalAssets.remoteConfig, }; console.log(DigitalAssets.remoteConfig); } handleCancel = () => { this.setState({ errorModal: false }); } handleOk = () => { if (this.state.downloadFilePath.indexOf('http') >= 0 || this.state.downloadFilePath.indexOf('//') === 0) { window.open(this.state.downloadFilePath); } else { window.open(this.state.uploadConfig.domain + this.state.downloadFilePath); } } onChange = (info: any) => { const status = info.file.status; let fileList = info.fileList; this.setState({ fileList }); if (status === 'done') { const returnCode = info.file.response.status.returnCode; if (returnCode === '99999') { message.warning('系统异常'); } else { if (info.file.response.ok) { if (info.file.response.body.allSuccess) { //message.success('上传成功!'); } else { let downloadFilePath = info.file.response.body.downloadFilePath; if (downloadFilePath && downloadFilePath.indexOf('http') < 0) { downloadFilePath = `/zone/invoice/biz-logging/downloadFile?filepath=${downloadFilePath}`; } const errorCount = info.file.response.body.errorCount; const successCount = info.file.response.body.successCount; let errorText = `录入成功${successCount} 条,失败${errorCount} 条!`; this.setState({ excel: false, errorModal: !!errorCount, errorInfo: errorText, downloadFilePath: downloadFilePath }); if (!!errorCount === false) { message.success('上传成功!'); } } this.props.onSuccess!(); } else { message.error(info.file.response.status.description); } } } else if (status === 'error') { message.error(`${info.file.name} 文件上传失败.`); } } render() { let { domain } = this.state.uploadConfig; const propsData = this.state.data; const url = domain + propsData.url; let downloadUrl = ''; if (propsData.downloadurl.indexOf('http') >= 0 || propsData.downloadurl.indexOf('//') === 0) { downloadUrl = propsData.downloadurl; } else { downloadUrl = domain + propsData.downloadurl; } const headers = { Authorization: this.state.uploadConfig.token! }; const props = { name: 'file', multiple: false, action: url, fileList: this.state.fileList, headers: headers, onChange: this.onChange, }; return (

Excel 模板下载

Excel 上传

{this.state.errorInfo} 点击下载按钮下载失败记录。
) } }