This commit is contained in:
王一嘉
2025-08-19 08:59:35 +08:00
parent 28515f5d3a
commit 0db9c62a8a

View File

@@ -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
}