openDocument打开文档一直无法打开?
发布于 7 年前 作者 xiongli 5585 次浏览 来自 官方Issues

openDocument api 在真机中打开文档一直无法打开,但是提醒打开文档成功,这是为啥呢?路径都拿到了

8 回复

楼主解决了吗,我手机也是有时能打开有时打不开,有的手机就一直打不开,然后开发者工具一直能打开。。。

( '▿ ’ )

openFile(filePath) {

wx.showLoading({

title: “正在打开中”,

icon: “loading”,

duration: 2000

});

wx.downloadFile({

url: filePath,

success: (res) => {

console.log(“11111”, res);

const filePath = res.tempFilePath;

var index = filePath.lastIndexOf(".");

let fileType = filePath.substring(index + 1, filePath.length);

let openFileType;

switch (fileType) {

case “docx”:

openFileType = “docx”;

break;

case “word”:

openFileType = “docx”;

break;

case “excel”:

openFileType = “xlsx”;

break;

case “xlsx”:

openFileType = “xlsx”;

break;

case “xls”:

openFileType = “xls”;

break;

case “ppt”:

openFileType = “ppt”;

break;

case “pptx”:

openFileType = “pptx”;

break;

case “pdf”:

openFileType = “pdf”;

break;

default:

openFileType = “doc”;

break;

}

wx.openDocument({

filePath: filePath,

fileType: openFileType,

success: (res) => {

console.log(“打开文档成功”);

},

fail: (res) => {

console.log(res);

}

});

},

fail: (res) => {

console.log(res);

wx.showToast({

title: “文件下载失败”

});

},

complete: () => {

wx.hideLoading();

}

});

},

麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

测试工具能打开文档吗?我感觉我们俩遇到的问题一样

我的为什么一会可以打开,一会打不开的?

回到顶部