封装showpdf方法

dev_winse
杨树明 6 years ago
parent 807aec3a1e
commit c37492dc75

@ -39,17 +39,18 @@ class Fileslistitem extends Component{
if(result.data.attachment_histories.length===0){
if(result.data.is_pdf===true){
this.props.ShowOnlinePdf(result.data.url)
//预览pdf
axios({
method:'get',
url:result.data.url,
responseType: 'arraybuffer',
}).then((result)=>{
var binaryData = [];
binaryData.push(result.data);
this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"}));
window.open(this.url);
})
// axios({
// method:'get',
// url:result.data.url,
// responseType: 'arraybuffer',
// }).then((result)=>{
// var binaryData = [];
// binaryData.push(result.data);
// this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"}));
// window.open(this.url);
// })
}else{
let link = document.createElement('a');
document.body.appendChild(link);

@ -43,16 +43,17 @@ class Showoldfiles extends Component{
}
showfiless=(url)=>{
axios({
method:'get',
url:url,
responseType: 'arraybuffer',
}).then((result)=>{
var binaryData = [];
binaryData.push(result.data);
this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"}));
window.open(this.url);
})
// axios({
// method:'get',
// url:url,
// responseType: 'arraybuffer',
// }).then((result)=>{
// var binaryData = [];
// binaryData.push(result.data);
// this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"}));
// window.open(this.url);
// })
this.props.ShowOnlinePdf(url)
}
render(){
let {visible,allfiles}=this.props;

@ -321,6 +321,19 @@ export function TPMIndexHOC(WrappedComponent) {
checkIfProfileCompleted = () => {
return this.state.current_user && this.state.current_user.profile_completed
}
ShowOnlinePdf = (url) => {
return axios({
method:'get',
url:url,
responseType: 'arraybuffer',
}).then((result)=>{
var binaryData = [];
binaryData.push(result.data);
this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"}));
window.open(this.url);
})
}
render() {
let{Headertop,Footerdown, isRender, AccountProfiletype}=this.state;
const common = {
@ -334,11 +347,11 @@ export function TPMIndexHOC(WrappedComponent) {
isNotMember: this.isNotMember,
isUserid:this.state.coursedata&&this.state.coursedata.userid,
fetchUser: this.fetchUser,
showLoginDialog: this.showLoginDialog,
checkIfLogin: this.checkIfLogin,
showProfileCompleteDialog: this.showProfileCompleteDialog,
checkIfProfileCompleted: this.checkIfProfileCompleted,
ShowOnlinePdf:(url)=>this.ShowOnlinePdf(url)
}
return (
<div>

Loading…
Cancel
Save