小程序
小游戏
企业微信
微信支付
扫描小程序码分享
最近做小程序开发。需要下载文档到本地,但是格式不支持 导致都没法在手机预览和转发下载 请问还有办法吗,我们公司得这些文件格式特殊 没法使用官方得 wx.openDocument
去打开,再转发下载
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
randomString(len) { len = len || 32; var $chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ var maxPos = $chars.length; var pwd = ""; for (let i = 0; i < len; i++) { pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); } return pwd; }, openDoc: function (e) { this.openDocTag = true; var index = e.currentTarget.dataset.index; var filePath = this.data.thread_data.doc_list[index].fileFullPath; var fileExtName = `.${this.data.thread_data.doc_list[index].fileType}`; let that = this; wx.showLoading({ title: "正在下载..", //提示的内容, mask: true, //显示透明蒙层,防止触摸穿透, success: (res) => { }, }); const randfile = that.randomString(32) + new Date().getTime() + fileExtName; const newPath = `${wx.env.USER_DATA_PATH}/${randfile}`; wx.downloadFile({ url: filePath, filePath: newPath, success: (res) => { wx.hideLoading(); wx.showLoading({ title: "正在打开..", //提示的内容, mask: true, //显示透明蒙层,防止触摸穿透, success: (res) => { }, }); wx.openDocument({ filePath: newPath, showMenu: true, success: (res) => { wx.hideLoading(); console.log("open res", res); }, fail: function (res) { console.log("open fail", res); wx.hideLoading(); }, }); }, fail: (res) => { console.log("res error", res); wx.hideLoading(); }, complete: (res) => { console.log("res complete", res); }, }); },
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
randomString(len) { len = len || 32; var $chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ var maxPos = $chars.length; var pwd = ""; for (let i = 0; i < len; i++) { pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); } return pwd; }, openDoc: function (e) { this.openDocTag = true; var index = e.currentTarget.dataset.index; var filePath = this.data.thread_data.doc_list[index].fileFullPath; var fileExtName = `.${this.data.thread_data.doc_list[index].fileType}`; let that = this; wx.showLoading({ title: "正在下载..", //提示的内容, mask: true, //显示透明蒙层,防止触摸穿透, success: (res) => { }, }); const randfile = that.randomString(32) + new Date().getTime() + fileExtName; const newPath = `${wx.env.USER_DATA_PATH}/${randfile}`; wx.downloadFile({ url: filePath, filePath: newPath, success: (res) => { wx.hideLoading(); wx.showLoading({ title: "正在打开..", //提示的内容, mask: true, //显示透明蒙层,防止触摸穿透, success: (res) => { }, }); wx.openDocument({ filePath: newPath, showMenu: true, success: (res) => { wx.hideLoading(); console.log("open res", res); }, fail: function (res) { console.log("open fail", res); wx.hideLoading(); }, }); }, fail: (res) => { console.log("res error", res); wx.hideLoading(); }, complete: (res) => { console.log("res complete", res); }, }); },