//在线预览文档
online_preview(){
//#ifndef H5
uni.showLoading({ title: '加载中...' })//出现加载中图标
let str = this.allUrl
uni.downloadFile({
url: str, //要预览的PDF的地址
success: function(res) {
console.log('预览成功',res)
if (res.statusCode === 200) {
var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
uni.openDocument({
filePath: Path, //要打开的文件路径
showMenu: false, //右上角是否有可以转发分享的功能
success: function(res) {
uni.hideLoading()//关闭加载中图标
uni.showToast({
title: '打开成功',
icon: 'none'
})
},
fail: function(res) {
uni.hideLoading()//关闭加载中图标
uni.showToast({
title: '打开失败,请下载wps再试',
icon: 'none'
})
console.log('打开失败',res) //打开失败
}
})
}
},
fail: function(res) {
uni.hideLoading()//关闭加载中图标
uni.showToast({
title: '加载失败,请稍后再试',
icon: 'none'
})
console.log('加载失败',res) //预览失败
}
})
// #endif
//#ifdef H5
let resultNew= encodeURIComponent(this.allUrl)
this.allUrl2 = 'http://view.officeapps.live.com/op/view.aspx?src='+ resultNew
window.open(this.allUrl2)
// #endif
},

x***@163.com
- 发布:2022-05-09 15:49
- 更新:2024-05-11 16:08
- 阅读:3024
uniapp APP + H5 在线预览文档 兼容 最麻烦的微信浏览器
分类:HBuilderX
8 个评论
要回复文章请先登录或注册
2***@qq.com
小璐不迷路
小璐不迷路
7***@qq.com
2***@qq.com
7***@qq.com
x***@163.com (作者)
x***@163.com (作者)