update
This commit is contained in:
@@ -66,7 +66,16 @@ export const copy = (context) => {
|
|||||||
// #endif
|
// #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) => {
|
export const download = (urls) => {
|
||||||
|
uni.showLoading({
|
||||||
|
title: '下载中'
|
||||||
|
});
|
||||||
// #ifndef APP-PLUS || MP-WEIXIN
|
// #ifndef APP-PLUS || MP-WEIXIN
|
||||||
const promises1 = urls.map(url => new Promise((resolve, reject) => {
|
const promises1 = urls.map(url => new Promise((resolve, reject) => {
|
||||||
const iframe = document.createElement('iframe');
|
const iframe = document.createElement('iframe');
|
||||||
@@ -77,8 +86,14 @@ export const download = (urls) => {
|
|||||||
}));
|
}));
|
||||||
Promise.all(promises1).then(() => {
|
Promise.all(promises1).then(() => {
|
||||||
showToast('保存成功');
|
showToast('保存成功');
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.hideLoading();
|
||||||
|
}, 1000);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
showToast('保存失败');
|
showToast('保存失败');
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.hideLoading();
|
||||||
|
}, 1000);
|
||||||
});
|
});
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
@@ -96,8 +111,14 @@ export const download = (urls) => {
|
|||||||
}));
|
}));
|
||||||
Promise.all(promises2).then(() => {
|
Promise.all(promises2).then(() => {
|
||||||
showToast('保存成功');
|
showToast('保存成功');
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.hideLoading();
|
||||||
|
}, 1000);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
showToast('保存失败');
|
showToast('保存失败');
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.hideLoading();
|
||||||
|
}, 1000);
|
||||||
});
|
});
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
@@ -106,7 +127,8 @@ export const download = (urls) => {
|
|||||||
uni.downloadFile({
|
uni.downloadFile({
|
||||||
url: v,
|
url: v,
|
||||||
success: ({tempFilePath}) => {
|
success: ({tempFilePath}) => {
|
||||||
uni.saveImageToPhotosAlbum({
|
const api = isVideoFile(tempFilePath) ? 'saveVideoToPhotosAlbum' : 'saveImageToPhotosAlbum';
|
||||||
|
uni[api]({
|
||||||
filePath: tempFilePath,
|
filePath: tempFilePath,
|
||||||
success: () => {
|
success: () => {
|
||||||
resolve(true);
|
resolve(true);
|
||||||
@@ -125,8 +147,14 @@ export const download = (urls) => {
|
|||||||
}));
|
}));
|
||||||
Promise.all(promises3).then(() => {
|
Promise.all(promises3).then(() => {
|
||||||
showToast('保存成功');
|
showToast('保存成功');
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.hideLoading();
|
||||||
|
}, 1000);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
showToast('保存失败');
|
showToast('保存失败');
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.hideLoading();
|
||||||
|
}, 1000);
|
||||||
});
|
});
|
||||||
// #endif
|
// #endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user