emacroh5lib 1.0.37 → 1.0.40

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.37",
3
+ "version": "1.0.40",
4
4
  "description": "EMacro前端组件库",
5
5
  "main": "dist/emacroh5lib.min.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -4,11 +4,12 @@ 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 VideoViewer from './views/VideoViewer/index.vue'
7
8
  import DragResizeView from './views/DragResizeView/index.vue'
8
9
  import DragView from './views/Draw/index.vue'
9
10
  import MessageBoxTest from "@/components/MessageBoxTest";
10
11
 
11
- const components = [FileViewer, ImageViewer, DragResizeView];
12
+ const components = [FileViewer, ImageViewer, VideoViewer, DragResizeView];
12
13
 
13
14
  const install = (Vue: any) => {
14
15
  if ((install as any).installed) return;
@@ -23,12 +24,12 @@ if (typeof window !== 'undefined' && (window as any).Vue) {
23
24
  install((window as any).Vue);
24
25
  }
25
26
 
26
-
27
+
27
28
  // import HelloWorld from "@/components/HelloWorld.vue";
28
29
  // import HelloWorld from "@/components/index";
29
30
 
30
-
31
+
31
32
 
32
33
 
33
34
  export default {}
34
- export { EMacro,FileViewer, ImageViewer, DragResizeView }
35
+ export { EMacro, FileViewer, ImageViewer, VideoViewer, DragResizeView }
@@ -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>
@@ -177,7 +177,6 @@
177
177
  // $this.setStyleByName($this.image, "height", height);
178
178
 
179
179
  $this.image = $this.$refs["duoViewerImage"];
180
- console.log("Promise.all", $this.image);
181
180
  $this.initDrag();
182
181
  this.$emit("loadComplete");
183
182
  const { width, height } = $this.listDataCache[index];
@@ -187,7 +186,6 @@
187
186
 
188
187
  Promise.race(promises).then((data) => {
189
188
  $this.image = $this.$refs["duoViewerImage"];
190
- console.log("Promise.race", $this.image);
191
189
  $this.initDrag();
192
190
  this.$emit("loadComplete");
193
191
  const { width, height } = $this.listDataCache[index];
@@ -359,9 +357,9 @@
359
357
 
360
358
  // Zoom action
361
359
  zoom(type) {
362
- let image = this.image,
363
- w = +this.getStyleByName(image, "width").split("px")[0],
364
- 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];
365
363
 
366
364
  if (h <= 20 && type === "out") return;
367
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() {
@@ -69,15 +74,23 @@ export default class TestView extends Vue {
69
74
  // "https://scpic.chinaz.net/files/pic/pic9/202109/bpic24244.jpg",
70
75
  // "https://scpic.chinaz.net/files/pic/pic9/202110/hpic4529.jpg",
71
76
  // "https://scpic.chinaz.net/files/pic/pic9/201912/zzpic22106.jpg",
72
- "https://scpic.chinaz.net/files/pic/pic9/202202/apic38580.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;