Browse Source

批量下载默认提示

MaiXinRong 2 years ago
parent
commit
302bc0a848
1 changed files with 15 additions and 1 deletions
  1. 15 1
      app/public/js/shares/ali_oss.js

+ 15 - 1
app/public/js/shares/ali_oss.js

@@ -1,4 +1,8 @@
 const AliOss = (function (){
+    const setting = {
+        hint: true
+    };
+
     const downloadFile = function (url, filename) {
         axios.get(url, {responseType: 'blob' }).then(res => {
             saveAs(res.data, filename);
@@ -20,6 +24,9 @@ const AliOss = (function (){
         const download = [], fails = [];
         files.forEach(f => {
             download.push(downloadFileSync(f.filepath).then(data => {
+                if (setting.hint) {
+                    toastr.success(`文件 “${f.filename + f.fileext}” 下载成功...`);
+                }
                 zip.file(f.filename + f.fileext, data, {binary: true});
             }).catch(err => {
                 fails.push(f);
@@ -27,6 +34,7 @@ const AliOss = (function (){
         });
         Promise.all(download).then(() => {
             if (fails.length < files.length) {
+                if (setting.hint) toastr.success('所有文件下载成功,压缩中...');
                 zip.generateAsync({ type: "blob" }).then(content => {
                     saveAs(content, filename);
                     successCallback && successCallback(fails);
@@ -37,5 +45,11 @@ const AliOss = (function (){
         })
     };
 
-    return { downloadFile, downloadFileSync, zipFiles}
+    const setSetting = function(data) {
+        if (!data) return;
+
+        setting.hint = data.hint || setting.hint;
+    };
+
+    return { downloadFile, downloadFileSync, zipFiles, setSetting }
 })();