Skip to content

Commit 7f7c508

Browse files
author
xiaohong
committed
feat: 完善AI音频播放
1 parent bfddd67 commit 7f7c508

File tree

8 files changed

+79
-74
lines changed

8 files changed

+79
-74
lines changed

src/assets/audio/response.mp3

1.66 MB
Binary file not shown.

src/layout/components/AppView.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ provide('reload', reload)
5757
5858
'!min-h-[calc(100%-var(--top-tool-height)-var(--app-content-padding)-var(--app-content-padding)-var(--tags-view-height))]':
5959
!fixedHeader && layout === 'cutMenu' && footer
60-
}
60+
},
61+
'h-0'
6162
]"
6263
>
6364
<router-view v-if="routerAlive">

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="flex ">
2+
<div class="flex h-full items-stretch">
33
<!-- 模式 -->
44
<Mode class="flex-none" @generate-music="generateMusic"/>
55
<!-- 音频列表 -->
@@ -15,6 +15,11 @@ defineOptions({ name: 'Index' })
1515
1616
const listRef = ref<Nullable<{generateMusic: (...args) => void}>>(null)
1717
18+
/*
19+
*@Description: 拿到左侧配置信息调用右侧音乐生成的方法
20+
*@MethodAuthor: xiaohong
21+
*@Date: 2024-07-19 11:13:38
22+
*/
1823
function generateMusic (args: {formData: Recordable}) {
1924
unref(listRef)?.generateMusic(args.formData)
2025
}

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

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<div class="flex gap-[10px]">
55
<el-image src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png" class="w-[45px]"/>
66
<div>
7-
<div>我很好</div>
8-
<div class="text-[12px] text-gray-400">刘大壮</div>
7+
<div>{{currentSong.name}}</div>
8+
<div class="text-[12px] text-gray-400">{{currentSong.singer}}</div>
99
</div>
1010
</div>
1111

@@ -21,7 +21,7 @@
2121
</div>
2222
<!-- 音频 -->
2323
<audio v-bind="audioProps" ref="audioRef" controls v-show="!audioProps" @timeupdate="audioTimeUpdate">
24-
<source :src="response"/>
24+
<source :src="audioUrl"/>
2525
</audio>
2626
</div>
2727

@@ -35,34 +35,36 @@
3535

3636
<script lang="ts" setup>
3737
import { formatPast } from '@/utils/formatTime'
38-
import response from '@/assets/audio/response.mp3'
38+
import audioUrl from '@/assets/audio/response.mp3'
3939
4040
defineOptions({ name: 'Index' })
4141
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-
})
42+
const currentSong = inject('currentSong', {})
5243
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-
}
44+
const audioRef = ref<Nullable<HTMLElement>>(null)
45+
// 音频相关属性https://www.runoob.com/tags/ref-av-dom.html
46+
const audioProps = reactive({
47+
autoplay: true,
48+
paused: false,
49+
currentTime: '00:00',
50+
duration: '00:00',
51+
muted: false,
52+
volume: 50,
53+
})
54+
55+
function toggleStatus (type: string) {
56+
audioProps[type] = !audioProps[type]
57+
if (type === 'paused' && audioRef.value) {
58+
if (audioProps[type]) {
59+
audioRef.value.pause()
60+
} else {
61+
audioRef.value.play()
6162
}
6263
}
64+
}
6365
64-
// 更新播放位置
65-
function audioTimeUpdate (args) {
66-
audioProps.currentTime = formatPast(new Date(args.timeStamp), 'mm:ss')
67-
}
66+
// 更新播放位置
67+
function audioTimeUpdate (args) {
68+
audioProps.currentTime = formatPast(new Date(args.timeStamp), 'mm:ss')
69+
}
6870
</script>

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
<template>
2-
<div class="flex flex-col h-[600px]">
2+
<div class="flex flex-col">
33
<div class="flex-auto flex overflow-hidden">
44
<el-tabs v-model="currentType" class="flex-auto px-[var(--app-content-padding)]">
55
<!-- 我的创作 -->
6-
<el-tab-pane label="我的创作" v-loading="loading" name="mine">
6+
<el-tab-pane v-loading="loading" label="我的创作" name="mine">
77
<el-row v-if="mySongList.length" :gutter="12">
88
<el-col v-for="song in mySongList" :key="song.id" :span="24">
9-
<songCard v-bind="song"/>
9+
<songCard :songInfo="song" @click="setCurrentSong(song)"/>
1010
</el-col>
1111
</el-row>
1212
<el-empty v-else description="暂无音乐"/>
1313
</el-tab-pane>
1414

1515
<!-- 试听广场 -->
16-
<el-tab-pane label="试听广场" v-loading="loading" name="square">
16+
<el-tab-pane v-loading="loading" label="试听广场" name="square">
1717
<el-row v-if="squareSongList.length" v-loading="loading" :gutter="12">
1818
<el-col v-for="song in squareSongList" :key="song.id" :span="24">
19-
<songCard v-bind="song"/>
19+
<songCard :songInfo="song" @click="setCurrentSong(song)"/>
2020
</el-col>
2121
</el-row>
2222
<el-empty v-else description="暂无音乐"/>
2323
</el-tab-pane>
2424
</el-tabs>
2525
<!-- songInfo -->
26-
<songInfo v-bind="squareSongList[0]" class="flex-none"/>
26+
<songInfo class="flex-none"/>
2727
</div>
2828
<audioBar class="flex-none"/>
2929
</div>
@@ -36,13 +36,18 @@ import audioBar from './audioBar/index.vue'
3636
3737
defineOptions({ name: 'Index' })
3838
39+
3940
const currentType = ref('mine')
4041
// loading 状态
4142
const loading = ref(false)
43+
// 当前音乐
44+
const currentSong = ref({})
4245
4346
const mySongList = ref<Recordable[]>([])
4447
const squareSongList = ref<Recordable[]>([])
4548
49+
provide('currentSong', currentSong)
50+
4651
/*
4752
*@Description: 调接口生成音乐列表
4853
*@MethodAuthor: xiaohong
@@ -57,7 +62,7 @@ function generateMusic (formData: Recordable) {
5762
id: index,
5863
audioUrl: '',
5964
videoUrl: '',
60-
title: '我走后',
65+
title: '我走后' + index,
6166
imageUrl: 'https://www.carsmp3.com/data/attachment/forum/201909/19/091020q5kgre20fidreqyt.jpg',
6267
desc: 'Metal, symphony, film soundtrack, grand, majesticMetal, dtrack, grand, majestic',
6368
date: '2024年04月30日 14:02:57',
@@ -76,6 +81,15 @@ function generateMusic (formData: Recordable) {
7681
}, 3000)
7782
}
7883
84+
/*
85+
*@Description: 设置当前播放的音乐
86+
*@MethodAuthor: xiaohong
87+
*@Date: 2024-07-19 11:22:33
88+
*/
89+
function setCurrentSong (music: Recordable) {
90+
currentSong.value = music
91+
}
92+
7993
defineExpose({
8094
generateMusic
8195
})
@@ -86,9 +100,9 @@ defineExpose({
86100
:deep(.el-tabs) {
87101
display: flex;
88102
flex-direction: column;
89-
.el-tabs__content{
90-
padding: 0 7px;
91-
overflow: auto;
92-
}
103+
.el-tabs__content {
104+
padding: 0 7px;
105+
overflow: auto;
106+
}
93107
}
94108
</style>
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template>
22
<div class="flex bg-[var(--el-bg-color-overlay)] p-12px mb-12px rounded-1">
3-
<el-image :src="imageUrl" class="flex-none w-80px"/>
3+
<el-image :src="songInfo.imageUrl" class="flex-none w-80px"/>
44
<div class="ml-8px">
5-
<div>{{ title }}</div>
5+
<div>{{ songInfo.title }}</div>
66
<div class="mt-8px text-12px text-[var(--el-text-color-secondary)] line-clamp-2">
7-
{{ desc }}
7+
{{ songInfo.desc }}
88
</div>
99
</div>
1010
</div>
@@ -15,15 +15,9 @@
1515
defineOptions({ name: 'Index' })
1616
1717
defineProps({
18-
imageUrl: {
19-
type: String
20-
},
21-
title: {
22-
type: String
23-
},
24-
desc: {
25-
type: String
18+
songInfo: {
19+
type: Object,
20+
default: () => ({})
2621
}
2722
})
28-
2923
</script>
Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
11
<template>
22
<ContentWrap class="w-300px mb-[0!important] line-height-24px">
3-
<el-image :src="imageUrl"/>
4-
<div class="">{{ title }}</div>
5-
<div class="text-[var(--el-text-color-secondary)] text-12px line-clamp-1">{{ desc }}</div>
6-
<div class="text-[var(--el-text-color-secondary)] text-12px">{{ date }}</div>
3+
<el-image :src="currentSong.imageUrl"/>
4+
<div class="">{{ currentSong.title }}</div>
5+
<div class="text-[var(--el-text-color-secondary)] text-12px line-clamp-1">
6+
{{ currentSong.desc }}
7+
</div>
8+
<div class="text-[var(--el-text-color-secondary)] text-12px">
9+
{{ currentSong.date }}
10+
</div>
711
<el-button size="small" round class="my-6px">信息复用</el-button>
8-
<div class="text-[var(--el-text-color-secondary)] text-12px" v-html="lyric"></div>
12+
<div class="text-[var(--el-text-color-secondary)] text-12px" v-html="currentSong.lyric"></div>
913
</ContentWrap>
1014
</template>
1115

1216
<script lang="ts" setup>
1317
1418
defineOptions({ name: 'Index' })
1519
16-
defineProps({
17-
imageUrl: {
18-
type: String
19-
},
20-
title: {
21-
type: String
22-
},
23-
desc: {
24-
type: String
25-
},
26-
date: {
27-
type: String
28-
},
29-
lyric: {
30-
type: String
31-
}
32-
})
20+
const currentSong = inject('currentSong', {})
21+
3322
</script>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ const modeRef = ref<Nullable<{ formData: Recordable }>>(null)
3636
*@Date: 2024-06-27 16:40:16
3737
*/
3838
function generateMusic () {
39-
emits('generate-music', {formData: unref(modeRef)?.formData.value})
39+
emits('generate-music', {formData: unref(modeRef)?.formData})
4040
}
4141
</script>

0 commit comments

Comments
 (0)