function getFileExt (filepath) { if (filepath != "") { const pos = "." + filepath.replace(/.+\./, ""); return pos; }}
function DownLoadFile (url) {
const type = getFileExt(url)
const fileArr = ['.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.pdf']
if (!fileArr.includes(type)) return
vx.showLoading()
vx.downloadFile({
url: url,// 下载的文件地址
success (data) {
vx.hideLoading()
const filePath = data.tempFilePath
const fs = vx.getFileSystemManager();
fs.saveFile({
tempFilePath: filePath,//Path我这里是wx.downloadFile()下载下来的文件临时地址
//wx.env.USER_DATA_PATH这个是微信文件的路径 没试过别的 别的路径一般没有权限
filePath: vx.env.USER_DATA_PATH + '/' + Date.parse(new Date()) + type,
success: function (res) {
console.log(res)
vx.openDocument({
showMenu: true,
filePath: res.savedFilePath,
success: function () {
}
})
},
fail: function (res) {
console.log(res)
vx.hideLoading()
}
})
},
fail (resd) {
console.log(resd, 'resd')
vx.hideLoading()
}
})
}