index.vue
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<template>
<audio
v-if="url"
v-bind="$attrs"
:id="uuid"
ref="audioRef"
:src="url"
class="player"
controls
controlsList="nodownload noplaybackrate"
@play="onPay"
/>
</template>
<script lang="ts" setup>
import { nanoid } from 'nanoid';
// import FileSaver from 'file-saver';
import { computed, ref } from 'vue';
const audioRef = ref({});
defineProps<{ url: string }>();
const uuid = computed(() => {
return `audio-${nanoid()}`;
});
const onPay = (e: any) => {
const audios = document.getElementsByTagName('audio');
[].forEach.call(audios, (i: HTMLAudioElement) => i !== e.target && i.pause());
};
const getRef = (): HTMLAudioElement => {
return audioRef.value as HTMLAudioElement;
};
defineExpose({ getRef });
</script>
<style lang="less" scoped>
.player {
height: 30px;
width: 100%;
outline: none;
display: flex;
}
audio {
&::-webkit-media-controls-volume-control-container {
display: none !important;
}
&::-webkit-media-controls-rewind-button {
display: none !important;
}
}
</style>