微信小程序点击下载excel,uni.downloadFile开发版和体验版正常下载打开xls文件。正式版点击下载无反应。
exportExcelInfo(query).then(res => {
let fileName = res.msg
var url =`${VUE_APP_API_URL}/tcapp/common/download?fileName=` + encodeURI(fileName) + '&&delete=true'
// let index = fileName.lastIndexOf('.');
// let fileType = res.msg.substring(index + 1, url.length);
uni.downloadFile({
url: url, // Excel文件URL
success: (downloadResult) => {
if (downloadResult.statusCode === 200) {
const filePath = downloadResult.tempFilePath;// 修改excel名字
uni.saveFile({
tempFilePath: filePath, // 下载文件的临时路径
filePath: `${uni.env.USER_DATA_PATH}/订单.xlsx`, // 指定新的文件名,包括扩展名
success: (saveRes) => {
console.log('文件保存成功',saveRes.savedFilePath);// 打开excel
uni.openDocument({
filePath: saveRes.savedFilePath, // 本地文件路径
fileType: 'xlsx', // 文件类型,根据实际情况调整
showMenu: true,
success: function() {
console.log('文件打开成功');
}
});
},
fail: (err) => {
console.error('文件保存失败',err);
}
});
} else {
console.error('下载失败');
}
},
fail: (error) => {
console.error('下载失败', error);
}
});
})
开发版打开调试去线上版看打印报什么错,后台配置downloadFile域名没有