美文网首页
小程序打开文件

小程序打开文件

作者: 萘小蒽 | 来源:发表于2022-11-04 16:06 被阅读0次

目前1.4库支持打开'doc','docx','xls','xlsx','ppt','pptx','pdf'等文件
api: openDocument、downloadFile

open(index) {
            let attachments = this.attachments[index];
            let fileUrl = attachments.fileUrl;
            let fileName = attachments.fileName;
            let fileType = attachments.fileType.toLowerCase();
            let fileTypes = ['doc','docx','xls','xlsx','ppt','pptx','pdf']; //openDocument fileType目前只支持范围
            if(!fileTypes.includes(fileType)){
              util.showMsg(`目前仅支持打开${fileTypes.join(',')}类型的文件` );
              return
            }
            wx.showLoading({
                title: '下载请求中,请耐心等待..'
            });
            wx.downloadFile({
                url: fileUrl,
                //filePath: filePath, // 指定文件下载后存储的路径
                header: {
                    'Authorization': "Bearer " + wx.getStorageSync("TOKEN")
                },
                success: function (res) {
                    console.log(res)
                    wx.hideLoading()
                    wx.openDocument({  //打开文件
                        filePath: res.tempFilePath,
                        fileType:fileType,
                        showMenu: true,  // 是否显示右上角菜单按钮 默认为false(看自身需求,可要可不要。后期涉及到右上角分享功能)
                        success: function () {
                            console.log(`打开文件成功`)
                        },
                        fail: function (err) {
                            console.log(err)
                        }
                    });
                },
                fail: function (res) {
                    console.log(res)
                },
                complete: function (res) {
                }
            })
        }

相关文章

  • 小程序打开文件

    目前1.4库支持打开'doc','docx','xls','xlsx','ppt','pptx','pdf'等文件...

  • WeBox群发小程序教程

    首先打开常用消息 开启右上角的,自动添加小程序消息 打开你的微信,找到文件传输助手,自己发送你要的小程序到文件传输...

  • Sublime微信小程序wxml, wxss代码高亮

    1. Sublime text打开微信小程序工程文件,找到一个wxml文件,打开。 2. 右下角显示“Plain ...

  • Sublime微信小程序wxml, wxss代码高亮

    1. Sublime text打开微信小程序工程文件,找到一个wxml文件,打开。 2. 右下角显示“Plain ...

  • 微信小程序npm vant为例

    1.在小程序根目录或者各个文件目录下(不能在小程序根目录外)新建文件夹 miniprogram_npm 2.打开c...

  • c++使用 ShellExecute 打开文件或执行程序

    使用 ShellExecute 打开文件或执行程序 可以使用 ShellExecute 打开文件或执行程序。 原型...

  • 微信小程序文件下载功能

    微信小程序简单的下载,点击下载之后出现加载动画,随后自动打开下载的文件,在微信小程序中下载的文件想要分享的话需要使...

  • open

    使用默认程序来打开文件、文件夹、链接等,也可以指定程序打开。 常用参数 -a application指定应用程序打...

  • 【总结】2017.01.19

    2017.01.19 - 计划 小程序文件上传 小程序下拉刷新loading - 实际完成 小程序文件上传 小程序...

  • Mac下 open、open -a与open -e的区别

    Open命令用于打开文件、目录或程序 open,使用关联的程序打开文件,例:open a.txt会用文本编辑打开a...

网友评论

      本文标题:小程序打开文件

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