• 小程序打开pdf文件


    wxml部分:
      <view class="content">
          <van-cell title="{{index+1}}.{{item.descripts}}" is-link wx:for="{{helpDetail}}" wx:key="index" bindtap="goToDetail" data-id="{{item.url}}" />
        </view>
     
     
    js部分:
     
      goToDetail:function(e){
        if(this.data.loading){
          return
        }
        let url = e.currentTarget.dataset.id; //pdf图片地址
        let _this = this;
        if (url != "") {
          if ((this.data.platform != "") && (this.data.platform != "ios")) {
            //非IOS设备打开文档
            this.setData({
              loading: true
            }, () => {
              this.openDocument(url);
            })
          } else {
            if (this.data.platform == "") {
              //未获取到设备信息
              wx.getSystemInfo({
                success: function(res) {
                  _this.setData({
                    platform: res.platform
                  })
                  if (res.platform != 'ios') {
                    _this.setData({
                      loading: true
                    }, () => {
                      _this.openDocument(url);
                    })
                  }
                }
              })
            } else {
              //IOS 设备
              wx.navigateTo({
                url: '../questionDetail/detail?url='+url,
              })
            }
          }
        } else {
          wx.showToast({
            title: '无帮助文档',
            icon: false,
          })
        }



      },
        /**
       * 打开文档
       */
      openDocument: function(url) {
        let _this = this;
        wx.downloadFile({
          url: url,
          success: function(res) {
            console.log(res)
            var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
            wx.openDocument({
              filePath: Path,
              success: function(res) {
                _this.setData({
                  loading: false,
                })
              }
            })
          },
          fail: function(res) {
            wx.showToast({
              title: '文档加载失败',
              icon: 'none',
            })
            _this.setData({
              loading: false,
            })
          }
        })
      },
  • 相关阅读:
    Linux命令权限 用户权限 组权限 文件、目录权限
    Linux基础命令
    Linux之centos7 VMware安装教程
    Python 输入输出 数据类型 变量
    操作系统和网络基础
    python之禅
    【Linux】Linux 在线安装yum
    【Linux】TFTP & NFS 服务器配置
    【读书笔记】如何高效学习(Learn More ,Study Less)
    【Linux】Windows与Linux之间的文件共享(基于网络)
  • 原文地址:https://www.cnblogs.com/zxm1993/p/12985595.html
Copyright © 2020-2023  润新知