// 附件base64解析
analyse64: function(attName, attType){
if(attType===1) { // 图像预览
this.loading_show = true;
this.blobURL = '';
let formData = new FormData();
let config = {
headers: {'Content-Type': 'multipart/form-data',
"Authorization": this.$sessionAuth()}};
formData.append('fileName', attName);
formData.append('filePath', "emp_profile");
this.uploadAxios.post(this.base64Url, formData,config)
.then((result)=>{
let file64 = result.data.extraData;
for (let i in file64) {
console.log(file64[i]);
this.base64 = file64[i];
}
this.preview_show = true;
this.loading_show = false;
});
}else if(attType===4) { // 视频预览
this.base64 = '';
let formData = new FormData();
let config = {
headers: {'Content-Type': 'multipart/form-data',
"Authorization": this.$sessionAuth()},
responseType: "blob"
};
formData.append('fileName', attName);
formData.append('path', "emp_profile");
this.uploadAxios.post(this.getVideoUrl, formData,config)
.then((response)=>{
let blob = new Blob([response.data],{type:"video/mp4"});
this.blobURL = window.URL.createObjectURL(blob);
this.preview_show = true;
});
}else{
return this.$vToast('该附件暂不支持手机端预览!')
}
},
touchSwitch:function(){
let layer = document.getElementById('topLayer');
let startX,startY,moveEndX,moveEndY,X,Y;
layer.addEventListener("touchstart",(event => {
startX = event.targetTouches[0].pageX;
startY = event.targetTouches[0].pageY;
}))
layer.addEventListener("touchend",(event => {
moveEndX = event.changedTouches[0].pageX;
moveEndY = event.changedTouches[0].pageY;
X = moveEndX-startX;
Y = moveEndY-startY;
if(X > 30) this.prevPreview(); // 右划
if(X < -30) this.nextPreview(); // 左划
}))
},
/*上一张*/
prevPreview:function(){
if(this.attachIndex<=0) return;
let att = this.attachs[this.attachIndex-1];
this.attachIndex--;
this.analyse64(att.Name,att.Type);
},
/*下一张*/
nextPreview:function(){
if(this.attachIndex >= this.attachs.length-1) return;
let att = this.attachs[this.attachIndex+1];
this.attachIndex++;
this.analyse64(att.Name,att.Type)
},
/*关闭预览*/
clsPreview:function(){
this.preview_show=false;
this.base64=''; //退出预览清除base64
this.blobURL=''; //退出预览清除blob
window.event.stopPropagation(); // 阻止冒泡传播, 防止点击A事件结果触发B事件的蝴蝶效应
},
js通过POST请求服务器文件,得到字节流并实现预览
最新推荐文章于 2023-03-23 17:02:53 发布