getSavedFileList() {
const fs = wx.getFileSystemManager()
fs.getSavedFileList({
success(res) {
const fileList = res.fileList
const data = []
fileList.forEach((file) => {
const filePath = file.filePath,
{
song,
ext
} = that.getUrlFileName(filePath);
if (ext === 'mp3' || ext === 'm4a' || ext === 'aac' || ext === 'wav') {
data.push({
song,
avatar: '',
url: filePath,
create_time: formatTime('yyyy-MM-dd hh:mmss', file.createTime),
})
}
})
that.setData({
data
})
}
})
},
DownloadFile() {
const {
url,
song
} = that.data.play;
wx.downloadFile({
url,
success: (res) => {
const fs = wx.getFileSystemManager()
fs.saveFile({
tempFilePath: res.tempFilePath,
filePath: `${wx.env.USER_DATA_PATH}/${song}.m4a`,
success: (res) => {
console.log(res.savedFilePath)
that.showToast('音频已保存到本地', 'success')
},
fail: (res) => {
that.showToast('保存音频失败', 'none')
},
})
},
fail: (res) => {
that.showToast('下载音频失败', 'none')
},
})
},