export function openFile(url, fileName, options = {}) {
const {
loadingText = '打开中...',
showSuccessToast = false,
showErrorToast = true
} = options
return new Promise((resolve, reject) => {
// 获取文件扩展名
const fileExtension = fileName.split('.').pop().toLowerCase()
// 根据文件扩展名确定文件类型
let fileType = fileExtension
// 显示加载提示
wx.showLoading({
title: loadingText,
mask: true
})
console.log("fileType",fileType)
// 下载文件
wx.downloadFile({
url: url,
success: (res) => {
if (res.statusCode === 200) {
// 打开文档
wx.openDocument({
filePath:encodeURI(res.tempFilePath),
fileType: fileType,
success: (openRes) => {
wx.hideLoading()
if (showSuccessToast) {
wx.showToast({
title: '文件打开成功',
icon: 'success'
})
}
resolve(openRes)
},
fail: (error) => {
wx.hideLoading()
if (showErrorToast) {
wx.showToast({
title: '无法打开此类型文件',
icon: 'none'
})
}
console.error('文件打开失败:', error)
reject(error)
}
})
} else {
wx.hideLoading()
if (showErrorToast) {
wx.showToast({
title: '文件下载失败',
icon: 'none'
})
}
console.error('文件下载失败:', res.errMsg)
reject(new Error(res.errMsg))
}
},
fail: (error) => {
wx.hideLoading()
if (showErrorToast) {
wx.showToast({
title: '文件下载失败',
icon: 'none'
})
}
console.error('文件下载失败:', error.errMsg)
reject(error)
}
})
})
}
上周还是好的 然后这周就白屏了 安卓是正常的ios不正常

复现代码 片段 https://developers.weixin.qq.com/s/tMM1l7m6873c