emacroh5lib 1.0.26 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emacroh5lib",
3
- "version": "1.0.26",
3
+ "version": "1.0.29",
4
4
  "description": "EMacro前端组件库",
5
5
  "main": "dist/emacroh5lib.min.js",
6
6
  "scripts": {
@@ -93,6 +93,7 @@
93
93
  "lay-excel": "^1.7.6",
94
94
  "query-string": "^7.0.1",
95
95
  "register-service-worker": "^1.7.2",
96
+ "sync-task-queue": "^1.0.4",
96
97
  "three": "^0.139.2",
97
98
  "types": "file:../../browser-md5-file",
98
99
  "typings": "^2.1.1",
@@ -2,6 +2,8 @@
2
2
  import * as XLSX from "xlsx";
3
3
  import BMF from 'browser-md5-file';
4
4
 
5
+ import createTaskQueue from 'sync-task-queue'
6
+
5
7
  export namespace EMacro {
6
8
 
7
9
  export const version = "1.0"
@@ -57,7 +59,7 @@ export namespace EMacro {
57
59
  }
58
60
 
59
61
  // 文件上传
60
- public static uploadFiles(files, postFunc, chunkSize: number = 1024 * 1024 * 1, errFunc = (err) => {
62
+ public static async uploadFiles(files, postFunc, chunkSize: number = 1024 * 1024 * 1, errFunc = (err) => {
61
63
  console.error(err);
62
64
  }) {
63
65
 
@@ -67,37 +69,27 @@ export namespace EMacro {
67
69
 
68
70
  for (let i = 0; i < files.length; i++) {
69
71
  const file = files[i];
72
+ const md5 = await File.getFileMD5(file)
73
+
70
74
  let { fileChunks, sliceSize, chunksLength } = File.getFileChunks(file, chunkSize)
71
75
 
72
- File.getFileMD5(file).then(md5 => {
73
-
74
- for (let index in fileChunks) {
75
- let chunk = fileChunks[Number(index)]
76
-
77
- setTimeout(async () => {
78
- await File.getBase64(chunk).then((base64: any) => {
79
- let data = {
80
- 'chunkIndex': Number(index), // 分片位置
81
- 'chunksLength': chunksLength, // 分片长度
82
- 'sliceSize': sliceSize, // 分片大小
83
- 'chunkSize': chunk.size, // 当前分片实际大小
84
- 'fileSize': file.size, // 文件总大小
85
- 'fileName': file.name, // 文件名
86
- 'data': base64.split(';base64,')[1], // 文件数据
87
- 'lastModifiedDate': file.lastModifiedDate, // 最后修改时间
88
- 'md5': md5,
89
- 'dataType': 'base64' // 数据的类型
90
- }
91
- postFunc(data)
92
- }).catch((err) => {
93
- errFunc({ err: err, file: file.file, chunkIndex: index, fileName: file.name })
94
- })
95
- }, 10);
76
+ for (let index in fileChunks) {
77
+ let chunk = fileChunks[Number(index)]
78
+ const base64 = await File.getBase64(chunk) as string
79
+ let data = {
80
+ 'chunkIndex': Number(index), // 分片位置
81
+ 'chunksLength': chunksLength, // 分片长度
82
+ 'sliceSize': sliceSize, // 分片大小
83
+ 'chunkSize': chunk.size, // 当前分片实际大小
84
+ 'fileSize': file.size, // 文件总大小
85
+ 'fileName': file.name, // 文件名
86
+ 'data': base64.split(';base64,')[1], // 文件数据
87
+ 'lastModifiedDate': file.lastModifiedDate, // 最后修改时间
88
+ 'md5': md5,
89
+ 'dataType': 'base64' // 数据的类型
96
90
  }
97
-
98
- }).catch(err => {
99
- throw err
100
- })
91
+ await postFunc(data)
92
+ }
101
93
 
102
94
  }
103
95
  }