master
parent
97d2f4fb4a
commit
8818e0bea3
13 changed files with 338 additions and 44 deletions
@ -0,0 +1,77 @@ |
||||
import util from '@/libs/util' |
||||
export default { |
||||
data() { |
||||
return { |
||||
playAuth: '', |
||||
player: null, |
||||
iframeSrc: '', |
||||
pdfVisible: false, |
||||
pdfSrc: '', |
||||
imgName: '', |
||||
imgSrc: '' |
||||
} |
||||
}, |
||||
mounted() { |
||||
this.insertScript() |
||||
}, |
||||
methods: { |
||||
preview(url,isVideo){ |
||||
let ext = util.getFileExt(url) |
||||
if(isVideo){ |
||||
this.$get(`${this.api.getPlayAuth}/${url}`).then(res => { |
||||
this.playAuth = res.data.playAuth |
||||
if(this.player){ |
||||
this.player.replayByVidAndPlayAuth(url,this.playAuth) |
||||
}else{ |
||||
this.player = new Aliplayer({ |
||||
id: 'player', |
||||
width: '100%', |
||||
autoplay: false, |
||||
vid : url, |
||||
playauth : this.playAuth, |
||||
encryptType:1, //当播放私有加密流时需要设置。
|
||||
}) |
||||
} |
||||
}).catch(res => {}) |
||||
}else if(ext == 'pdf'){ |
||||
this.pdfSrc = url |
||||
this.pdfVisible = true |
||||
}else if(util.isDoc(ext)){ |
||||
window.open(`https://view.officeapps.live.com/op/view.aspx?src=${url}`) |
||||
}else if(util.isImg(ext)){ |
||||
window.open(url) |
||||
} |
||||
}, |
||||
insertScript(){ |
||||
const linkTag = document.createElement('link') |
||||
linkTag.id = 'aliplayerLink' |
||||
linkTag.rel = 'stylesheet' |
||||
linkTag.href = 'https://g.alicdn.com/de/prismplayer/2.8.2/skins/default/aliplayer-min.css' |
||||
document.body.appendChild(linkTag) |
||||
|
||||
const scriptTag = document.createElement('script') |
||||
scriptTag.id = 'aliplayerScript' |
||||
scriptTag.type = 'text/javascript' |
||||
scriptTag.src = 'https://g.alicdn.com/de/prismplayer/2.8.2/aliplayer-min.js' |
||||
document.body.appendChild(scriptTag) |
||||
this.$once('hook:beforeDestroy', function () { |
||||
document.body.removeChild(document.querySelector('#aliplayerLink')) |
||||
document.body.removeChild(document.querySelector('#aliplayerScript')) |
||||
}) |
||||
}, |
||||
closePlayer(){ |
||||
this.playAuth = '' |
||||
this.player.pause() |
||||
}, |
||||
download(fileName,url){ |
||||
let ext = util.getFileExt(url) |
||||
if(util.isImg(ext)){ |
||||
this.imgName = fileName |
||||
this.imgSrc = url |
||||
this.$refs.picLink.click() |
||||
}else{ |
||||
window.open(url) |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue