emacroh5lib 1.0.22 → 1.0.25
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/dist/emacroh5lib.min.js +1 -1
- package/package.json +4 -2
- package/src/router/index.ts +4 -10
- package/src/utilities/File.ts +61 -37
- package/src/views/TestView/index.vue +32 -5
- package/tsconfig.json +1 -1
package/package.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "emacroh5lib",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.25",
|
4
4
|
"description": "EMacro前端组件库",
|
5
|
-
"main": "dist/emacroh5lib.min.js",
|
5
|
+
"main": "dist/emacroh5lib.min.js",
|
6
6
|
"scripts": {
|
7
7
|
"build": "webpack --mode=production --node-env=production",
|
8
8
|
"build:dev": "webpack --mode=development",
|
@@ -78,6 +78,7 @@
|
|
78
78
|
"@types/js-cookie": "^3.0.1",
|
79
79
|
"@vue/cli-plugin-typescript": "^5.0.4",
|
80
80
|
"axios": "^0.26.1",
|
81
|
+
"browser-md5-file": "^1.1.1",
|
81
82
|
"core-js": "^3.22.2",
|
82
83
|
"deep-eql": "^4.0.0",
|
83
84
|
"echarts": "^5.3.2",
|
@@ -92,6 +93,7 @@
|
|
92
93
|
"query-string": "^7.0.1",
|
93
94
|
"register-service-worker": "^1.7.2",
|
94
95
|
"three": "^0.139.2",
|
96
|
+
"types": "file:../../browser-md5-file",
|
95
97
|
"typings": "^2.1.1",
|
96
98
|
"vue": "^2.6.14",
|
97
99
|
"vue-class-component": "^7.2.3",
|
package/src/router/index.ts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
import Vue from 'vue'
|
2
2
|
import VueRouter, { RouteConfig } from 'vue-router'
|
3
3
|
import HomeView from '../views/HomeView.vue'
|
4
|
+
import FileViewer from '../views/FileViewer/index.vue'
|
5
|
+
import TestView from '../views/TestView/index.vue'
|
4
6
|
|
5
7
|
Vue.use(VueRouter)
|
6
8
|
|
@@ -10,23 +12,15 @@ const routes: Array<RouteConfig> = [
|
|
10
12
|
name: 'home',
|
11
13
|
component: HomeView
|
12
14
|
},
|
13
|
-
{
|
14
|
-
path: '/about',
|
15
|
-
name: 'about',
|
16
|
-
// route level code-splitting
|
17
|
-
// this generates a separate chunk (about.[hash].js) for this route
|
18
|
-
// which is lazy-loaded when the route is visited.
|
19
|
-
component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
|
20
|
-
},
|
21
15
|
{
|
22
16
|
path: '/FileViewer',
|
23
17
|
name: 'FileViewer',
|
24
|
-
component:
|
18
|
+
component: FileViewer
|
25
19
|
},
|
26
20
|
{
|
27
21
|
path: '/TestView',
|
28
22
|
name: 'TestView',
|
29
|
-
component:
|
23
|
+
component: TestView
|
30
24
|
},
|
31
25
|
]
|
32
26
|
|
package/src/utilities/File.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
import * as XLSX from "xlsx";
|
3
|
+
import BMF from 'browser-md5-file';
|
3
4
|
|
4
5
|
export namespace EMacro {
|
5
6
|
|
@@ -7,9 +8,25 @@ export namespace EMacro {
|
|
7
8
|
|
8
9
|
export class File {
|
9
10
|
|
10
|
-
public static getFileMD5(file
|
11
|
+
public static getFileMD5(file) {
|
12
|
+
return new Promise((res, rej) => {
|
11
13
|
|
12
|
-
|
14
|
+
const fileReader = new FileReader()
|
15
|
+
fileReader.readAsBinaryString(file);
|
16
|
+
fileReader.onload = e => {
|
17
|
+
const bmf = new BMF();
|
18
|
+
bmf.md5(file, (err, md5) => {
|
19
|
+
if (err !== null) {
|
20
|
+
rej(err)
|
21
|
+
} else {
|
22
|
+
res(md5)
|
23
|
+
}
|
24
|
+
}, progress => {
|
25
|
+
console.log('getFileMD5 progress number:', progress);
|
26
|
+
});
|
27
|
+
}
|
28
|
+
|
29
|
+
})
|
13
30
|
}
|
14
31
|
|
15
32
|
private static getBase64(blob) {
|
@@ -21,60 +38,67 @@ export namespace EMacro {
|
|
21
38
|
});
|
22
39
|
}
|
23
40
|
|
24
|
-
public static getFileChunks(file: any): any {
|
41
|
+
public static getFileChunks(file: any, chunkSize: number = 1024 * 1024 * 1): any {
|
25
42
|
|
26
|
-
let {size}
|
27
|
-
|
28
|
-
const sliceSize = 1024 * 1024 * 2;
|
29
|
-
let totalChunks = Math.ceil(size / sliceSize)
|
43
|
+
let { size } = file
|
44
|
+
let totalChunks = Math.ceil(size / chunkSize)
|
30
45
|
let fileChunks = new Array<any>()
|
31
|
-
if (size >
|
46
|
+
if (size > chunkSize) {
|
32
47
|
for (let i = 0; i < totalChunks; i++) {
|
33
|
-
let start = i *
|
34
|
-
let end = (i + 1) *
|
48
|
+
let start = i * chunkSize
|
49
|
+
let end = (i + 1) * chunkSize
|
35
50
|
let chunk = file.slice(start, end)
|
36
51
|
fileChunks.push(chunk)
|
37
52
|
}
|
38
53
|
} else {
|
39
54
|
fileChunks.push(file)
|
40
55
|
}
|
41
|
-
return { "fileChunks": fileChunks, "sliceSize":
|
56
|
+
return { "fileChunks": fileChunks, "sliceSize": chunkSize, "chunksLength": fileChunks.length }
|
42
57
|
}
|
43
58
|
|
44
59
|
// 文件上传
|
45
|
-
public static uploadFiles(files, postFunc, errFunc = (err) => {
|
60
|
+
public static uploadFiles(files, postFunc, chunkSize: number = 1024 * 1024 * 1, errFunc = (err) => {
|
46
61
|
console.error(err);
|
47
62
|
}) {
|
48
63
|
|
49
64
|
if (files[0].fileName == "" || files[0].fileSize == "" || files[0].fileSize == 0) {
|
50
|
-
throw new Error("
|
65
|
+
throw new Error("文件异常")
|
51
66
|
}
|
52
67
|
|
53
|
-
let that = this
|
54
68
|
for (let i = 0; i < files.length; i++) {
|
55
|
-
const file = files[i];
|
56
|
-
let { fileChunks, sliceSize, chunksLength } = File.getFileChunks(file)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
69
|
+
const file = files[i];
|
70
|
+
let { fileChunks, sliceSize, chunksLength } = File.getFileChunks(file, chunkSize)
|
71
|
+
|
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);
|
96
|
+
}
|
97
|
+
|
98
|
+
}).catch(err => {
|
99
|
+
throw err
|
100
|
+
})
|
101
|
+
|
78
102
|
}
|
79
103
|
}
|
80
104
|
|
@@ -4,6 +4,7 @@
|
|
4
4
|
<button @click="handleOpen">打开查看器</button>
|
5
5
|
<button @click="exportExcel($event)">透过Excel模板导出表格</button>
|
6
6
|
<button @click="selectFile($event)">选择文件</button>
|
7
|
+
<button @click="fileMD5($event)">文件MD5</button>
|
7
8
|
|
8
9
|
<image-viewer :list="srcList" @open="openCallback" @close="closeCallback" :show.sync="showViewer"
|
9
10
|
:currentIndex="currentIndex" />
|
@@ -45,10 +46,10 @@ import { EMacro } from "../../utilities/File";
|
|
45
46
|
import axios from 'axios'
|
46
47
|
import Cookie from 'js-cookie'
|
47
48
|
|
49
|
+
import LAY_EXCEL from 'lay-excel';
|
48
50
|
|
51
|
+
import BMF from 'browser-md5-file';
|
49
52
|
|
50
|
-
import LAY_EXCEL from 'lay-excel';
|
51
|
-
import { error } from "jquery";
|
52
53
|
|
53
54
|
@Component({
|
54
55
|
components: {
|
@@ -211,13 +212,10 @@ export default class TestView extends Vue {
|
|
211
212
|
|
212
213
|
|
213
214
|
EMacro.File.selectFile().then((files) => {
|
214
|
-
|
215
215
|
EMacro.File.uploadFiles(files, file => {
|
216
216
|
|
217
|
-
|
218
217
|
file.savePath = "C:\\MES\\EMacroAndroidServer_Windows_v1.1\\EMacroAssets\\file\\" + file.fileName
|
219
218
|
|
220
|
-
|
221
219
|
let postData = { 'id': 0, 'message': '', 'action': 'uploadSOPFile', 'user': {}, 'data': file }
|
222
220
|
axios.post("http://121.228.113.68:8019/H5/prod/Command/requestVueData", postData, {
|
223
221
|
timeout: 6000,
|
@@ -259,6 +257,35 @@ export default class TestView extends Vue {
|
|
259
257
|
console.log("changeSize index", index);
|
260
258
|
}
|
261
259
|
|
260
|
+
public fileMD5() {
|
261
|
+
|
262
|
+
EMacro.File.selectFile().then(files => {
|
263
|
+
|
264
|
+
if (files == null) {
|
265
|
+
return
|
266
|
+
}
|
267
|
+
|
268
|
+
EMacro.File.getFileMD5(files[0]).then(md5 => {
|
269
|
+
|
270
|
+
console.log("文件MD5", md5);
|
271
|
+
|
272
|
+
})
|
273
|
+
|
274
|
+
|
275
|
+
// new MD5().update(buffer).digest()
|
276
|
+
|
277
|
+
|
278
|
+
// const hash = crypto
|
279
|
+
// .createHash('md5')
|
280
|
+
// .update(files[0], 'utf8')
|
281
|
+
// .digest('hex');
|
282
|
+
|
283
|
+
})
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
}
|
288
|
+
|
262
289
|
public mounted() {
|
263
290
|
const listEl = document.getElementById('list') as HTMLElement;
|
264
291
|
this.listWidth = listEl.clientWidth;
|
package/tsconfig.json
CHANGED