emacroh5lib 1.0.19 → 1.0.22

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.19",
3
+ "version": "1.0.22",
4
4
  "description": "EMacro前端组件库",
5
5
  "main": "dist/emacroh5lib.min.js",
6
6
  "scripts": {
@@ -1,3 +1,4 @@
1
+
1
2
  import * as XLSX from "xlsx";
2
3
 
3
4
  export namespace EMacro {
@@ -6,7 +7,78 @@ 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
+
26
+ let {size} = file
27
+
28
+ const sliceSize = 1024 * 1024 * 2;
29
+ let totalChunks = Math.ceil(size / sliceSize)
30
+ let fileChunks = new Array<any>()
31
+ if (size > sliceSize) {
32
+ for (let i = 0; i < totalChunks; i++) {
33
+ let start = i * sliceSize
34
+ let end = (i + 1) * sliceSize
35
+ let chunk = file.slice(start, end)
36
+ fileChunks.push(chunk)
37
+ }
38
+ } else {
39
+ fileChunks.push(file)
40
+ }
41
+ return { "fileChunks": fileChunks, "sliceSize": sliceSize, "chunksLength": fileChunks.length }
42
+ }
43
+
44
+ // 文件上传
45
+ public static uploadFiles(files, postFunc, errFunc = (err) => {
46
+ console.error(err);
47
+ }) {
48
+
49
+ if (files[0].fileName == "" || files[0].fileSize == "" || files[0].fileSize == 0) {
50
+ throw new Error("文件列表为空")
51
+ }
52
+
53
+ let that = this
54
+ for (let i = 0; i < files.length; i++) {
55
+ const file = files[i];
56
+ let { fileChunks, sliceSize, chunksLength } = File.getFileChunks(file)
57
+ for (let index in fileChunks) {
58
+ let chunk = fileChunks[Number(index)]
59
+ setTimeout(async () => {
60
+ await File.getBase64(chunk).then((base64: any) => {
61
+ let data = {
62
+ 'chunkIndex': Number(index), // 分片位置
63
+ 'chunksLength': chunksLength, // 分片长度
64
+ 'sliceSize': sliceSize, // 分片大小
65
+ 'chunkSize': chunk.size, // 当前分片实际大小
66
+ 'fileSize': file.size, // 文件总大小
67
+ 'fileName': file.name, // 文件名
68
+ 'data': base64.split(';base64,')[1], // 文件数据
69
+ 'lastModifiedDate': file.lastModifiedDate, // 最后修改时间
70
+ 'dataType': 'base64' // 数据的类型
71
+ }
72
+ postFunc(data)
73
+ }).catch((err) => {
74
+ errFunc({ err: err, file: file.file, chunkIndex: index, fileName: file.name })
75
+ })
76
+ }, 10);
77
+ }
78
+ }
79
+ }
80
+
81
+ public static selectFile(options: any = { multiple: true, accept: "*/*" }): Promise<FileList | null> {
10
82
  return new Promise((res: (value: FileList) => void, rej) => {
11
83
  const el = document.createElement("input");
12
84
  el.type = "file";
@@ -29,7 +101,10 @@ export namespace EMacro {
29
101
 
30
102
  public static readLocalExcel(onloadend: (file, workbook) => void, options: any = { multiple: true, accept: "*/*" }) {
31
103
 
32
- this.selectFile(options).then((files: FileList) => {
104
+ this.selectFile(options).then((files: FileList | null) => {
105
+ if (files === null) {
106
+ return
107
+ }
33
108
  for (let i = 0; i < files.length; i++) {
34
109
  const file = files[i];
35
110
  let reader = new FileReader();
@@ -47,8 +122,7 @@ export namespace EMacro {
47
122
  }
48
123
 
49
124
  }
50
-
51
125
 
52
126
 
53
127
 
54
-
128
+
@@ -3,15 +3,18 @@
3
3
 
4
4
  <button @click="handleOpen">打开查看器</button>
5
5
  <button @click="exportExcel($event)">透过Excel模板导出表格</button>
6
+ <button @click="selectFile($event)">选择文件</button>
6
7
 
7
8
  <image-viewer :list="srcList" @open="openCallback" @close="closeCallback" :show.sync="showViewer"
8
9
  :currentIndex="currentIndex" />
9
10
 
10
11
 
12
+
13
+
11
14
  <div class="list" id="list">
12
15
 
13
- <DragResizeView v-for="(rect, index) in rects" :key="index" :isStorage="true" :name="rect.name" :w="rect.width" :h="rect.height"
14
- :x="rect.left" :y="rect.top" :parentW="listWidth" :parentH="listHeight" :axis="rect.axis"
16
+ <DragResizeView v-for="(rect, index) in rects" :key="index" :isStorage="true" :name="rect.name" :w="rect.width"
17
+ :h="rect.height" :x="rect.left" :y="rect.top" :parentW="listWidth" :parentH="listHeight" :axis="rect.axis"
15
18
  :isActive="rect.active" :minw="rect.minw" :minh="rect.minh" :isDraggable="rect.draggable"
16
19
  :isResizable="rect.resizable" :parentLimitation="rect.parentLim" :snapToGrid="rect.snapToGrid"
17
20
  :aspectRatio="rect.aspectRatio" :z="rect.zIndex" :contentClass="rect.class" v-on:activated="activateEv(index)"
@@ -37,10 +40,15 @@ import DragResizeView from "@/views/DragResizeView/index.vue";
37
40
  import Draw from "@/views/Draw/index.vue";
38
41
 
39
42
  import { formatJson, export_json_to_excel, number_to_excel, testToExcel } from "./Export2Excel"
43
+ import { EMacro } from "../../utilities/File";
44
+
45
+ import axios from 'axios'
46
+ import Cookie from 'js-cookie'
40
47
 
41
48
 
42
49
 
43
50
  import LAY_EXCEL from 'lay-excel';
51
+ import { error } from "jquery";
44
52
 
45
53
  @Component({
46
54
  components: {
@@ -199,6 +207,40 @@ export default class TestView extends Vue {
199
207
  LAY_EXCEL.exportExcel(list, '表格导出.xlsx', 'xlsx')
200
208
  }
201
209
 
210
+ public selectFile(e) {
211
+
212
+
213
+ EMacro.File.selectFile().then((files) => {
214
+
215
+ EMacro.File.uploadFiles(files, file => {
216
+
217
+
218
+ file.savePath = "C:\\MES\\EMacroAndroidServer_Windows_v1.1\\EMacroAssets\\file\\" + file.fileName
219
+
220
+
221
+ let postData = { 'id': 0, 'message': '', 'action': 'uploadSOPFile', 'user': {}, 'data': file }
222
+ axios.post("http://121.228.113.68:8019/H5/prod/Command/requestVueData", postData, {
223
+ timeout: 6000,
224
+ headers: {
225
+ Authorization: "Basic RU1hY3JvOkVNYWNybw==",
226
+ "Content-Type": "application/json;charset=UTF-8",
227
+ }
228
+ }).then(data => {
229
+
230
+ console.log("上传返回", data);
231
+
232
+ }).catch(err => {
233
+ console.error("上传错误: ", err);
234
+ })
235
+
236
+ })
237
+
238
+ }).catch(err => {
239
+ console.error(err);
240
+ })
241
+
242
+ }
243
+
202
244
  activateEv(index) {
203
245
  console.log("activateEv index", index);
204
246
  }