Commit 295f309b authored by 王苓芝's avatar 王苓芝

文件格式控制

parent e2da9548
import { Upload, Icon, Modal, notification } from 'antd'; import { Upload, Icon, Modal, message } from 'antd';
import React from 'react'; import React from 'react';
import config from '../../../config/env.config'; import config from '../../../config/env.config';
import { qiniuToken } from '@/services/qiniu'; import { qiniuToken } from '@/services/qiniu';
...@@ -22,6 +22,7 @@ class PicturesWall extends React.Component { ...@@ -22,6 +22,7 @@ class PicturesWall extends React.Component {
previewVisible: false, previewVisible: false,
previewImage: '', previewImage: '',
fileList: [], fileList: [],
isValid: false,
}; };
async componentDidMount() { async componentDidMount() {
...@@ -45,14 +46,19 @@ class PicturesWall extends React.Component { ...@@ -45,14 +46,19 @@ class PicturesWall extends React.Component {
beforeUpload = file => { beforeUpload = file => {
const types = ['application/pdf', 'image/png', 'image/jpeg']; const types = ['application/pdf', 'image/png', 'image/jpeg'];
if (types.indexOf(file.type) === -1) { if (types.indexOf(file.type) === -1) {
notification.error('输入格式有问题'); this.setState({ isValid: false });
return false; message.error('输入格式有问题');
} }
return true; return types.indexOf(file.type) !== -1;
}; };
handleChange = ({ fileList }) => { handleChange = info => {
this.setState({ fileList }); console.log('info', info.file);
if (!this.state.isValid) {
this.setState({ fileList: [] });
return;
}
this.setState({ fileList: info.fileList });
}; };
customRequest = ({ file, onError, onSuccess }) => { customRequest = ({ file, onError, onSuccess }) => {
...@@ -89,6 +95,7 @@ class PicturesWall extends React.Component { ...@@ -89,6 +95,7 @@ class PicturesWall extends React.Component {
render() { render() {
const { previewVisible, previewImage, fileList } = this.state; const { previewVisible, previewImage, fileList } = this.state;
console.log('fileList---render', fileList);
const uploadButton = ( const uploadButton = (
<div> <div>
<Icon type="plus" /> <Icon type="plus" />
......
...@@ -76,7 +76,7 @@ export default props => { ...@@ -76,7 +76,7 @@ export default props => {
<Modal title="上传发票" visible={visible} footer={null} onCancel={props.onCancel} width="700px"> <Modal title="上传发票" visible={visible} footer={null} onCancel={props.onCancel} width="700px">
<Tabs defaultActiveKey="1" className={styles.tab} onChange={changeTab} activeKey={tabValue}> <Tabs defaultActiveKey="1" className={styles.tab} onChange={changeTab} activeKey={tabValue}>
<TabPane tab="上传凭证" key="1"> <TabPane tab="上传凭证" key="1">
<UploadC ref={picUpload} accept=".png,.jpg,.jpeg,.pdf" /> <UploadC ref={picUpload} />
</TabPane> </TabPane>
<TabPane tab="上传附件" key="2"> <TabPane tab="上传附件" key="2">
<a <a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment