toReport(path) {
path = path || http.......slfjlf.pdf
let first = path.lastIndexOf(".");//取到文件名开始到最后一个点的长度
let suffixName = path.substring(first, path.length );//截取获得后缀名
uni.showLoading({
title:'加载中,请稍后~'
})
const fs = uni.getFileSystemManager()
// 获取本地缓存文件清空,防止缓存过多预览失败
fs.readdir({
dirPath: wx.env.USER_DATA_PATH,
success: res=>{
if(res.files&&res.files.length>0){
res.files.forEach(item=>{
fs.unlink({
filePath: wx.env.USER_DATA_PATH + '/' + item
})
})
this.openDocument(path, suffixName)
} else {
this.openDocument(path, suffixName)
}
}
})
}
openDocument(path, suffixName){
console.log(picDomain + path);
uni.downloadFile({
url: picDomain + path,
filePath: wx.env.USER_DATA_PATH + '/' + this.detail.reportName + suffixName,
success: res => {
uni.hideLoading()
console.log('准备预览')
console.log(res)
uni.openDocument({
showMenu: true,
filePath: res.filePath,
})
},
fail:res=>{
uni.hideLoading()
console.log(res)
}
})
}
uni小程序预览pdf、word文档
最新推荐文章于 2024-09-10 16:09:26 发布