1.代码
previewFile() {
uni.showLoading({
title: '加载中'
})
uni.downloadFile({
url: "https://...../gwy.xls", //后端返回的文件地址
filePath: wx.env.USER_DATA_PATH + '/gwy.xls',
// filePath: wx.env.USER_DATA_PATH + '/' + item.name + '.' + item.value.split('.')[item.value.split('.').length - 1],
success: function(res) {
if (res.statusCode === 200) {
uni.openDocument({
showMenu: true,
filePath: res.filePath,
success: function(res) {
console.log(res, '打开文件成功')
},
fail: (err) => {
uni.showToast({
title: '打开文件失败请重试',
icon: 'none'
})
}
})
} else {
uni.showToast({
title: '打开文件失败请重试',
icon: 'none'
})
}
uni.hideLoading()
},
fail: (err) => {
uni.hideLoading()
uni.showToast({
title: '加载失败请重试',
icon: "none"
})
}
})
}