提交 f88c8f16 authored 作者: 钟是志's avatar 钟是志

2019年9月24日 12:38:44

上级 07293ed8
...@@ -8,24 +8,19 @@ export default class UploadButton extends React.Component { ...@@ -8,24 +8,19 @@ export default class UploadButton extends React.Component {
} }
clickUpload = (e) => { clickUpload = (e) => {
if(e && e.stopPropagation){
e.stopPropagation(); // alert(window.navigator.userAgent);
e.preventDefault();
}
// document.getElementById('infoUpload').click(); // document.getElementById('infoUpload').click();
this.fileInput.click(); this.fileInput.click();
}; };
imgFileChange = (e) => { imgFileChange = (e) => {
if(e && e.stopPropagation){
e.stopPropagation();
e.preventDefault();
}
const file = this.fileInput.files[this.fileInput.files.length - 1]; const file = this.fileInput.files[this.fileInput.files.length - 1];
if(!file) { if(!file) {
return false; return false;
} }
Toast.loading(); Toast.loading('文件上传中', 0);
uploadFile({file}).then((res) => { uploadFile({file}).then((res) => {
Toast.hide(); Toast.hide();
if(res && res.url){ if(res && res.url){
...@@ -46,21 +41,35 @@ export default class UploadButton extends React.Component { ...@@ -46,21 +41,35 @@ export default class UploadButton extends React.Component {
render() { render() {
return ( return (
<div style={{fontSize: '18px',paddingTop: '10px',paddingBottom: '10px'}} > <div style={{
fontSize: '18px',
paddingTop: '10px',
paddingBottom: '10px',
position: 'relative'
}} >
<p
/* onClick={this.clickUpload}*/
style={{
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
textAlign: 'center',
lineHeight: '46px',
margin: 'auto',
}}>
上传
</p>
<input type="file" <input type="file"
accept={'image/*'} accept={'image/*'}
id={'infoUpload'} id={'infoUpload'}
style={{ display: 'none' }} style={{ opacity: 0 }}
onChange={this.imgFileChange} onChange={this.imgFileChange}
ref={input => { ref={input => {
this.fileInput = input; this.fileInput = input;
}} }}
/> />
<p onClick={this.clickUpload} style={{textAlign: 'center'}}>
上传
</p>
</div> </div>
) )
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论