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這個是微信文件的路徑??沒試過別的??別的路徑一般沒有權(quán)限
????????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()
????}
??})
}