update
This commit is contained in:
@@ -66,7 +66,16 @@ export const copy = (context) => {
|
||||
// #endif
|
||||
}
|
||||
|
||||
export const isVideoFile = (filename) => {
|
||||
const videoExtensions = ['.mp4', '.avi', '.mov', '.mkv', '.wmv', '.flv', '.webm', '.mpeg', '.mpg', '.3gp'];
|
||||
const fileExtension = filename.slice(((filename.lastIndexOf(".") - 1) >>> 0) + 2).toLowerCase();
|
||||
return videoExtensions.includes(`.${fileExtension}`);
|
||||
}
|
||||
|
||||
export const download = (urls) => {
|
||||
uni.showLoading({
|
||||
title: '下载中'
|
||||
});
|
||||
// #ifndef APP-PLUS || MP-WEIXIN
|
||||
const promises1 = urls.map(url => new Promise((resolve, reject) => {
|
||||
const iframe = document.createElement('iframe');
|
||||
@@ -77,8 +86,14 @@ export const download = (urls) => {
|
||||
}));
|
||||
Promise.all(promises1).then(() => {
|
||||
showToast('保存成功');
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 1000);
|
||||
}).catch(() => {
|
||||
showToast('保存失败');
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 1000);
|
||||
});
|
||||
// #endif
|
||||
|
||||
@@ -96,8 +111,14 @@ export const download = (urls) => {
|
||||
}));
|
||||
Promise.all(promises2).then(() => {
|
||||
showToast('保存成功');
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 1000);
|
||||
}).catch(() => {
|
||||
showToast('保存失败');
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 1000);
|
||||
});
|
||||
// #endif
|
||||
|
||||
@@ -106,7 +127,8 @@ export const download = (urls) => {
|
||||
uni.downloadFile({
|
||||
url: v,
|
||||
success: ({tempFilePath}) => {
|
||||
uni.saveImageToPhotosAlbum({
|
||||
const api = isVideoFile(tempFilePath) ? 'saveVideoToPhotosAlbum' : 'saveImageToPhotosAlbum';
|
||||
uni[api]({
|
||||
filePath: tempFilePath,
|
||||
success: () => {
|
||||
resolve(true);
|
||||
@@ -125,8 +147,14 @@ export const download = (urls) => {
|
||||
}));
|
||||
Promise.all(promises3).then(() => {
|
||||
showToast('保存成功');
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 1000);
|
||||
}).catch(() => {
|
||||
showToast('保存失败');
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 1000);
|
||||
});
|
||||
// #endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user