|
@@ -1,6 +1,7 @@
|
1
|
1
|
<template>
|
2
|
2
|
<div class="img-wrapper">
|
3
|
3
|
<img :src="resource.img.src" @load="onLoad" alt="">
|
|
4
|
+ <div v-if="showGesture" class="gesture" :style="gestureStyle"><i class="iconfont icon-cc-pointer-right"></i></div>
|
4
|
5
|
<div v-if="resource.playBtn" class="paybtn" :style="btnStyle" @click="onPlayBtn">
|
5
|
6
|
<AudioPlayingVue :style="iconStyle" />
|
6
|
7
|
<audio :src="resource.audio" preload="auto" ref="audioRef" @ended="onEnded"></audio>
|
|
@@ -21,11 +22,14 @@ const props = defineProps({
|
21
|
22
|
default: () => ({})
|
22
|
23
|
},
|
23
|
24
|
showFog: Boolean,
|
|
25
|
+ index: Number,
|
24
|
26
|
});
|
25
|
27
|
|
26
|
28
|
const btnStyle = ref({});
|
|
29
|
+const gestureStyle = ref({});
|
27
|
30
|
const audioRef = ref();
|
28
|
31
|
const playState = ref(0);
|
|
32
|
+const showGesture = ref(props.resource.showGesture);
|
29
|
33
|
const iconStyle = computed(() => ({
|
30
|
34
|
opacity: playState.value
|
31
|
35
|
}));
|
|
@@ -34,6 +38,11 @@ const playAudio = () => {
|
34
|
38
|
audioRef.value.play();
|
35
|
39
|
playState.value = 1;
|
36
|
40
|
updateCurrent(props.resource.audio);
|
|
41
|
+
|
|
42
|
+ // 播放一次, 立即消失
|
|
43
|
+ if (showGesture.value) {
|
|
44
|
+ showGesture.value = false;
|
|
45
|
+ }
|
37
|
46
|
}
|
38
|
47
|
|
39
|
48
|
const stopAudio = () => {
|
|
@@ -64,15 +73,22 @@ const onEnded = () => {
|
64
|
73
|
|
65
|
74
|
// 图片加载完成, 设置播放器
|
66
|
75
|
const onLoad = (e) => {
|
67
|
|
- if (!props.resource.playBtn) return;
|
68
|
|
-
|
69
|
|
- const { pos } = props.resource.playBtn;
|
70
|
|
- const { width, height, naturalHeight, naturalWidth } = e.target;
|
71
|
|
- const d = 32; // 宽度一半
|
72
|
|
- const x = width * pos[0] / naturalWidth - d;
|
73
|
|
- const y = height * pos[1] / naturalHeight - d;
|
74
|
|
-
|
75
|
|
- btnStyle.value = { left: `${x}px`, top: `${y}px` }
|
|
76
|
+ if (props.resource.playBtn) {
|
|
77
|
+ const { pos } = props.resource.playBtn;
|
|
78
|
+ const { width, height, naturalHeight, naturalWidth } = e.target;
|
|
79
|
+ const d = 32; // 宽度一半
|
|
80
|
+ const centerX = width * pos[0] / naturalWidth;
|
|
81
|
+ const centerY = height * pos[1] / naturalHeight;
|
|
82
|
+ const x = centerX - d;
|
|
83
|
+ const y = centerY - d;
|
|
84
|
+ btnStyle.value = { left: `${x}px`, top: `${y}px` }
|
|
85
|
+
|
|
86
|
+ // 如果显示引导手势, 那么计算坐标
|
|
87
|
+ if (showGesture.value) {
|
|
88
|
+ const d2 = 12 // 字体大小一半
|
|
89
|
+ gestureStyle.value = { left: `${x - d2 * 2}px`, top: `${centerY - d2}px` }
|
|
90
|
+ }
|
|
91
|
+ }
|
76
|
92
|
}
|
77
|
93
|
|
78
|
94
|
</script>
|
|
@@ -82,6 +98,27 @@ const onLoad = (e) => {
|
82
|
98
|
margin-top: -0.5px; // 解决 iphone13 白边问题
|
83
|
99
|
position: relative;
|
84
|
100
|
|
|
101
|
+ .gesture {
|
|
102
|
+ position: absolute;
|
|
103
|
+ z-index: 9;
|
|
104
|
+ animation: gestureAnimation 1.6s ease-in-out infinite;
|
|
105
|
+
|
|
106
|
+ .iconfont {
|
|
107
|
+ font-size: 24px;
|
|
108
|
+ }
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ @keyframes gestureAnimation {
|
|
112
|
+ from {
|
|
113
|
+ opacity: 0;
|
|
114
|
+ transform: translateX(0);
|
|
115
|
+ }
|
|
116
|
+ to {
|
|
117
|
+ opacity: 1;
|
|
118
|
+ transform: translateX(12px);
|
|
119
|
+ }
|
|
120
|
+ }
|
|
121
|
+
|
85
|
122
|
.paybtn {
|
86
|
123
|
position: absolute;
|
87
|
124
|
width: 64px;
|