emacroh5lib 1.0.18 → 1.0.21

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.18",
3
+ "version": "1.0.21",
4
4
  "description": "EMacro前端组件库",
5
5
  "main": "dist/emacroh5lib.min.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -4,11 +4,11 @@ import { EMacro } from "./utilities/File";
4
4
 
5
5
  import FileViewer from './views/FileViewer/index.vue'
6
6
  import ImageViewer from './views/ImageViewer/index.vue'
7
- import DragResizeView from './views/DragResizeViewTs/index.vue'
7
+ import DragResizeView from './views/DragResizeView/index.vue'
8
8
  import DragView from './views/Draw/index.vue'
9
9
  import MessageBoxTest from "@/components/MessageBoxTest";
10
10
 
11
- const components = [FileViewer, ImageViewer, DragResizeView, DragView];
11
+ const components = [FileViewer, ImageViewer, DragResizeView];
12
12
 
13
13
  const install = (Vue: any) => {
14
14
  if ((install as any).installed) return;
@@ -31,4 +31,4 @@ if (typeof window !== 'undefined' && (window as any).Vue) {
31
31
 
32
32
 
33
33
  export default {}
34
- export { EMacro,FileViewer, ImageViewer, DragResizeView, DragView }
34
+ export { EMacro,FileViewer, ImageViewer, DragResizeView }
@@ -1,3 +1,4 @@
1
+
1
2
  import * as XLSX from "xlsx";
2
3
 
3
4
  export namespace EMacro {
@@ -6,7 +7,74 @@ export namespace EMacro {
6
7
 
7
8
  export class File {
8
9
 
9
- private static selectFile(options: any = { multiple: true, accept: "*/*" }) {
10
+ public static getFileMD5(file: File): string {
11
+
12
+ throw "NG"
13
+ }
14
+
15
+ private static getBase64(blob) {
16
+ return new Promise((resolve, reject) => {
17
+ const reader = new FileReader();
18
+ reader.readAsDataURL(blob);
19
+ reader.onload = () => resolve(reader.result);
20
+ reader.onerror = error => reject(error);
21
+ });
22
+ }
23
+
24
+ public static getFileChunks(file: any): any {
25
+ let { size } = file
26
+ const sliceSize = 1024 * 1024 * 2;
27
+ let totalChunks = Math.ceil(size / sliceSize)
28
+ let fileChunks = new Array<any>()
29
+ if (size > sliceSize) {
30
+ for (let i = 0; i < totalChunks; i++) {
31
+ let start = i * sliceSize
32
+ let end = (i + 1) * sliceSize
33
+ let chunk = file.slice(start, end)
34
+ fileChunks.push(chunk)
35
+ }
36
+ } else {
37
+ fileChunks.push(file)
38
+ }
39
+ return { "fileChunks": fileChunks, "sliceSize": sliceSize, "chunksLength": fileChunks.length }
40
+ }
41
+
42
+ // 文件上传
43
+ public static uploadFiles(files, postFunc, errFunc: (err) => {}) {
44
+
45
+ if (files[0].fileName == "" || files[0].fileSize == "" || files[0].fileSize == 0) {
46
+ throw new Error("请选择要上传的文件")
47
+ }
48
+
49
+ let that = this
50
+ for (let i = 0; i < files.length; i++) {
51
+ const file = files[i];
52
+ let { fileChunks, sliceSize, chunksLength } = File.getFileChunks(file.file)
53
+ for (let index in fileChunks) {
54
+ let chunk = fileChunks[Number(index)]
55
+ setTimeout(async () => {
56
+ await File.getBase64(chunk).then((base64: any) => {
57
+ let data = {
58
+ 'chunkIndex': Number(index), // 分片位置
59
+ 'chunksLength': chunksLength, // 分片长度
60
+ 'sliceSize': sliceSize, // 分片大小
61
+ 'chunkSize': chunk.size, // 当前分片实际大小
62
+ 'fileSize': file.file.size, // 文件总大小
63
+ 'fileName': file.file.name, // 文件名
64
+ 'data': base64.split(';base64,')[1], // 文件数据
65
+ 'lastModifiedDate': file.file.lastModifiedDate, // 最后修改时间
66
+ 'dataType': 'base64' // 数据的类型
67
+ }
68
+ postFunc(data)
69
+ }).catch((err) => {
70
+ errFunc({ err: err, file: file.file, chunkIndex: index, fileName: file.file.name })
71
+ })
72
+ }, 10);
73
+ }
74
+ }
75
+ }
76
+
77
+ public static selectFile(options: any = { multiple: true, accept: "*/*" }): Promise<FileList | null> {
10
78
  return new Promise((res: (value: FileList) => void, rej) => {
11
79
  const el = document.createElement("input");
12
80
  el.type = "file";
@@ -29,7 +97,10 @@ export namespace EMacro {
29
97
 
30
98
  public static readLocalExcel(onloadend: (file, workbook) => void, options: any = { multiple: true, accept: "*/*" }) {
31
99
 
32
- this.selectFile(options).then((files: FileList) => {
100
+ this.selectFile(options).then((files: FileList | null) => {
101
+ if (files === null) {
102
+ return
103
+ }
33
104
  for (let i = 0; i < files.length; i++) {
34
105
  const file = files[i];
35
106
  let reader = new FileReader();
@@ -47,8 +118,7 @@ export namespace EMacro {
47
118
  }
48
119
 
49
120
  }
50
-
51
121
 
52
122
 
53
123
 
54
-
124
+