uploadImg = (formData) =>{const xhr = newXMLHttpRequest();//进度监听//xhr.upload.addEventListener('progress', (e)=>{console.log(e.loaded / e.total)}, false);//加载监听//xhr.addEventListener('load', ()=>{console.log("加载中");}, false);//错误监听
xhr.addEventListener('error', ()=>{const step = this.state.index;this.setState({
modeling:false});if(step === 1){this.setState({
faced:[]
})
}else if(step === 2){this.setState({
lookUp:[]
})
}else if(step === 3){this.setState({
overLook:[]
})
}else if(step === 4){this.setState({
left:[]
})
}else if(step === 5){this.setState({
right:[]
})
}
Toast.fail('建模失败', 1)
},false);
xhr.onreadystatechange= () =>{if (xhr.readyState === 4) {if(xhr.status === 200){const result =JSON.parse(xhr.responseText);if (result.status === 10000) {this._Upload(this.state.index,`http:${result.url}`,result.filename)this.setState({
faced:[{
url:`http:${result.url}`,
id:123}]
})
}else{const step = this.state.index;this.setState({
modeling:false});if(step === 1){this.setState({
faced:[]
})
}else if(step === 2){this.setState({
lookUp:[]
})
}else if(step === 3){this.setState({
overLook:[]
})
}else if(step === 4){this.setState({
left:[]
})
}else if(step === 5){this.setState({
right:[]
})
}
Toast.fail(result.message,1.5)
}
}else{const step = this.state.index;this.setState({
modeling:false});if(step === 1){this.setState({
faced:[]
})
}else if(step === 2){this.setState({
lookUp:[]
})
}else if(step === 3){this.setState({
overLook:[]
})
}else if(step === 4){this.setState({
left:[]
})
}else if(step === 5){this.setState({
right:[]
})
}
Toast.fail('建模失败', 1)
}
}
};
xhr.open('POST', '/api/file/file/upload' , true);
xhr.send(formData);
};