Преглед изворни кода

上传附件功能优化调整

user5 пре 7 месеци
родитељ
комит
90aac0333d
1 измењених фајлова са 217 додато и 25 уклоњено
  1. 217 25
      src/main/webapp/static/oss/ossupload.js

+ 217 - 25
src/main/webapp/static/oss/ossupload.js

@@ -147,13 +147,24 @@ function CollectUploadWithSts(storeAs, file,attachmentId,attachmentFlag,uploadPa
             return alert(errmsg);
         }
         console.log("---------result"+result);
+        // 动态设置 timeout 时间,单位为毫秒
+        let timeout;
+        if (file.size <= 10 * 1024 * 1024) { // 小于10MB
+            timeout = 10000; // 10秒
+        } else if (file.size <= 100 * 1024 * 1024) { // 小于100MB
+            timeout = 30000; // 30秒
+        } else { // 大于100MB
+            timeout = 60000; // 60秒
+        }
+
+
         client = new OSS.Wrapper({
             accessKeyId: result.AccessKeyId,
             accessKeySecret: result.AccessKeySecret,
             stsToken: result.SecurityToken,
             bucket: result.Bucket,
             endpoint: result.Endpoint,
-            timeout:'30000'
+            timeout:timeout
         });
         storeAs = "attachment-file/" + storeAs +"/"+today+new Date().getTime()+ file.name;
         if(cpt == 1)
@@ -209,13 +220,24 @@ function multipartUploadWithStsOnProcessAccessory(storeAs, file,attachmentId,att
             return alert(errmsg);
         }
         console.log("---------result"+result);
+        // 动态设置 timeout 时间,单位为毫秒
+        let timeout;
+        if (file.size <= 10 * 1024 * 1024) { // 小于10MB
+            timeout = 10000; // 10秒
+        } else if (file.size <= 100 * 1024 * 1024) { // 小于100MB
+            timeout = 30000; // 30秒
+        } else { // 大于100MB
+            timeout = 60000; // 60秒
+        }
+
+
         client = new OSS.Wrapper({
             accessKeyId: result.AccessKeyId,
             accessKeySecret: result.AccessKeySecret,
             stsToken: result.SecurityToken,
             bucket: result.Bucket,
             endpoint: result.Endpoint,
-            timeout:'30000'
+            timeout:timeout
         });
         storeAs = "attachment-file/" + storeAs +"/"+today+new Date().getTime()+ file.name;
         multitestOnProcessAccessory(client, storeAs, file,attachmentId,attachmentFlag,uploadPath.replace('http://dmtest-test.oss-cn-shanghai.aliyuncs.com', result.AliyunUrl),divId,size, fileCount);
@@ -271,13 +293,25 @@ function multipartUploadWithSts(storeAs, file,attachmentId,attachmentFlag,upload
             return alert(errmsg);
         }
         console.log("---------result"+result);
+
+        // 动态设置 timeout 时间,单位为毫秒
+        let timeout;
+        if (file.size <= 10 * 1024 * 1024) { // 小于10MB
+            timeout = 10000; // 10秒
+        } else if (file.size <= 100 * 1024 * 1024) { // 小于100MB
+            timeout = 30000; // 30秒
+        } else { // 大于100MB
+            timeout = 60000; // 60秒
+        }
+
+
         client = new OSS.Wrapper({
             accessKeyId: result.AccessKeyId,
             accessKeySecret: result.AccessKeySecret,
             stsToken: result.SecurityToken,
             bucket: result.Bucket,
             endpoint: result.Endpoint,
-            timeout:'30000'
+            timeout:timeout
         });
         storeAs = "attachment-file/" + storeAs +"/"+today+new Date().getTime()+ file.name;
         if(cpt == 1)
@@ -335,13 +369,24 @@ function multipartUploadWithExter(storeAs, file,attachmentId,attachmentFlag,uplo
             return alert(errmsg);
         }
         console.log("---------result"+result);
+        // 动态设置 timeout 时间,单位为毫秒
+        let timeout;
+        if (file.size <= 10 * 1024 * 1024) { // 小于10MB
+            timeout = 10000; // 10秒
+        } else if (file.size <= 100 * 1024 * 1024) { // 小于100MB
+            timeout = 30000; // 30秒
+        } else { // 大于100MB
+            timeout = 60000; // 60秒
+        }
+
+
         client = new OSS.Wrapper({
             accessKeyId: result.AccessKeyId,
             accessKeySecret: result.AccessKeySecret,
             stsToken: result.SecurityToken,
             bucket: result.Bucket,
             endpoint: result.Endpoint,
-            timeout:'30000'
+            timeout:timeout
         });
         storeAs = "attachment-file/" + storeAs +"/"+new Date().getTime()+ file.name;
         if(cpt == 1)
@@ -398,13 +443,24 @@ function multipartUploadWorkOrder(storeAs, file,attachmentId,attachmentFlag,uplo
             return alert(errmsg);
         }
         console.log("---------result"+result);
+        // 动态设置 timeout 时间,单位为毫秒
+        let timeout;
+        if (file.size <= 10 * 1024 * 1024) { // 小于10MB
+            timeout = 10000; // 10秒
+        } else if (file.size <= 100 * 1024 * 1024) { // 小于100MB
+            timeout = 30000; // 30秒
+        } else { // 大于100MB
+            timeout = 60000; // 60秒
+        }
+
+
         client = new OSS.Wrapper({
             accessKeyId: result.AccessKeyId,
             accessKeySecret: result.AccessKeySecret,
             stsToken: result.SecurityToken,
             bucket: result.Bucket,
             endpoint: result.Endpoint,
-            timeout:'30000'
+            timeout:timeout
         });
         storeAs = "attachment-file/" + storeAs +"/"+today+new Date().getTime()+ file.name;
         if(cpt == 1)
@@ -644,13 +700,24 @@ function multipartUploadWithStsCollection(storeAs, file,attachmentId,attachmentF
             return alert(errmsg);
         }
         console.log("---------result"+result);
+        // 动态设置 timeout 时间,单位为毫秒
+        let timeout;
+        if (file.size <= 10 * 1024 * 1024) { // 小于10MB
+            timeout = 10000; // 10秒
+        } else if (file.size <= 100 * 1024 * 1024) { // 小于100MB
+            timeout = 30000; // 30秒
+        } else { // 大于100MB
+            timeout = 60000; // 60秒
+        }
+
+
         client = new OSS.Wrapper({
             accessKeyId: result.AccessKeyId,
             accessKeySecret: result.AccessKeySecret,
             stsToken: result.SecurityToken,
             bucket: result.Bucket,
             endpoint: result.Endpoint,
-            timeout:'30000'
+            timeout:timeout
         });
         storeAs = url;
         if(cpt == 1)
@@ -709,13 +776,24 @@ function multipartUploadWithStsCollectionCollect(storeAs, file,attachmentId,atta
             return alert(errmsg);
         }
         console.log("---------result"+result);
+        // 动态设置 timeout 时间,单位为毫秒
+        let timeout;
+        if (file.size <= 10 * 1024 * 1024) { // 小于10MB
+            timeout = 10000; // 10秒
+        } else if (file.size <= 100 * 1024 * 1024) { // 小于100MB
+            timeout = 30000; // 30秒
+        } else { // 大于100MB
+            timeout = 60000; // 60秒
+        }
+
+
         client = new OSS.Wrapper({
             accessKeyId: result.AccessKeyId,
             accessKeySecret: result.AccessKeySecret,
             stsToken: result.SecurityToken,
             bucket: result.Bucket,
             endpoint: result.Endpoint,
-            timeout:'30000'
+            timeout:timeout
         });
         storeAs = url;
         multitestCollectionCollect(client, storeAs, file,attachmentId,attachmentFlag,uploadPath.replace('http://dmtest-test.oss-cn-shanghai.aliyuncs.com', result.AliyunUrl),divId,size, fileCount,fileUrl,fileSize);
@@ -1164,11 +1242,22 @@ function multitestFlag (ossClient,storeAs, file,attachmentId,attachmentFlag,uplo
 
 function multitest (ossClient, storeAs, file,attachmentId,attachmentFlag,uploadPath,divId, size,cpt) {
 
+    // 根据文件大小动态配置 parallel
+    let parallel;
+    if (file.size < 50 * 1024 * 1024) { // 小于 50 MB
+        parallel = 1;
+    } else if (file.size < 200 * 1024 * 1024) { // 50 MB 到 200 MB
+        parallel = 3;
+    } else if (file.size < 1024 * 1024 * 1024) { // 200 MB 到 1 GB
+        parallel = 5;
+    } else { // 大于 1 GB
+        parallel = 8;
+    }
     var names =  storeAs.split("/");
     var name = names[names.length-1];
     ossClient.multipartUpload(storeAs, file,{
         partSize: 1 * 1024 * 1024,
-        parallel: 5,
+        parallel: parallel,
         progress: function* (percent, cpt) {
             var p = Math.floor(percent*100);
             $("#jindutiao"+divId).attr("style","width: "+p+"%");
@@ -1292,12 +1381,22 @@ function multitest (ossClient, storeAs, file,attachmentId,attachmentFlag,uploadP
     });
 };
 function CollectMultitest (ossClient, storeAs, file,attachmentId,attachmentFlag,uploadPath,divId, size,cpt) {
-
+    // 根据文件大小动态配置 parallel
+    let parallel;
+    if (file.size < 50 * 1024 * 1024) { // 小于 50 MB
+        parallel = 1;
+    } else if (file.size < 200 * 1024 * 1024) { // 50 MB 到 200 MB
+        parallel = 3;
+    } else if (file.size < 1024 * 1024 * 1024) { // 200 MB 到 1 GB
+        parallel = 5;
+    } else { // 大于 1 GB
+        parallel = 8;
+    }
     var names =  storeAs.split("/");
     var name = names[names.length-1];
     ossClient.multipartUpload(storeAs, file,{
         partSize: 1 * 1024 * 1024,
-        parallel: 5,
+        parallel: parallel,
         progress: function* (percent, cpt) {
             var p = Math.floor(percent*100);
             $("#jindutiao"+divId).attr("style","width: "+p+"%");
@@ -1413,12 +1512,22 @@ function CollectMultitest (ossClient, storeAs, file,attachmentId,attachmentFlag,
     });
 };
 function multitestWorkOrder (ossClient, storeAs, file,attachmentId,attachmentFlag,uploadPath,divId, size,cpt) {
-
+    // 根据文件大小动态配置 parallel
+    let parallel;
+    if (file.size < 50 * 1024 * 1024) { // 小于 50 MB
+        parallel = 1;
+    } else if (file.size < 200 * 1024 * 1024) { // 50 MB 到 200 MB
+        parallel = 3;
+    } else if (file.size < 1024 * 1024 * 1024) { // 200 MB 到 1 GB
+        parallel = 5;
+    } else { // 大于 1 GB
+        parallel = 8;
+    }
     var names =  storeAs.split("/");
     var name = names[names.length-1];
     ossClient.multipartUpload(storeAs, file,{
         partSize: 1 * 1024 * 1024,
-        parallel: 5,
+        parallel: parallel,
         progress: function* (percent, cpt) {
             var p = Math.floor(percent*100);
             $("#jindutiao"+divId).attr("style","width: "+p+"%");
@@ -1568,13 +1677,24 @@ function multipartUploadWithStsRecordsReported(storeAs, file,attachmentId,attach
             return alert(errmsg);
         }
         console.log("---------result"+result);
+        // 动态设置 timeout 时间,单位为毫秒
+        let timeout;
+        if (file.size <= 10 * 1024 * 1024) { // 小于10MB
+            timeout = 10000; // 10秒
+        } else if (file.size <= 100 * 1024 * 1024) { // 小于100MB
+            timeout = 30000; // 30秒
+        } else { // 大于100MB
+            timeout = 60000; // 60秒
+        }
+
+
         client = new OSS.Wrapper({
             accessKeyId: result.AccessKeyId,
             accessKeySecret: result.AccessKeySecret,
             stsToken: result.SecurityToken,
             bucket: result.Bucket,
             endpoint: result.Endpoint,
-            timeout:'30000'
+            timeout:timeout
         });
         storeAs = "attachment-file/" + storeAs +"/"+today+new Date().getTime()+ file.name;
         if(cpt == 1)
@@ -1584,12 +1704,22 @@ function multipartUploadWithStsRecordsReported(storeAs, file,attachmentId,attach
     })
 };
 function multitestRecordsReported (ossClient, storeAs, file,attachmentId,attachmentFlag,uploadPath,divId, size,cpt) {
-
+    // 根据文件大小动态配置 parallel
+    let parallel;
+    if (file.size < 50 * 1024 * 1024) { // 小于 50 MB
+        parallel = 1;
+    } else if (file.size < 200 * 1024 * 1024) { // 50 MB 到 200 MB
+        parallel = 3;
+    } else if (file.size < 1024 * 1024 * 1024) { // 200 MB 到 1 GB
+        parallel = 5;
+    } else { // 大于 1 GB
+        parallel = 8;
+    }
     var names =  storeAs.split("/");
     var name = names[names.length-1];
     ossClient.multipartUpload(storeAs, file,{
         partSize: 1 * 1024 * 1024,
-        parallel: 5,
+        parallel: parallel,
         progress: function* (percent, cpt) {
             var p = Math.floor(percent*100);
             $("#jindutiao"+divId).attr("style","width: "+p+"%");
@@ -1711,12 +1841,22 @@ function multitestRecordsReported (ossClient, storeAs, file,attachmentId,attachm
 
 
 function multitestOnProcessAccessory (ossClient, storeAs, file,attachmentId,attachmentFlag,uploadPath,divId, size,fileCount) {
-
+    // 根据文件大小动态配置 parallel
+    let parallel;
+    if (file.size < 50 * 1024 * 1024) { // 小于 50 MB
+        parallel = 1;
+    } else if (file.size < 200 * 1024 * 1024) { // 50 MB 到 200 MB
+        parallel = 3;
+    } else if (file.size < 1024 * 1024 * 1024) { // 200 MB 到 1 GB
+        parallel = 5;
+    } else { // 大于 1 GB
+        parallel = 8;
+    }
     var names =  storeAs.split("/");
     var name = names[names.length-1];
     ossClient.multipartUpload(storeAs, file,{
         partSize: 1 * 1024 * 1024,
-        parallel: 5,
+        parallel: parallel,
         progress: function* (percent, cpt) {
             var p = Math.floor(percent*100);
             $("#jindutiao"+divId).attr("style","width: "+p+"%");
@@ -2125,13 +2265,24 @@ function invoiceReimbursementMultipartUploadWithSts(storeAs, file,attachmentId,a
             return alert(errmsg);
         }
         console.log("---------result"+result);
+        // 动态设置 timeout 时间,单位为毫秒
+        let timeout;
+        if (file.size <= 10 * 1024 * 1024) { // 小于10MB
+            timeout = 10000; // 10秒
+        } else if (file.size <= 100 * 1024 * 1024) { // 小于100MB
+            timeout = 30000; // 30秒
+        } else { // 大于100MB
+            timeout = 60000; // 60秒
+        }
+
+
         client = new OSS.Wrapper({
             accessKeyId: result.AccessKeyId,
             accessKeySecret: result.AccessKeySecret,
             stsToken: result.SecurityToken,
             bucket: result.Bucket,
             endpoint: result.Endpoint,
-            timeout:'30000'
+            timeout:timeout
         });
         storeAs = "attachment-file/" + storeAs +"/"+today+new Date().getTime()+ file.name;
         invoiceReimbursementMultitest(client, storeAs, file,attachmentId,attachmentFlag,uploadPath.replace('http://dmtest-test.oss-cn-shanghai.aliyuncs.com', result.AliyunUrl),divId,size, cpt);
@@ -2140,12 +2291,22 @@ function invoiceReimbursementMultipartUploadWithSts(storeAs, file,attachmentId,a
 
 
 function invoiceReimbursementMultitest (ossClient, storeAs, file,attachmentId,attachmentFlag,uploadPath,divId, size,cpt) {
-
+    // 根据文件大小动态配置 parallel
+    let parallel;
+    if (file.size < 50 * 1024 * 1024) { // 小于 50 MB
+        parallel = 1;
+    } else if (file.size < 200 * 1024 * 1024) { // 50 MB 到 200 MB
+        parallel = 3;
+    } else if (file.size < 1024 * 1024 * 1024) { // 200 MB 到 1 GB
+        parallel = 5;
+    } else { // 大于 1 GB
+        parallel = 8;
+    }
     var names =  storeAs.split("/");
     var name = names[names.length-1];
     ossClient.multipartUpload(storeAs, file,{
         partSize: 1 * 1024 * 1024,
-        parallel: 5,
+        parallel: parallel,
         progress: function* (percent, cpt) {
             var p = Math.floor(percent*100);
             $("#jindutiao"+divId).attr("style","width: "+p+"%");
@@ -2407,12 +2568,22 @@ function fileCollectAccessory(storeAs, file,attachmentId,attachmentFlag,uploadPa
 };
 
 function collectAccessory (ossClient, storeAs, file,attachmentId,attachmentFlag,uploadPath,divId, size,cpt) {
-
+    // 根据文件大小动态配置 parallel
+    let parallel;
+    if (file.size < 50 * 1024 * 1024) { // 小于 50 MB
+        parallel = 1;
+    } else if (file.size < 200 * 1024 * 1024) { // 50 MB 到 200 MB
+        parallel = 3;
+    } else if (file.size < 1024 * 1024 * 1024) { // 200 MB 到 1 GB
+        parallel = 5;
+    } else { // 大于 1 GB
+        parallel = 8;
+    }
     var names =  storeAs.split("/");
     var name = names[names.length-1];
     ossClient.multipartUpload(storeAs, file,{
         partSize: 1 * 1024 * 1024,
-        parallel: 5,
+        parallel: parallel,
         progress: function* (percent, cpt) {
             var p = Math.floor(percent*100);
             $("#jindutiao"+divId).attr("style","width: "+p+"%");
@@ -2640,13 +2811,24 @@ function multiTypePartUploadWithSts(storeAs, file,attachmentId,attachmentFlag,up
             return alert(errmsg);
         }
         console.log("---------result"+result);
+        // 动态设置 timeout 时间,单位为毫秒
+        let timeout;
+        if (file.size <= 10 * 1024 * 1024) { // 小于10MB
+            timeout = 10000; // 10秒
+        } else if (file.size <= 100 * 1024 * 1024) { // 小于100MB
+            timeout = 30000; // 30秒
+        } else { // 大于100MB
+            timeout = 60000; // 60秒
+        }
+
+
         client = new OSS.Wrapper({
             accessKeyId: result.AccessKeyId,
             accessKeySecret: result.AccessKeySecret,
             stsToken: result.SecurityToken,
             bucket: result.Bucket,
             endpoint: result.Endpoint,
-            timeout:'30000'
+            timeout:timeout
         });
         storeAs = "attachment-file/" + storeAs +"/"+today+new Date().getTime()+ file.name;
         if(cpt == 1)
@@ -2658,12 +2840,22 @@ function multiTypePartUploadWithSts(storeAs, file,attachmentId,attachmentFlag,up
 
 
 function multiTypeTest (ossClient, storeAs, file,attachmentId,attachmentFlag,uploadPath,divId,type, size,cpt) {
-
+    // 根据文件大小动态配置 parallel
+    let parallel;
+    if (file.size < 50 * 1024 * 1024) { // 小于 50 MB
+        parallel = 1;
+    } else if (file.size < 200 * 1024 * 1024) { // 50 MB 到 200 MB
+        parallel = 3;
+    } else if (file.size < 1024 * 1024 * 1024) { // 200 MB 到 1 GB
+        parallel = 5;
+    } else { // 大于 1 GB
+        parallel = 8;
+    }
     var names =  storeAs.split("/");
     var name = names[names.length-1];
     ossClient.multipartUpload(storeAs, file,{
         partSize: 1 * 1024 * 1024,
-        parallel: 5,
+        parallel: parallel,
         progress: function* (percent, cpt) {
             var p = Math.floor(percent*100);
             $("#jindutiao"+divId).attr("style","width: "+p+"%");