emacroh5lib 1.0.28 → 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.28",
3
+ "version": "1.0.29",
4
4
  "description": "EMacro前端组件库",
5
5
  "main": "dist/emacroh5lib.min.js",
6
6
  "scripts": {
@@ -59,7 +59,7 @@ export namespace EMacro {
59
59
  }
60
60
 
61
61
  // 文件上传
62
- 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) => {
63
63
  console.error(err);
64
64
  }) {
65
65
 
@@ -69,39 +69,27 @@ export namespace EMacro {
69
69
 
70
70
  for (let i = 0; i < files.length; i++) {
71
71
  const file = files[i];
72
- let { fileChunks, sliceSize, chunksLength } = File.getFileChunks(file, chunkSize)
73
-
74
- File.getFileMD5(file).then(md5 => {
75
-
76
- const taskQueue = createTaskQueue();
77
-
78
- for (let index in fileChunks) {
79
- let chunk = fileChunks[Number(index)]
72
+ const md5 = await File.getFileMD5(file)
80
73
 
81
- File.getBase64(chunk).then((base64: any) => {
82
- let data = {
83
- 'chunkIndex': Number(index), // 分片位置
84
- 'chunksLength': chunksLength, // 分片长度
85
- 'sliceSize': sliceSize, // 分片大小
86
- 'chunkSize': chunk.size, // 当前分片实际大小
87
- 'fileSize': file.size, // 文件总大小
88
- 'fileName': file.name, // 文件名
89
- 'data': base64.split(';base64,')[1], // 文件数据
90
- 'lastModifiedDate': file.lastModifiedDate, // 最后修改时间
91
- 'md5': md5,
92
- 'dataType': 'base64' // 数据的类型
93
- }
94
-
95
- taskQueue.enqueue(postFunc(data)).then((res) => console.log('文件上传chunkIndex: ', index, res));
74
+ let { fileChunks, sliceSize, chunksLength } = File.getFileChunks(file, chunkSize)
96
75
 
97
- }).catch((err) => {
98
- errFunc({ err: err, file: file.file, chunkIndex: index, fileName: file.name })
99
- })
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' // 数据的类型
100
90
  }
101
-
102
- }).catch(err => {
103
- throw err
104
- })
91
+ await postFunc(data)
92
+ }
105
93
 
106
94
  }
107
95
  }