uni-app openDocument 为什么钉钉官网远程调试小程序页面能打开pdf没反应

uni-app openDocument 为什么钉钉官网远程调试小程序页面能打开pdf没反应

开发环境 版本号 项目创建方式
Windows 10 HBuilderX
### 示例代码:

```javascript
uni.downloadFile({    
  url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",    
  success: (res) => {    
    console.log("res:", res);    

    uni.openDocument({    
      filePath: res.tempFilePath, // 必须是临时本地路径    
      fileType: "pdf",    
      success: () => console.log("打开成功"),    
      fail: (err) => console.error("打开失败", err),    
    });    
  },    
});

操作步骤:

uni.downloadFile({    
  url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",    
  success: (res) => {    
    console.log("res:", res);    

    uni.openDocument({    
      filePath: res.tempFilePath, // 必须是临时本地路径    
      fileType: "pdf",    
      success: () => console.log("打开成功"),    
      fail: (err) => console.error("打开失败", err),    
    });    
  },    
});

预期结果:

打开pdf

实际结果:

报错卡死

bug描述:

uni.downloadFile({    
  url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",    
  success: (res) => {    
    console.log("res:", res);    

    uni.openDocument({    
      filePath: res.tempFilePath, // 必须是临时本地路径    
      fileType: "pdf",    
      success: () => console.log("打开成功"),    
      fail: (err) => console.error("打开失败", err),    
    });    
  },    
});

报错:

when transfer page data or component data of page src/subpackages/..../index,data json stringify failed, please check data {}
report catch error RangeError: Maximum call stack size exceeded
at Jv.onerror (af-appx.worker.min.js:26)
at i (af-appx.worker.min.js:26)
at c.emit (af-appx.worker.min.js:26)
at Jv.onerror (af-appx.worker.min.js:26)
at i (af-appx.worker.min.js:26)
at c.emit (af-appx.worker.min.js:26)
at Jv.onerror (af-appx.worker.min.js:26)
at i (af-appx.worker.min.js:26)
at c.emit (af-appx.worker.min.js:26)
at Jv.onerror (af-appx.worker.min.js:26)
downloadFile 执行了,有返回地址,但是openDocument应该是报错了,卡住了。

钉钉官网远程调试小程序页面能打开pdf
https://open.dingtalk.com/tools/explorer/jsapi?spm=ding_open_doc.document.0.0.71f92f5fZb72Gp&id=11464

换成 dd.openDocument 也不行


更多关于uni-app openDocument 为什么钉钉官网远程调试小程序页面能打开pdf没反应的实战教程也可以访问 https://www.itying.com/category-93-b0.html

10 回复

该bug反馈内容基本完整,但存在关键缺失:未明确说明运行平台(是uni-app编译的App、钉钉小程序还是其他平台)。代码示例完整可直接运行,复现步骤仅重复代码缺乏操作细节。预期结果合理,但实际结果中的"Maximum call stack size exceeded"错误表明存在数据处理异常,非正常现象。分类信息缺少运行平台和设备信息,HBuilderX版本4.87较旧(当前最新为4.95+)。
经知识库核查,uni.openDocument在钉钉小程序平台兼容性良好,但错误日志中af-appx.worker.min.js表明实际运行在钉钉环境。问题可能源于:1) PDF文件过大导致JSON序列化失败;2) uni-app对钉钉环境适配问题。知识库提示App端建议使用三方PDF插件,且saveFile会移动临时文件,可能影响后续openDocument调用。
建议用户:1) 确认运行平台并补充设备信息;2) 尝试小文件测试;3) 更新HBuilderX至最新版;4) 若为App端考虑使用PDF插件方案。该问题可能涉及平台适配边界情况,需结合具体环境进一步排查。 内容为 AI 生成,仅供参考

更多关于uni-app openDocument 为什么钉钉官网远程调试小程序页面能打开pdf没反应的实战教程也可以访问 https://www.itying.com/category-93-b0.html


瞎说,hbx 最新版本就是4.87,检查更新是最新的。pdf也不大就13kb。就这么几行代码,也没有用到saveFile。
钉钉官方网页调试小程序就可以调试打开下载后的pdf。都说了是小程序,没有app的事儿。

改成这样 试试有没有问题
dd.downloadFile({
url: “https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf”,
success: (res) => {
console.log(“res:”, res);

      dd.openDocument({      
        filePath: res.tempFilePath, // 必须是临时本地路径      
        fileType: "pdf",      
        success: () => console.log("打开成功"),      
        fail: (err) => console.error("打开失败", err),      
      });      
    },      
  });<br>

我应该都试过,downloadFile没问题,dd.openDocument,我想想,这个不是报一堆不认识的错误就是报 openDocument is not a function,不知道为什么你看看这个: 钉钉官网远程调试小程序页面能打开pdf https://open.dingtalk.com/tools/explorer/jsapi?spm=ding_open_doc.document.0.0.71f92f5fZb72Gp&id=11464 先用 downloadFile 下载,然后拿到给的地址再添加到上面页面里提供输入参数的地方,运行调试就可以打开。

邪门不好像是钉钉原生报openDocument is not a function,但是网页调试还能打开。

大佬,请问后面是怎么解决的,我现在也遇到了这个问题

解决不了

我试了用支付宝小程序可以预览pdf,但钉钉小程序无法预览

查一下钉钉小程序官方文档,看看是否支持这个API,或者使用上有没有差异

根据你提供的信息,这个问题主要出现在钉钉小程序环境中。以下是关键原因分析和解决方案:

核心原因: 钉钉小程序远程调试环境对 uni.openDocument 的支持存在限制。虽然钉钉官方文档显示支持 dd.openDocument,但在远程调试时可能无法正常调用系统文档查看器。

解决方案:

  1. 使用钉钉原生 API:uni.openDocument 替换为钉钉原生的 dd.openDocument

    dd.downloadFile({
      url: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
      success: (res) => {
        dd.openDocument({
          filePath: res.filePath,
          fileType: 'pdf'
        });
      }
    });
    
  2. 检查文件路径格式: 确保下载成功后获取的文件路径正确。钉钉返回的是 res.filePath 而非 res.tempFilePath

  3. 真机测试验证: 远程调试环境可能存在限制,建议在真机钉钉客户端中进行测试。真机环境通常能正常调用系统文档查看器。

  4. 文件类型兼容性: 确认PDF文件本身无损坏,可尝试其他PDF文件进行测试。

  5. 权限配置: 在钉钉小程序配置文件中添加必要的权限声明:

    {
      "requiredPrivateInfos": ["downloadFile", "openDocument"]
    }
回到顶部