diff --git a/src/utils/uils.js b/src/utils/uils.js index 93561f7..890bd9c 100644 --- a/src/utils/uils.js +++ b/src/utils/uils.js @@ -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 }