emacroh5lib 1.0.38 → 1.0.41
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 +1 -1
- package/src/index.ts +5 -4
- package/src/utilities/File.ts +87 -0
- package/src/views/ImageViewer/index.vue +30 -12
- package/src/views/TestView/index.vue +32 -10
- package/src/views/VideoViewer/index.vue +443 -0
- package/src/views/VideoViewer/style/css/index.css +186 -0
- package/src/views/VideoViewer/style/css/index.less +212 -0
- package/src/views/VideoViewer/style/images/icons.png +0 -0
- package/webpack.config.js +18 -2
package/package.json
CHANGED
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 }
|
package/src/utilities/File.ts
CHANGED
@@ -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
|
|
@@ -177,9 +177,8 @@
|
|
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
|
-
this.$emit("loadComplete");
|
181
|
+
$this.$emit("loadComplete");
|
183
182
|
const { width, height } = $this.listDataCache[index];
|
184
183
|
$this.setStyleByName($this.image, "width", width);
|
185
184
|
$this.setStyleByName($this.image, "height", height);
|
@@ -187,12 +186,15 @@
|
|
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];
|
194
192
|
$this.setStyleByName($this.image, "width", width);
|
195
193
|
$this.setStyleByName($this.image, "height", height);
|
194
|
+
|
195
|
+
setTimeout(() => {
|
196
|
+
$this.resetZoom();
|
197
|
+
}, 100);
|
196
198
|
})
|
197
199
|
|
198
200
|
},
|
@@ -221,13 +223,26 @@
|
|
221
223
|
},
|
222
224
|
|
223
225
|
// Reset zoom action
|
224
|
-
resetZoom() {
|
226
|
+
resetZoom(adaptive = true) {
|
225
227
|
let image = this.image;
|
226
228
|
const imageObject = new Image();
|
227
229
|
|
228
230
|
imageObject.src = this.list[this.index];
|
229
231
|
|
230
|
-
|
232
|
+
let { width, height } = imageObject;
|
233
|
+
|
234
|
+
if (adaptive) {
|
235
|
+
let rate = 1
|
236
|
+
if (width > height) {
|
237
|
+
rate = width / document.body.clientWidth
|
238
|
+
}
|
239
|
+
else {
|
240
|
+
rate = height / document.body.clientHeight
|
241
|
+
}
|
242
|
+
|
243
|
+
width = width / rate
|
244
|
+
height = height / rate
|
245
|
+
}
|
231
246
|
|
232
247
|
this.setStyleByName(image, "width", `${width}px`);
|
233
248
|
this.setStyleByName(image, "height", `${height}px`);
|
@@ -312,11 +327,15 @@
|
|
312
327
|
}
|
313
328
|
this.judgeThumbnailListMove(lastIndex, this.index);
|
314
329
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
330
|
+
setTimeout(() => {
|
331
|
+
this.resetZoom();
|
332
|
+
|
333
|
+
this.setStyleByName(this.image, "width", this.currentData.width);
|
334
|
+
this.setStyleByName(this.image, "height", this.currentData.height);
|
335
|
+
this.setStyleByName(this.image, "left", this.currentData.left);
|
336
|
+
this.setStyleByName(this.image, "top", this.currentData.top);
|
337
|
+
this.setTransform(this.image, this.currentData.transform);
|
338
|
+
}, 100);
|
320
339
|
},
|
321
340
|
// To judge thumbnail list move
|
322
341
|
judgeThumbnailListMove(lastIndex, index) {
|
@@ -360,7 +379,6 @@
|
|
360
379
|
// Zoom action
|
361
380
|
zoom(type) {
|
362
381
|
let image = this.image;
|
363
|
-
console.log("zoom缩放", image);
|
364
382
|
let w = +this.getStyleByName(image, "width").split("px")[0];
|
365
383
|
let h = +this.getStyleByName(image, "height").split("px")[0];
|
366
384
|
|
@@ -527,7 +545,7 @@
|
|
527
545
|
this.zoom("out");
|
528
546
|
break;
|
529
547
|
case "one-to-one":
|
530
|
-
this.resetZoom();
|
548
|
+
this.resetZoom(false);
|
531
549
|
break;
|
532
550
|
case "prev":
|
533
551
|
this.switchAction("prev");
|
@@ -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,31 @@ export default class TestView extends Vue {
|
|
63
68
|
|
64
69
|
public currentIndex: Number = 0; // 打开图片查看器时,需要定位到的图片的索引
|
65
70
|
public srcList: Array<String> = [
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
71
|
+
"http://121.228.113.68:8069/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\看板整体图.png",
|
72
|
+
"http://121.228.113.68:8069/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\060 广西电子商务公共服务平台大数据中心.png",
|
73
|
+
"https://scpic.chinaz.net/files/pic/pic9/202203/apic39703.jpg",
|
74
|
+
"https://scpic.chinaz.net/files/pic/pic9/202005/zzpic24899.jpg",
|
75
|
+
"https://scpic.chinaz.net/files/pic/pic9/202109/bpic24244.jpg",
|
76
|
+
"https://scpic.chinaz.net/files/pic/pic9/202110/hpic4529.jpg",
|
77
|
+
"https://scpic.chinaz.net/files/pic/pic9/201912/zzpic22106.jpg",
|
72
78
|
"https://scpic.chinaz.net/files/pic/pic9/202202/apic38580.jpg",
|
79
|
+
// "http://192.168.0.107:99/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\编程向未来.mp4",
|
80
|
+
// "http://192.168.0.107:99/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\ker.mp4",
|
81
|
+
// "http://192.168.0.107:99/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\video2.mp4",
|
82
|
+
// "http://192.168.0.107:99/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\看板整体图.png",
|
73
83
|
] // 图片查看器数据集
|
84
|
+
|
85
|
+
public src: String = "http://192.168.0.107:99/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\编程向未来.mp4"
|
86
|
+
|
74
87
|
public showViewer: Boolean = false // 是否打开图片查看器
|
88
|
+
public showVideoViewer: Boolean = false // 是否打开图片查看器
|
75
89
|
|
76
90
|
public listWidth = 0;
|
77
91
|
public listHeight = 0;
|
78
92
|
|
79
93
|
public handleOpen() {
|
80
94
|
this.showViewer = true;
|
95
|
+
// this.showVideoViewer = true;
|
81
96
|
}
|
82
97
|
public openCallback() { } // 打开时的回调
|
83
98
|
public closeCallback() { } // 关闭时的回调
|
@@ -208,7 +223,7 @@ export default class TestView extends Vue {
|
|
208
223
|
}
|
209
224
|
|
210
225
|
public selectFile(e) {
|
211
|
-
|
226
|
+
|
212
227
|
EMacro.File.selectFile().then((files) => {
|
213
228
|
EMacro.File.uploadFiles(files, file => {
|
214
229
|
|
@@ -285,6 +300,13 @@ export default class TestView extends Vue {
|
|
285
300
|
}
|
286
301
|
|
287
302
|
public mounted() {
|
303
|
+
|
304
|
+
EMacro.getVideoScale("http://121.228.113.68:8069/H5/GetFile?type=0&path=C:\\SOP\\PCB001\\编程向未来.mp4").then(info => {
|
305
|
+
console.log("获取视频", info);
|
306
|
+
});
|
307
|
+
|
308
|
+
|
309
|
+
|
288
310
|
const listEl = document.getElementById('list') as HTMLElement;
|
289
311
|
this.listWidth = listEl.clientWidth;
|
290
312
|
this.listHeight = listEl.clientHeight;
|