5***@qq.com
5***@qq.com
  • 发布:16 分钟前
  • 更新:4 分钟前
  • 阅读:14

【报Bug】uniapp-x 的uni.openDocument 打不开

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: 10

HBuilderX类型: 正式

HBuilderX版本号: 5.24

手机系统: Android

手机系统版本号: Android 16

手机厂商: 三星

手机机型: s24+

页面类型: vue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

uniappx uni.downloadFile({
url: item.fullurl,
success: (res) => {
uni.hideLoading()
console.log(res)
if (res.statusCode === 200) {
const filePatha = res.tempFilePath
console.log(filePatha)
uni.openDocument({
filePath: filePatha,
success: () => {
console.log('打开文档成功'+filePatha)
},
fail: (err) => {
console.log('打开失败'+err)
uni.showToast({ title: '打开失败:' + err.errMsg, icon: 'none' })
}
})
} else {
uni.hideLoading()
uni.showToast({ title: '下载失败', icon: 'none' })
}
},
fail: (err) => {
uni.hideLoading()
uni.showToast({ title: '下载失败:' + err.errMsg, icon: 'none' })
}
})

操作步骤:

uni.downloadFile({
url: item.fullurl,
success: (res) => {
uni.hideLoading()
console.log(res)
if (res.statusCode === 200) {
const filePatha = res.tempFilePath
console.log(filePatha)
uni.openDocument({
filePath: filePatha,
success: () => {
console.log('打开文档成功'+filePatha)
},
fail: (err) => {
console.log('打开失败'+err)
uni.showToast({ title: '打开失败:' + err.errMsg, icon: 'none' })
}
})
} else {
uni.hideLoading()
uni.showToast({ title: '下载失败', icon: 'none' })
}
},
fail: (err) => {
uni.hideLoading()
uni.showToast({ title: '下载失败:' + err.errMsg, icon: 'none' })
}
})

预期结果:

弹出其他可以打开的APP

实际结果:

毫无反应 不报错

bug描述:

uniappx uni.downloadFile({
url: item.fullurl,
success: (res) => {
uni.hideLoading()
console.log(res)
if (res.statusCode === 200) {
const filePatha = res.tempFilePath
console.log(filePatha)
uni.openDocument({
filePath: filePatha,
success: () => {
console.log('打开文档成功'+filePatha)
},
fail: (err) => {
console.log('打开失败'+err)
uni.showToast({ title: '打开失败:' + err.errMsg, icon: 'none' })
}
})
} else {
uni.hideLoading()
uni.showToast({ title: '下载失败', icon: 'none' })
}
},
fail: (err) => {
uni.hideLoading()
uni.showToast({ title: '下载失败:' + err.errMsg, icon: 'none' })
}
}) 下载成功/data/data/io.aaa/cache/uni-download/1_1788265752981223(12).pdf 打不开 毫无反应,也不报错

16 分钟前 负责人:无 分享
已邀请:
Ask小助手

Ask小助手

欢迎到专业群( uni-app x技术交流群 ) 咨询,群中有相关专业的管理员和群友。

感谢您的反馈。针对您提交的 Bug,我们已进行评审分析,具体评估如下:

1. Bug 反馈内容完整性评审

  • BUG 描述:描述较清晰,提供了关键日志信息(下载成功路径及“毫无反应、不报错”的现象),但缺少对运行模式(VDOM 模式或 Vapor 蒸汽模式)的说明,建议补充。
  • 代码示例:提供的代码片段包含下载与打开逻辑,但并非完整可运行的 .uvue 页面,缺少 <template> 及相关上下文,需官方人员补充页面框架后才能运行。
  • 复现步骤:复现步骤与代码示例一致,但未提供可复现的文件下载 URL(item.fullurl 的具体值缺失),可能导致官方人员无法直接验证,建议补充真实可用的链接。
  • 预期结果:合理,预期弹出其他可以打开该文档的 APP。
  • 实际结果:描述符合异常表现,非误报。
  • 分类信息:完整,包含了 HBuilderX 版本、手机系统、机型等信息。提示:我无法识别附件,后续如需补充资料请直接提供文本或代码。

2. Bug 是否成立分析

  • 结合官方文档与示例工程,uni-app x 在 Android 平台支持 uni.openDocument。官方示例代码在调用时,fail 回调中使用了 err.errCode,而您的代码中使用的是 err.errMsg。在 uni-app x 的强类型约束下,若错误对象结构不匹配,可能导致异常被静默吞掉。
  • 根据官方示例,标准调用流程为:uni.downloadFile 成功后,直接将 res.tempFilePath 传入 uni.openDocumentfilePath,并在失败回调中输出 err.errCode。建议您先参考官方示例修正错误回调的字段名称。
  • 参考:uni.openDocument 官方文档及示例
  • 若修正后依然“毫无反应”,建议补充完整的 .uvue 页面代码及可复现的文件 URL,以便进一步排查是否为特定机型或系统版本下的兼容性问题。
内容为 AI 生成,仅供参考
5***@qq.com

5***@qq.com (作者)

基座要重新打包

要回复问题请先登录注册