美文网首页
vue文件在线预览

vue文件在线预览

作者: 嘴角上扬h | 来源:发表于2022-02-18 15:44 被阅读0次
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{

                }
            }
        }
    }
}

相关文章

网友评论

      本文标题:vue文件在线预览

      本文链接:https://www.haomeiwen.com/subject/cbjylrtx.html