emacroh5lib 1.0.36 → 1.0.39

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.36",
3
+ "version": "1.0.39",
4
4
  "description": "EMacro前端组件库",
5
5
  "main": "dist/emacroh5lib.min.js",
6
6
  "scripts": {
@@ -154,6 +154,93 @@ export namespace EMacro {
154
154
  }
155
155
  }
156
156
 
157
+ // 获取最大公约数
158
+ function getGcd(a, b) {
159
+ let n1, n2;
160
+ if (a > b) {
161
+ n1 = a;
162
+ n2 = b;
163
+ } else {
164
+ n1 = b;
165
+ n2 = a;
166
+ }
167
+
168
+ let remainder = n1 % n2;
169
+ if (remainder === 0) {
170
+ return n2;
171
+ } else {
172
+ return getGcd(n2, remainder)
173
+ }
174
+ }
175
+
176
+ export const getVideoScale = async (url: string) => {
177
+ const video = document.createElement('video');
178
+ video.setAttribute("width", "10");
179
+ video.setAttribute("height", "10");
180
+ video.setAttribute("style", "position: absolute;opacity: 0;z-index: -5;top: 0;");
181
+ video.setAttribute("src", url);
182
+
183
+ document.body.appendChild(video);
184
+
185
+ const p = new Promise(function (resolve, reject) {
186
+ video.addEventListener('canplay', function (e: any) {
187
+ const gcd = getGcd(e.target.videoWidth, e.target.videoHeight);
188
+ resolve([e.target.videoWidth / gcd, e.target.videoHeight / gcd])
189
+ })
190
+ })
191
+ const res = await p;
192
+ document.body.removeChild(video);
193
+ return res
194
+ }
195
+
196
+ export const getVideoBase64 = async (url: string, timestamp: number = -1, bufftime: number = 2000) => {
197
+
198
+ const scale = await getVideoScale(url) as any;
199
+ const width = scale[0] + ''
200
+ const height = scale[1] + ''
201
+ const base64 = await new Promise(function (resolve) {
202
+ let dataURL = ''
203
+ let video = document.createElement('video')
204
+ video.setAttribute('crossOrigin', 'anonymous') //处理跨域
205
+ video.setAttribute('src', url)
206
+ video.setAttribute('width', width)
207
+ video.setAttribute('height', height)
208
+ video.setAttribute('autoplay', 'autoplay')
209
+ document.body.appendChild(video)
210
+ video.addEventListener('loadeddata', function () {
211
+
212
+ video.pause()
213
+
214
+ if (timestamp === -1) {
215
+ timestamp = Math.random() * video.duration
216
+ }
217
+ video.currentTime = timestamp
218
+
219
+ /*
220
+ 使用定时器为了视频跳转到某一帧的时候视频进行缓冲,等视频加载完成之后进行截图
221
+ 如果截图是黑屏说明视频未加载完成就开始截屏了
222
+ */
223
+ setTimeout(() => {
224
+ let canvas = document.createElement('canvas');
225
+ // const width = canvas.width; //canvas的尺寸和图片一样
226
+ // const height = canvas.height;
227
+ canvas.width = video.width
228
+ canvas.height = video.height
229
+ canvas.getContext('2d')!.drawImage(video, 0, 0, video.width, video.height) //绘制canvas
230
+ dataURL = canvas.toDataURL('image/jpeg') //转换为base64
231
+ document.body.removeChild(video)
232
+ resolve(dataURL)
233
+ }, bufftime);
234
+
235
+ })
236
+ })
237
+
238
+ return base64;
239
+ }
240
+
241
+
242
+
243
+
157
244
  }
158
245
 
159
246
 
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <div class="duo-viewer" v-if="show" ref="duoViewer" @click="clickAgent">
3
3
  <div class="duo-viewer-mask">
4
- <img ref="duoViewerImage" :src="realSrc" :alt="alt" class="duo-viewer-mask__image" />
4
+ <img ref="duoViewerImage" :src="realSrc" :alt="alt" class="duo-viewer-mask__image"/>
5
5
  </div>
6
6
  <div class="duo-viewer-footer">
7
7
  <div class="duo-viewer-footer__title">{{ realName }}</div>
@@ -88,12 +88,6 @@
88
88
  alt: {
89
89
  type: String,
90
90
  default: "加载失败...",
91
- },
92
- loadComplete: {
93
- type: Function,
94
- default: function () {
95
- console.log("loadComplete");
96
- }
97
91
  }
98
92
  },
99
93
  computed: {
@@ -161,12 +155,12 @@
161
155
  height: `${imageObject.height}px`,
162
156
  };
163
157
 
164
- resolve(event);
158
+ resolve("");
165
159
  imageObject.onload = null
166
160
  };
167
161
 
168
162
  imageObject.onerror = function (event) {
169
- resolve(event);
163
+ resolve("");
170
164
  imageObject.onerror = null
171
165
  };
172
166
 
@@ -175,19 +169,25 @@
175
169
  );
176
170
  });
177
171
 
178
- // Promise.all(promises).then((data) => {
179
- // this.image = this.$refs["duoViewerImage"];
180
- // this.initDrag();
181
- // const { width, height } = $this.listDataCache[index];
182
- // $this.setStyleByName($this.image, "width", width);
183
- // $this.setStyleByName($this.image, "height", height);
184
- // })
172
+ Promise.all(promises).then((data) => {
173
+ // this.image = this.$refs["duoViewerImage"];
174
+ // this.initDrag();
175
+ // const { width, height } = $this.listDataCache[index];
176
+ // $this.setStyleByName($this.image, "width", width);
177
+ // $this.setStyleByName($this.image, "height", height);
178
+
179
+ $this.image = $this.$refs["duoViewerImage"];
180
+ $this.initDrag();
181
+ this.$emit("loadComplete");
182
+ const { width, height } = $this.listDataCache[index];
183
+ $this.setStyleByName($this.image, "width", width);
184
+ $this.setStyleByName($this.image, "height", height);
185
+ })
185
186
 
186
187
  Promise.race(promises).then((data) => {
187
188
  $this.image = $this.$refs["duoViewerImage"];
188
- console.log("$this.image", $this.image);
189
189
  $this.initDrag();
190
- $this.loadComplete()
190
+ this.$emit("loadComplete");
191
191
  const { width, height } = $this.listDataCache[index];
192
192
  $this.setStyleByName($this.image, "width", width);
193
193
  $this.setStyleByName($this.image, "height", height);
@@ -357,9 +357,9 @@
357
357
 
358
358
  // Zoom action
359
359
  zoom(type) {
360
- let image = this.image,
361
- w = +this.getStyleByName(image, "width").split("px")[0],
362
- h = +this.getStyleByName(image, "height").split("px")[0];
360
+ let image = this.image;
361
+ let w = +this.getStyleByName(image, "width").split("px")[0];
362
+ let h = +this.getStyleByName(image, "height").split("px")[0];
363
363
 
364
364
  if (h <= 20 && type === "out") return;
365
365
 
@@ -10,8 +10,9 @@
10
10
  :currentIndex="currentIndex" />
11
11
 
12
12
 
13
- <div class="list" id="list">
14
13
 
14
+
15
+ <div class="list" id="list" v-if="false">
15
16
  <DragResizeView v-for="(rect, index) in rects" :key="index" :isStorage="true" :name="rect.name" :w="rect.width"
16
17
  :h="rect.height" :x="rect.left" :y="rect.top" :parentW="listWidth" :parentH="listHeight" :axis="rect.axis"
17
18
  :isActive="rect.active" :minw="rect.minw" :minh="rect.minh" :isDraggable="rect.draggable"
@@ -21,13 +22,14 @@
21
22
  v-on:resizing="changeSize($event, index)">
22
23
  <div class="filler" :style="{ backgroundColor: rect.color }"></div>
23
24
  </DragResizeView>
24
-
25
25
  </div>
26
26
 
27
- <Draw>
27
+ <Draw v-if="false">
28
28
  <div class="filler2">111</div>
29
29
  </Draw>
30
30
 
31
+ <video-viewer :list="srcList" :show.sync="showVideoViewer" width="80%" height="80%"/>
32
+
31
33
 
32
34
  </div>
33
35
  </template>
@@ -35,6 +37,7 @@
35
37
  <script lang="ts">
36
38
  import { Component, Vue } from "vue-property-decorator";
37
39
  import ImageViewer from "@/views/ImageViewer/index.vue";
40
+ import VideoViewer from "@/views/VideoViewer/index.vue";
38
41
  import DragResizeView from "@/views/DragResizeView/index.vue";
39
42
  import Draw from "@/views/Draw/index.vue";
40
43
 
@@ -47,12 +50,14 @@ import Cookie from 'js-cookie'
47
50
  import LAY_EXCEL from 'lay-excel';
48
51
 
49
52
  import BMF from 'browser-md5-file';
53
+ import { info } from "console";
50
54
 
51
55
 
52
56
  @Component({
53
57
  components: {
54
58
  ImageViewer,
55
59
  DragResizeView,
60
+ VideoViewer,
56
61
  Draw
57
62
  },
58
63
  mounted() {
@@ -63,21 +68,29 @@ export default class TestView extends Vue {
63
68
 
64
69
  public currentIndex: Number = 0; // 打开图片查看器时,需要定位到的图片的索引
65
70
  public srcList: Array<String> = [
66
- "http://172.16.1.83:18019/EMacroApi/GetFile?type=0&path=C:\\MES\\EMacroAndroidServer_Windows_v1.1\\EMacroAssets\\file\\%E6%97%A0%E6%A0%87%E9%A2%98.png",
67
- "https://scpic.chinaz.net/files/pic/pic9/202203/apic39703.jpg",
68
- "https://scpic.chinaz.net/files/pic/pic9/202005/zzpic24899.jpg",
69
- "https://scpic.chinaz.net/files/pic/pic9/202109/bpic24244.jpg",
70
- "https://scpic.chinaz.net/files/pic/pic9/202110/hpic4529.jpg",
71
- "https://scpic.chinaz.net/files/pic/pic9/201912/zzpic22106.jpg",
72
- "https://scpic.chinaz.net/files/pic/pic9/202202/apic38580.jpg",
71
+ // "http://172.16.1.83:18019/EMacroApi/GetFile?type=0&path=C:\\MES\\EMacroAndroidServer_Windows_v1.1\\EMacroAssets\\file\\%E6%97%A0%E6%A0%87%E9%A2%98.png",
72
+ // "https://scpic.chinaz.net/files/pic/pic9/202203/apic39703.jpg",
73
+ // "https://scpic.chinaz.net/files/pic/pic9/202005/zzpic24899.jpg",
74
+ // "https://scpic.chinaz.net/files/pic/pic9/202109/bpic24244.jpg",
75
+ // "https://scpic.chinaz.net/files/pic/pic9/202110/hpic4529.jpg",
76
+ // "https://scpic.chinaz.net/files/pic/pic9/201912/zzpic22106.jpg",
77
+ // "https://scpic.chinaz.net/files/pic/pic9/202202/apic38580.jpg",
78
+ "http://192.168.0.107:99/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\编程向未来.mp4",
79
+ "http://192.168.0.107:99/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\ker.mp4",
80
+ "http://192.168.0.107:99/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\video2.mp4",
73
81
  ] // 图片查看器数据集
82
+
83
+ public src: String = "http://192.168.0.107:99/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\编程向未来.mp4"
84
+
74
85
  public showViewer: Boolean = false // 是否打开图片查看器
86
+ public showVideoViewer: Boolean = false // 是否打开图片查看器
75
87
 
76
88
  public listWidth = 0;
77
89
  public listHeight = 0;
78
90
 
79
91
  public handleOpen() {
80
- this.showViewer = true;
92
+ // this.showViewer = true;
93
+ this.showVideoViewer = true;
81
94
  }
82
95
  public openCallback() { } // 打开时的回调
83
96
  public closeCallback() { } // 关闭时的回调
@@ -208,7 +221,7 @@ export default class TestView extends Vue {
208
221
  }
209
222
 
210
223
  public selectFile(e) {
211
-
224
+
212
225
  EMacro.File.selectFile().then((files) => {
213
226
  EMacro.File.uploadFiles(files, file => {
214
227
 
@@ -285,6 +298,13 @@ export default class TestView extends Vue {
285
298
  }
286
299
 
287
300
  public mounted() {
301
+
302
+ EMacro.getVideoScale("http://121.228.113.68:8069/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\编程向未来.mp4").then(info => {
303
+ console.log("获取视频", info);
304
+ });
305
+
306
+
307
+
288
308
  const listEl = document.getElementById('list') as HTMLElement;
289
309
  this.listWidth = listEl.clientWidth;
290
310
  this.listHeight = listEl.clientHeight;