Skip to content

Commit 806888c

Browse files
author
xiaohong
committed
feat: 新增音频播放器
1 parent 9336280 commit 806888c

File tree

4 files changed

+65
-9
lines changed

4 files changed

+65
-9
lines changed

src/views/ai/music/components/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="flex h-1/1">
2+
<div class="flex ">
33
<!-- 模式 -->
44
<Mode class="flex-none" @generate-music="generateMusic"/>
55
<!-- 音频列表 -->
@@ -13,7 +13,7 @@ import List from './list/index.vue'
1313
1414
defineOptions({ name: 'Index' })
1515
16-
const listRef = ref<{generateMusic: (...args) => void} | null>(null)
16+
const listRef = ref<Nullable<{generateMusic: (...args) => void}>>(null)
1717
1818
function generateMusic (args: {formData: Recordable}) {
1919
unref(listRef)?.generateMusic(args.formData)
Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,68 @@
11
<template>
2-
<div class="h-72px bg-[var(--el-bg-color-overlay)] b-solid b-1 b-[var(--el-border-color)] b-l-none">播放器</div>
2+
<div class="flex items-center justify-between px-2 h-72px bg-[var(--el-bg-color-overlay)] b-solid b-1 b-[var(--el-border-color)] b-l-none">
3+
<!-- 歌曲信息 -->
4+
<div class="flex gap-[10px]">
5+
<el-image src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" class="w-[45px]"/>
6+
<div>
7+
<div>我很好</div>
8+
<div class="text-[12px] text-gray-400">刘大壮</div>
9+
</div>
10+
</div>
11+
12+
<!-- 音频controls -->
13+
<div class="flex gap-[12px] items-center">
14+
<Icon icon="majesticons:back-circle" :size="20" class="text-gray-300 cursor-pointer"/>
15+
<Icon :icon="audioProps.paused ? 'mdi:arrow-right-drop-circle' : 'solar:pause-circle-bold'" :size="30" class=" cursor-pointer" @click="toggleStatus('paused')"/>
16+
<Icon icon="majesticons:next-circle" :size="20" class="text-gray-300 cursor-pointer"/>
17+
<div class="flex gap-[16px] items-center">
18+
<span>{{audioProps.currentTime}}</span>
19+
<el-slider v-model="audioProps.duration" color="#409eff" class="w-[160px!important] "/>
20+
<span>{{ audioProps.duration }}</span>
21+
</div>
22+
<!-- 音频 -->
23+
<audio v-bind="audioProps" ref="audioRef" controls v-show="!audioProps" @timeupdate="audioTimeUpdate">
24+
<source :src="response"/>
25+
</audio>
26+
</div>
27+
28+
<!-- 音量控制器 -->
29+
<div class="flex gap-[16px] items-center">
30+
<Icon :icon="audioProps.muted ? 'tabler:volume-off' : 'tabler:volume'" :size="20" class="cursor-pointer" @click="toggleStatus('muted')"/>
31+
<el-slider v-model="audioProps.volume" color="#409eff" class="w-[160px!important] "/>
32+
</div>
33+
</div>
334
</template>
435

536
<script lang="ts" setup>
37+
import { formatPast } from '@/utils/formatTime'
38+
import response from '@/assets/audio/response.mp3'
639
740
defineOptions({ name: 'Index' })
841
42+
const audioRef = ref<Nullable<HTMLElement>>(null)
43+
// 音频相关属性https://www.runoob.com/tags/ref-av-dom.html
44+
const audioProps = reactive({
45+
autoplay: true,
46+
paused: false,
47+
currentTime: '00:00',
48+
duration: '00:00',
49+
muted: false,
50+
volume: 50,
51+
})
52+
53+
function toggleStatus (type: string) {
54+
audioProps[type] = !audioProps[type]
55+
if (type === 'paused' && audioRef.value) {
56+
if (audioProps[type]) {
57+
audioRef.value.pause()
58+
} else {
59+
audioRef.value.play()
60+
}
61+
}
62+
}
63+
64+
// 更新播放位置
65+
function audioTimeUpdate (args) {
66+
audioProps.currentTime = formatPast(new Date(args.timeStamp), 'mm:ss')
67+
}
968
</script>

src/views/ai/music/components/list/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="flex flex-col h-full">
2+
<div class="flex flex-col h-[600px]">
33
<div class="flex-auto flex overflow-hidden">
44
<el-tabs v-model="currentType" class="flex-auto px-[var(--app-content-padding)]">
55
<!-- 我的创作 -->

src/views/ai/music/components/mode/index.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<ContentWrap class="w-300px h-full">
2+
<ContentWrap class="w-300px h-full mb-[0!important]">
33
<el-radio-group v-model="generateMode" class="mb-15px">
44
<el-radio-button label="desc">
55
描述模式
@@ -28,10 +28,7 @@ const emits = defineEmits(['generate-music'])
2828
2929
const generateMode = ref('lyric')
3030
31-
interface ModeRef {
32-
formData: Recordable
33-
}
34-
const modeRef = ref<ModeRef | null>(null)
31+
const modeRef = ref<Nullable<{ formData: Recordable }>>(null)
3532
3633
/*
3734
*@Description: 根据信息生成音乐

0 commit comments

Comments
 (0)