zoukankan      html  css  js  c++  java
  • uniapp实现线上文件预览

    使用uni.downloadFile、uni.previewImage、uni.openDocument实现文件预览

    uni.openDocument(OBJECT)官网描述

    新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx。

    平台差异说明

    AppH5微信小程序支付宝小程序百度小程序字节跳动小程序、飞书小程序QQ小程序快手小程序
    x x

    OBJECT 参数说明:

    参数名类型必填说明平台差异说明
    filePath String 文件路径,可通过 downFile 获得  
    fileType String 文件类型,指定文件类型打开文件,有效值 doc, xls, ppt, pdf, docx, xlsx, pptx 微信小程序
    showMenu Boolean 右上角是否有可以转发分享的功能 微信小程序
    success String 接口调用成功的回调函数  
    fail String 接口调用失败的回调函数 微信小程序
    complete String 接口调用结束的回调函数(调用成功、失败都会执行)  

    代码:

    uni.downloadFile({
    	 url: this.sjuAjax.fileUrl+fileUrl,
    	 success: function (res) {
             if(res.tempFilePath.indexOf(".png" ||".jpg") > -1)
             {
                var filePath = []
                filePath[0]=res.tempFilePath;
                // 预览图片
                uni.previewImage({
                  urls: filePath,
                  success: function (res) {   
                    console.log('打开成功')
                  },
                  fail:function(res){
                    console.log(res)
                  }
                })
             }
             else
             {
              var filePath = res.tempFilePath;
              uni.openDocument({
                           filePath: filePath,
                           success: function (res) {
                                console.log('打开文档成功');
                           }
                     });
             }
    }, fail:function (res){ console.log(res) } });
  • 相关阅读:
    面试题
    linux I/O复用
    grep
    转载 hadoop 伪分布安装
    hadoop配置文件: hdfs-site.xml, mapred-site.xml
    Format aborted in 格式化namenode 失败的原因
    ERROR org.apache.hadoop.hdfs.server.datanode.DataNode: Incompatible namespaceIDs
    /etc/rc.d/init.d/iptables: No such file or directory 错误原因
    linux配置Hadoop伪分布安装模式
    初学Linux 命令
  • 原文地址:https://www.cnblogs.com/Intellectualscholar/p/15756408.html
Copyright © 2011-2022 走看看