import React from 'react'; // import { DigitalAssetVerification as agent } from '../../../'; import agent from '../../Server'; /** Props接口 */ interface IProps { fileUrl?: string; //默认图片列表 value: any; } export default class UploadComponent extends React.Component { constructor(props: IProps) { super(props); this.state = { uploadFileList: [], value: this.props.value || [] }; } componentDidMount() { const { value } = this.state; if (value.length > 0) { const list = value.map((item) => { return { name: item.fileOriginalName, response: { key: item.fileUploadName } }; }); this.setState({ uploadFileList: list }); } } onPreview = async (data) => { const { fileUrl = '/web/verifiedTask/getFileDownloadUrl' } = this.props; const response = await agent.post(fileUrl, { fileNameList: [data.key] }, this); const res = response.res[0]; const href = `${res}`; let a = window.document.createElement('a'); a.setAttribute('href', href); a.setAttribute('target', '_blank'); a.click(); // a = null; } render() { const { uploadFileList } = this.state; return (
{ uploadFileList.map((item, key) => { return ( { this.onPreview(item.response); }}> {item.name} ) }) }
); } }