vue文件在线预览

2022-02-18  本文已影响0人  嘴角上扬h
export default {
    install(Vue,option){
        Vue.prototype.filePreview = function(fileData,clickType){
            let fileValueSuffix = ''
            if(fileData.suffix){
                fileValueSuffix = fileData.suffix
            }else{
                let index = fileData.url.lastIndexOf("."); //(考虑严谨用lastIndexOf(".")得到)得到"."在第几位
                fileValueSuffix = fileData.url.substring(index+1); //截断"."之前的,得到后缀
            }
            if(/(xls|XLS|xlsx|XLSX|doc|DOC|docx|DOCX|PPT|PPTX|ppt|pptx)$/.test(fileValueSuffix)){
                window.open('http://view.officeapps.live.com/op/view.aspx?src='+fileData.url)
            }else if(/(jpg|JPG|JPEG|jpeg|bmp|BMP|mpg|MPG|mpeg|MPEG|tis|TIS|png|pdf|PDF|txt|png|GIF|gif|SVG|svg|webp)$/.test(fileValueSuffix)){
                window.open(fileData.url)
            }else{
                if(clickType == 'click'){
                //单击
                this.$message({
                    type: "warning",
                    message: "该类型不支持在线预览!",
                    duration: 2000,
                });
                }else if(clickType == 'dbclick'){
                //双击
                    
                }else{

                }
            }
        }
    }
}
上一篇 下一篇

猜你喜欢

热点阅读