封装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.attachment_histories.length===0){
if(result.data.is_pdf===true){ if(result.data.is_pdf===true){
this.props.ShowOnlinePdf(result.data.url)
//预览pdf //预览pdf
axios({ // axios({
method:'get', // method:'get',
url:result.data.url, // url:result.data.url,
responseType: 'arraybuffer', // responseType: 'arraybuffer',
}).then((result)=>{ // }).then((result)=>{
var binaryData = []; // var binaryData = [];
binaryData.push(result.data); // binaryData.push(result.data);
this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"})); // this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"}));
window.open(this.url); // window.open(this.url);
}) // })
}else{ }else{
let link = document.createElement('a'); let link = document.createElement('a');
document.body.appendChild(link); document.body.appendChild(link);

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

@ -320,6 +320,19 @@ export function TPMIndexHOC(WrappedComponent) {
} }
checkIfProfileCompleted = () => { checkIfProfileCompleted = () => {
return this.state.current_user && this.state.current_user.profile_completed 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() { render() {
let{Headertop,Footerdown, isRender, AccountProfiletype}=this.state; let{Headertop,Footerdown, isRender, AccountProfiletype}=this.state;
@ -334,11 +347,11 @@ export function TPMIndexHOC(WrappedComponent) {
isNotMember: this.isNotMember, isNotMember: this.isNotMember,
isUserid:this.state.coursedata&&this.state.coursedata.userid, isUserid:this.state.coursedata&&this.state.coursedata.userid,
fetchUser: this.fetchUser, fetchUser: this.fetchUser,
showLoginDialog: this.showLoginDialog, showLoginDialog: this.showLoginDialog,
checkIfLogin: this.checkIfLogin, checkIfLogin: this.checkIfLogin,
showProfileCompleteDialog: this.showProfileCompleteDialog, showProfileCompleteDialog: this.showProfileCompleteDialog,
checkIfProfileCompleted: this.checkIfProfileCompleted, checkIfProfileCompleted: this.checkIfProfileCompleted,
ShowOnlinePdf:(url)=>this.ShowOnlinePdf(url)
} }
return ( return (
<div> <div>

Loading…
Cancel
Save