emacroh5lib 1.0.38 → 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/dist/emacroh5lib.min.js +1 -1
- package/package.json +1 -1
- package/src/utilities/File.ts +87 -0
- package/src/views/ImageViewer/index.vue +1 -4
- package/src/views/TestView/index.vue +26 -6
- 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/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
|
|
@@ -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];
|
@@ -360,7 +358,6 @@
|
|
360
358
|
// Zoom action
|
361
359
|
zoom(type) {
|
362
360
|
let image = this.image;
|
363
|
-
console.log("zoom缩放", image);
|
364
361
|
let w = +this.getStyleByName(image, "width").split("px")[0];
|
365
362
|
let h = +this.getStyleByName(image, "height").split("px")[0];
|
366
363
|
|
@@ -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;
|
@@ -0,0 +1,443 @@
|
|
1
|
+
<template>
|
2
|
+
<div class="duo-viewer" v-if="show" ref="duoViewer" @click="clickAgent">
|
3
|
+
<div class="duo-viewer-mask">
|
4
|
+
<video :width="width" :height="height" :src="realSrc" type="video/mp4" class="duo-viewer-mask__image"
|
5
|
+
controls="controls" autoplay="autoplay" loop="loop">
|
6
|
+
您的浏览器不支持 HTML5 video 标签。
|
7
|
+
</video>
|
8
|
+
</div>
|
9
|
+
<div class="duo-viewer-footer" v-if="showThumbnail">
|
10
|
+
<div class="duo-viewer-footer__title">{{ realName }}</div>
|
11
|
+
<div class="duo-viewer-footer__toolbar">
|
12
|
+
<ul>
|
13
|
+
<li class="duo-viewer-footer__zoom-in" data-viewer-action="zoom-in"></li>
|
14
|
+
<li class="duo-viewer-footer__zoom-out" data-viewer-action="zoom-out"></li>
|
15
|
+
<li class="duo-viewer-footer__one-to-one" data-viewer-action="one-to-one"></li>
|
16
|
+
<li class="duo-viewer-footer__prev" data-viewer-action="prev"></li>
|
17
|
+
|
18
|
+
<li class="duo-viewer-footer__play" data-viewer-action="play"></li>
|
19
|
+
|
20
|
+
<li class="duo-viewer-footer__next" data-viewer-action="next"></li>
|
21
|
+
<li class="duo-viewer-footer__reset" data-viewer-action="reset"></li>
|
22
|
+
<li class="duo-viewer-footer__rotate-left" data-viewer-action="rotate-left"></li>
|
23
|
+
<li class="duo-viewer-footer__rotate-right" data-viewer-action="rotate-right"></li>
|
24
|
+
</ul>
|
25
|
+
</div>
|
26
|
+
<div class="duo-viewer-footer__navbar">
|
27
|
+
<div class="duo-viewer-footer__navbar-thumbnail-wrap">
|
28
|
+
<div ref="duoViewerImageThumbnailList" class="duo-viewer-footer__navbar-thumbnail-list"
|
29
|
+
:style="{ width: `${listLength * 34}px` }">
|
30
|
+
<div :key="item + i" v-for="(item, i) in list" :class="
|
31
|
+
i === index
|
32
|
+
? 'duo-viewer-footer__navbar-thumbnail-item viewer-current'
|
33
|
+
: 'duo-viewer-footer__navbar-thumbnail-item'
|
34
|
+
">
|
35
|
+
<img data-viewer-action="select" :data-viewer-action-index="i" :src="getVideoImg(item, i)"
|
36
|
+
:alt="alt" class="duo-viewer-footer__navbar-thumbnail-image" />
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
</div>
|
42
|
+
<div class="duo-viewer-close" @click="handleClose">
|
43
|
+
<div class="duo-viewer-close__off"></div>
|
44
|
+
</div>
|
45
|
+
</div>
|
46
|
+
</template>
|
47
|
+
|
48
|
+
<script>
|
49
|
+
|
50
|
+
import { EMacro } from "../../utilities/File";
|
51
|
+
|
52
|
+
export default {
|
53
|
+
name: "ImageViewer",
|
54
|
+
data() {
|
55
|
+
return {
|
56
|
+
viewerSrc: "",
|
57
|
+
image: null,
|
58
|
+
listDataCache: [],
|
59
|
+
index: 0,
|
60
|
+
imgUrl: "",
|
61
|
+
isCreatePoster: false
|
62
|
+
};
|
63
|
+
},
|
64
|
+
props: {
|
65
|
+
// Image src list
|
66
|
+
list: {
|
67
|
+
type: Array,
|
68
|
+
default: [],
|
69
|
+
},
|
70
|
+
// Control is show of viewer
|
71
|
+
show: {
|
72
|
+
type: Boolean,
|
73
|
+
default: false,
|
74
|
+
},
|
75
|
+
// Default index
|
76
|
+
currentIndex: {
|
77
|
+
type: Number,
|
78
|
+
default: 0,
|
79
|
+
},
|
80
|
+
name: {
|
81
|
+
type: [String, Array],
|
82
|
+
default: null,
|
83
|
+
},
|
84
|
+
width: {
|
85
|
+
type: String,
|
86
|
+
default: null,
|
87
|
+
},
|
88
|
+
height: {
|
89
|
+
type: String,
|
90
|
+
default: null,
|
91
|
+
},
|
92
|
+
imgList: {
|
93
|
+
type: [String, Array],
|
94
|
+
default: null,
|
95
|
+
},
|
96
|
+
showThumbnail: {
|
97
|
+
type: Boolean,
|
98
|
+
default: false,
|
99
|
+
}
|
100
|
+
},
|
101
|
+
computed: {
|
102
|
+
listLength() {
|
103
|
+
return this.list.length;
|
104
|
+
},
|
105
|
+
realSrc() {
|
106
|
+
if (this.width === null && this.height === null) {
|
107
|
+
EMacro.getVideoScale(this.list[this.index]).then(info => {
|
108
|
+
this.width = info[0]
|
109
|
+
this.height = info[1]
|
110
|
+
});
|
111
|
+
}
|
112
|
+
return this.list[this.index];
|
113
|
+
},
|
114
|
+
realName() {
|
115
|
+
if (this.name == null) {
|
116
|
+
return this.list[this.index];
|
117
|
+
} else if (typeof this.name == "string") {
|
118
|
+
return this.name
|
119
|
+
} else if (Array.isArray(this.name)) {
|
120
|
+
return this.name[this.index];
|
121
|
+
} else {
|
122
|
+
return "未命名"
|
123
|
+
}
|
124
|
+
},
|
125
|
+
currentData() {
|
126
|
+
return this.listDataCache[this.index];
|
127
|
+
},
|
128
|
+
},
|
129
|
+
watch: {
|
130
|
+
show(val) {
|
131
|
+
if (val) {
|
132
|
+
|
133
|
+
if (this.imgList === null && this.showThumbnail) {
|
134
|
+
this.imgList = new Array();
|
135
|
+
this.isCreatePoster = true
|
136
|
+
}
|
137
|
+
for (let i = 0; i < this.list.length; i++) {
|
138
|
+
this.createVideoImg(this.list[i], i);
|
139
|
+
}
|
140
|
+
this.$emit("open");
|
141
|
+
this.index = this.currentIndex;
|
142
|
+
this.init();
|
143
|
+
} else {
|
144
|
+
this.$emit("close");
|
145
|
+
}
|
146
|
+
},
|
147
|
+
},
|
148
|
+
mounted() {
|
149
|
+
|
150
|
+
},
|
151
|
+
methods: {
|
152
|
+
getVideoImg(url, i) {
|
153
|
+
|
154
|
+
if (this.imgList !== null && typeof this.imgList == "string") {
|
155
|
+
return this.imgList
|
156
|
+
} else if (this.imgList !== null && Array.isArray(this.imgList)) {
|
157
|
+
return this.imgList[i]
|
158
|
+
} else {
|
159
|
+
return ""
|
160
|
+
}
|
161
|
+
},
|
162
|
+
async createVideoImg(url, i) {
|
163
|
+
if (!this.isCreatePoster) {
|
164
|
+
return
|
165
|
+
}
|
166
|
+
const base64 = await EMacro.getVideoBase64(url)
|
167
|
+
this.imgList.push(base64)
|
168
|
+
},
|
169
|
+
// Global init
|
170
|
+
init() {
|
171
|
+
// this.initMouseWheel();
|
172
|
+
this.keydown();
|
173
|
+
},
|
174
|
+
|
175
|
+
// Reset Rotate
|
176
|
+
resetRotate() {
|
177
|
+
let image = this.image,
|
178
|
+
oldTransform = this.getCurrentTransform(image);
|
179
|
+
|
180
|
+
oldTransform.rotate = `0deg`;
|
181
|
+
|
182
|
+
this.setTransform(image, oldTransform);
|
183
|
+
},
|
184
|
+
|
185
|
+
// Reset zoom action
|
186
|
+
resetZoom() {
|
187
|
+
let image = this.image;
|
188
|
+
const imageObject = new Image();
|
189
|
+
|
190
|
+
imageObject.src = this.list[this.index];
|
191
|
+
|
192
|
+
const { width, height } = imageObject;
|
193
|
+
|
194
|
+
this.setStyleByName(image, "width", `${width}px`);
|
195
|
+
this.setStyleByName(image, "height", `${height}px`);
|
196
|
+
|
197
|
+
this.listDataCache[this.index].width = `${width}px`;
|
198
|
+
this.listDataCache[this.index].height = `${height}px`;
|
199
|
+
},
|
200
|
+
|
201
|
+
// Reset all action
|
202
|
+
resetAll() {
|
203
|
+
this.resetZoom();
|
204
|
+
this.resetRotate();
|
205
|
+
this.resetPosition();
|
206
|
+
this.initListDataCache(this.index);
|
207
|
+
},
|
208
|
+
|
209
|
+
// Rotate action
|
210
|
+
rotate(type) {
|
211
|
+
let image = this.image,
|
212
|
+
oldTransform = this.getCurrentTransform(image),
|
213
|
+
oldRotate = Math.round(
|
214
|
+
Math.atan2(+oldTransform.skewY, +oldTransform.scaleX) *
|
215
|
+
(180 / Math.PI)
|
216
|
+
),
|
217
|
+
changeValue = type === "left" ? -90 : 90,
|
218
|
+
rotateValue = oldRotate + changeValue;
|
219
|
+
|
220
|
+
oldTransform.rotate = `${rotateValue}deg`;
|
221
|
+
|
222
|
+
oldTransform.translateX = `${oldTransform.translateX}px`;
|
223
|
+
oldTransform.translateY = `${oldTransform.translateY}px`;
|
224
|
+
this.currentData.transform = oldTransform;
|
225
|
+
this.setTransform(image, oldTransform);
|
226
|
+
},
|
227
|
+
|
228
|
+
// Get style by name
|
229
|
+
getStyleByName(obj, type) {
|
230
|
+
return window.getComputedStyle(obj, null)[type];
|
231
|
+
},
|
232
|
+
|
233
|
+
// Set style by name
|
234
|
+
setStyleByName(obj, key, value) {
|
235
|
+
obj && (obj.style[key] = value);
|
236
|
+
},
|
237
|
+
|
238
|
+
// Get element current transform
|
239
|
+
getCurrentTransform(obj) {
|
240
|
+
let value,
|
241
|
+
transform = this.getStyleByName(obj, "transform");
|
242
|
+
|
243
|
+
if (transform === "none") return;
|
244
|
+
|
245
|
+
value = transform.split("(")[1].split(")")[0].split(",");
|
246
|
+
|
247
|
+
return {
|
248
|
+
scaleX: value[0].trim(),
|
249
|
+
skewY: value[1].trim(),
|
250
|
+
// skewX: value[2].trim(),
|
251
|
+
// scaleY: value[3].trim(),
|
252
|
+
translateX: value[4].trim(),
|
253
|
+
translateY: value[5].trim(),
|
254
|
+
};
|
255
|
+
},
|
256
|
+
// Next or prev action
|
257
|
+
switchAction(a) {
|
258
|
+
let lastIndex = this.index;
|
259
|
+
switch (a) {
|
260
|
+
case "prev":
|
261
|
+
// prev action
|
262
|
+
this.index += this.index <= 0 ? 0 : -1;
|
263
|
+
break;
|
264
|
+
case "next":
|
265
|
+
// next action
|
266
|
+
let srcListLength = this.listLength - 1;
|
267
|
+
|
268
|
+
this.index +=
|
269
|
+
this.index >= srcListLength ? srcListLength - this.index : 1;
|
270
|
+
break;
|
271
|
+
default:
|
272
|
+
this.index = +a;
|
273
|
+
break;
|
274
|
+
}
|
275
|
+
this.judgeThumbnailListMove(lastIndex, this.index);
|
276
|
+
|
277
|
+
// this.setStyleByName(this.image, "width", this.currentData.width);
|
278
|
+
// this.setStyleByName(this.image, "height", this.currentData.height);
|
279
|
+
// this.setStyleByName(this.image, "left", this.currentData.left);
|
280
|
+
// this.setStyleByName(this.image, "top", this.currentData.top);
|
281
|
+
// this.setTransform(this.image, this.currentData.transform);
|
282
|
+
},
|
283
|
+
// To judge thumbnail list move
|
284
|
+
judgeThumbnailListMove(lastIndex, index) {
|
285
|
+
if (lastIndex == index) return;
|
286
|
+
|
287
|
+
let translateX = 0,
|
288
|
+
lastTransform = 0,
|
289
|
+
step = index - lastIndex,
|
290
|
+
move = step * 34,
|
291
|
+
length = this.listLength,
|
292
|
+
target = this.$refs["duoViewerImageThumbnailList"];
|
293
|
+
|
294
|
+
if (!target) return;
|
295
|
+
|
296
|
+
lastTransform = this.getCurrentTransform(target);
|
297
|
+
|
298
|
+
if (lastTransform) {
|
299
|
+
translateX = Math.abs(+lastTransform.translateX);
|
300
|
+
}
|
301
|
+
|
302
|
+
this.setTransform(target, {
|
303
|
+
scaleX: "1",
|
304
|
+
skewY: "0",
|
305
|
+
translateX: `-${translateX + move}px`,
|
306
|
+
translateY: "0%",
|
307
|
+
rotate: "0deg",
|
308
|
+
});
|
309
|
+
},
|
310
|
+
// Set element Transform
|
311
|
+
setTransform(obj, transformValue) {
|
312
|
+
let str = "";
|
313
|
+
|
314
|
+
str += `translateX(${transformValue["translateX"]}) `;
|
315
|
+
str += `translateY(${transformValue["translateY"]}) `;
|
316
|
+
transformValue["rotate"] &&
|
317
|
+
(str += `rotate(${transformValue["rotate"]}) `);
|
318
|
+
|
319
|
+
this.setStyleByName(obj, "transform", str);
|
320
|
+
},
|
321
|
+
|
322
|
+
// FullScreen action
|
323
|
+
requestFullScreen() {
|
324
|
+
let element = this.$refs["duoViewer"],
|
325
|
+
requestMethod =
|
326
|
+
element.requestFullScreen ||
|
327
|
+
element.webkitRequestFullScreen ||
|
328
|
+
element.mozRequestFullScreen ||
|
329
|
+
element.msRequestFullScreen;
|
330
|
+
|
331
|
+
if (requestMethod) {
|
332
|
+
requestMethod.call(element);
|
333
|
+
} else if (typeof window.ActiveXObject !== "undefined") {
|
334
|
+
// ie
|
335
|
+
let wscript = new ActiveXObject("WScript.Shell");
|
336
|
+
wscript !== null && wscript.SendKeys("{F11}");
|
337
|
+
}
|
338
|
+
},
|
339
|
+
|
340
|
+
// Keydown action
|
341
|
+
keydown() {
|
342
|
+
window.addEventListener("keydown", (e) => {
|
343
|
+
e = event || window.event || arguments.callee.caller.arguments[0];
|
344
|
+
|
345
|
+
if (e && e.keyCode == 40) {
|
346
|
+
// down
|
347
|
+
this.zoom("out");
|
348
|
+
}
|
349
|
+
if (e && e.keyCode == 37) {
|
350
|
+
// left
|
351
|
+
this.switchAction("prev");
|
352
|
+
}
|
353
|
+
if (e && e.keyCode == 39) {
|
354
|
+
// right
|
355
|
+
this.switchAction("next");
|
356
|
+
}
|
357
|
+
if (e && e.keyCode == 38) {
|
358
|
+
// up
|
359
|
+
this.zoom("in");
|
360
|
+
}
|
361
|
+
if (e && e.keyCode == 27) {
|
362
|
+
// esc
|
363
|
+
this.handleClose()
|
364
|
+
}
|
365
|
+
});
|
366
|
+
},
|
367
|
+
|
368
|
+
// Init mouse wheel event
|
369
|
+
initMouseWheel() {
|
370
|
+
const scrollFn = (e) => {
|
371
|
+
e = e || window.event;
|
372
|
+
if (e.wheelDelta) {
|
373
|
+
// for IE/Google
|
374
|
+
if (e.wheelDelta > 0) {
|
375
|
+
this.zoom("out");
|
376
|
+
}
|
377
|
+
if (e.wheelDelta < 0) {
|
378
|
+
this.zoom("in");
|
379
|
+
}
|
380
|
+
} else if (e.detail) {
|
381
|
+
// for Firefox
|
382
|
+
if (e.detail > 0) {
|
383
|
+
this.zoom("out");
|
384
|
+
}
|
385
|
+
if (e.detail < 0) {
|
386
|
+
this.zoom("in");
|
387
|
+
}
|
388
|
+
}
|
389
|
+
};
|
390
|
+
|
391
|
+
document.addEventListener &&
|
392
|
+
document.addEventListener("DOMMouseScroll", scrollFn, false);
|
393
|
+
window.onmousewheel = document.onmousewheel = scrollFn;
|
394
|
+
},
|
395
|
+
|
396
|
+
// Agent
|
397
|
+
clickAgent(e) {
|
398
|
+
switch (e.target.getAttribute("data-viewer-action")) {
|
399
|
+
case "zoom-in":
|
400
|
+
this.zoom("in");
|
401
|
+
break;
|
402
|
+
case "zoom-out":
|
403
|
+
this.zoom("out");
|
404
|
+
break;
|
405
|
+
case "one-to-one":
|
406
|
+
this.resetZoom();
|
407
|
+
break;
|
408
|
+
case "prev":
|
409
|
+
this.switchAction("prev");
|
410
|
+
break;
|
411
|
+
case "play":
|
412
|
+
this.requestFullScreen();
|
413
|
+
break;
|
414
|
+
case "next":
|
415
|
+
this.switchAction("next");
|
416
|
+
break;
|
417
|
+
case "reset":
|
418
|
+
this.resetAll();
|
419
|
+
break;
|
420
|
+
case "select":
|
421
|
+
this.switchAction(e.target.getAttribute("data-viewer-action-index"));
|
422
|
+
break;
|
423
|
+
case "rotate-left":
|
424
|
+
this.rotate("left");
|
425
|
+
break;
|
426
|
+
case "rotate-right":
|
427
|
+
this.rotate("right");
|
428
|
+
break;
|
429
|
+
}
|
430
|
+
},
|
431
|
+
// On close
|
432
|
+
handleClose() {
|
433
|
+
this.imgList = null
|
434
|
+
this.isCreatePoster = false
|
435
|
+
this.$emit("update:show", false);
|
436
|
+
},
|
437
|
+
},
|
438
|
+
};
|
439
|
+
</script>
|
440
|
+
|
441
|
+
<style lang="less" scoped>
|
442
|
+
@import "./style/css/index.css";
|
443
|
+
</style>
|