|
|
@@ -0,0 +1,98 @@
|
|
|
+<template>
|
|
|
+ <div v-if="audioInfo !== null">
|
|
|
+ <v-container>
|
|
|
+ <v-col>
|
|
|
+ <v-row>
|
|
|
+ <v-col>
|
|
|
+ <h3 v-text="audioInfo.title" />
|
|
|
+ </v-col>
|
|
|
+ </v-row>
|
|
|
+ </v-col>
|
|
|
+ </v-container>
|
|
|
+ <v-container>
|
|
|
+ <audio-player
|
|
|
+ ref="audioPlayer"
|
|
|
+ :show-prev-button="false"
|
|
|
+ :show-next-button="false"
|
|
|
+ :show-playback-rate="false"
|
|
|
+ :show-volume-button="false"
|
|
|
+ :is-loop="false"
|
|
|
+ :audio-list="audioList.map(elm => elm.url)"
|
|
|
+ :before-play="handleBeforePlay"
|
|
|
+ theme-color="#87CEFA"
|
|
|
+ />
|
|
|
+ </v-container>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { audioInfo } from '@/api/media/audio'
|
|
|
+import TimeUtil from '@/utils/time-util.vue'
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'Audio',
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ TimeUtil,
|
|
|
+ audioId: '',
|
|
|
+ audioInfo: null,
|
|
|
+ currentAudioName: '',
|
|
|
+ audioList: [],
|
|
|
+ benched: 0
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ items() {
|
|
|
+ return Array.from({ length: this.length }, (k, v) => v + 1)
|
|
|
+ },
|
|
|
+ length() {
|
|
|
+ return 100
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ // 获取 url 上的 path 参数
|
|
|
+ this.audioId = this.$route.params.id
|
|
|
+ // 请求后端获取数据
|
|
|
+ this.getAudioInfo(this.audioId)
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getAudioInfo(audioId) {
|
|
|
+ audioInfo(audioId)
|
|
|
+ .then(res => {
|
|
|
+ if (res.code === 0) {
|
|
|
+ const audioData = res.data
|
|
|
+ document.title = audioData.title
|
|
|
+ this.audioInfo = audioData
|
|
|
+ this.audioList.push({
|
|
|
+ name: audioData.title,
|
|
|
+ url: audioData.audioUrl
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ console.error(res.msg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.error(error.message)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 播放前做的事
|
|
|
+ handleBeforePlay(next) {
|
|
|
+ // 这里可以做一些事情...
|
|
|
+ this.currentAudioName = this.audioList[this.$refs.audioPlayer.currentPlayIndex].name
|
|
|
+ next() // 开始播放
|
|
|
+ },
|
|
|
+ handlePlaySpecify() {
|
|
|
+ this.$refs.audioPlayer.currentPlayIndex = 1
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs.audioPlayer.play()
|
|
|
+ this.title = this.audioList[
|
|
|
+ this.$refs.audioPlayer.currentPlayIndex
|
|
|
+ ].name
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style>
|
|
|
+</style>
|