// #ifdef MP-WEIXIN
const fs = wx.getFileSystemManager(),
userDataPath = wx.env.USER_DATA_PATH;
const filePath = params.filePath || `${userDataPath}/${params.name}.${params.extName}`;
wx.showLoading({
title: "文件下载中...",
});
wx.downloadFile({
url,
success(res) {
let tempFile = res.tempFilePath;
let img = ["png", "jpg", "gif"];
if (tempFile && img.includes(params.extName)) {
wx.saveImageToPhotosAlbum({
filePath: tempFile,
success: function () {
wx.showToast({
title: "保存成功!",
icon: "success",
});
},
fail() {
wx.showToast({
title: "保存失败!",
icon: "error",
});
},
});
} else {
fs.saveFile({
tempFilePath: tempFile,
filePath,
success: function () {
wx.showToast({
title: "保存成功!",
icon: "success",
});
},
fail() {
wx.showToast({
title: "保存失败!",
icon: "error",
});
},
});
}
},
fail() {
wx.showToast({
title: "下载失败!",
icon: "error",
});
},
complete() {
wx.hideLoading();
},
});
// #endif