uniapp 微信小程序 从微信聊天列表(会话)中上传文件(pdf和office)并浏览(还没提交给后台)

需求场景:

用户选择从微信会话列表选择和上传office(word、ppt、excel)和pdf文件,还没提交给后台时允许用户点击进行文件预览。

实现代码:

        // 获取微信列表中图片/文件
        chooseWeChatMessage(type='file'){
        	//从客户端会话选择文件
            wx.chooseMessageFile({
              count: 10,
              type: type,
              success (res) {
                const tempFiles = res.tempFiles
                console.log('获取微信消息中文件:', tempFiles)
                if(type='file'){
               		// 新开页面打开文档
                    wx.openDocument({
                      filePath: tempFiles[0].path, 
                      showMenu: false, //是否显示右上角菜单按钮  默认为false
                      success: function (res) {
                        console.log('打开本地文档成功')
                      },
                      fail: function(error){
                        console.log('打开本地文档失败')
                      }
                    })
                }
              

你可能感兴趣的:(uniapp,文件预览)