feat(music-detail): 添加歌词展开和折叠功能
- 在 MusicDetail 组件中添加了歌词展开和折叠功能 - 新增 isLyricExpanded、isLyricTooLong 和 displayedLyric 等响应式变量 - 实现了 toggleLyricExpansion 方法来切换歌词展开状态 - 在模板中添加了折叠和展开歌词的按钮
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -12,6 +12,7 @@ dist
|
|||||||
dist-ssr
|
dist-ssr
|
||||||
*.local
|
*.local
|
||||||
|
|
||||||
|
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/extensions.json
|
!.vscode/extensions.json
|
||||||
@@ -35,6 +36,7 @@ target
|
|||||||
*.iml
|
*.iml
|
||||||
out
|
out
|
||||||
gen
|
gen
|
||||||
|
*/upload
|
||||||
*/.vscode
|
*/.vscode
|
||||||
.vscode
|
.vscode
|
||||||
#忽略所有.svn目录
|
#忽略所有.svn目录
|
||||||
|
|||||||
@@ -106,7 +106,10 @@
|
|||||||
<div v-if="activeTab === 'lyric'">
|
<div v-if="activeTab === 'lyric'">
|
||||||
<div v-if="music && music.lyric" class="music-lyric">
|
<div v-if="music && music.lyric" class="music-lyric">
|
||||||
<h2>歌词</h2>
|
<h2>歌词</h2>
|
||||||
<pre>{{ music.lyric }}</pre>
|
<pre>{{ displayedLyric }}</pre>
|
||||||
|
<div v-if="isLyricTooLong" class="lyric-toggle-button" @click="toggleLyricExpansion">
|
||||||
|
{{ isLyricExpanded ? '收起歌词' : '查看更多歌词' }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<el-empty v-else description="暂无歌词" />
|
<el-empty v-else description="暂无歌词" />
|
||||||
</div>
|
</div>
|
||||||
@@ -226,6 +229,26 @@ const replyingTo = ref(null)
|
|||||||
const expandedComments = ref([])
|
const expandedComments = ref([])
|
||||||
let commentSubscription = null;
|
let commentSubscription = null;
|
||||||
|
|
||||||
|
const isLyricExpanded = ref(false)
|
||||||
|
const LYRIC_PREVIEW_LINES = 10
|
||||||
|
|
||||||
|
const isLyricTooLong = computed(() => {
|
||||||
|
if (!music.value || !music.value.lyric) return false
|
||||||
|
return music.value.lyric.split('\n').length > LYRIC_PREVIEW_LINES
|
||||||
|
})
|
||||||
|
|
||||||
|
const displayedLyric = computed(() => {
|
||||||
|
if (!music.value || !music.value.lyric) return ''
|
||||||
|
if (isLyricExpanded.value || !isLyricTooLong.value) {
|
||||||
|
return music.value.lyric
|
||||||
|
}
|
||||||
|
return music.value.lyric.split('\n').slice(0, LYRIC_PREVIEW_LINES).join('\n')
|
||||||
|
})
|
||||||
|
|
||||||
|
const toggleLyricExpansion = () => {
|
||||||
|
isLyricExpanded.value = !isLyricExpanded.value
|
||||||
|
}
|
||||||
|
|
||||||
// 计算属性
|
// 计算属性
|
||||||
const isPlaying = computed(() => {
|
const isPlaying = computed(() => {
|
||||||
return playerStore.getCurrentMusic?.id === music.value?.id && playerStore.getIsPlaying
|
return playerStore.getCurrentMusic?.id === music.value?.id && playerStore.getIsPlaying
|
||||||
@@ -517,6 +540,17 @@ onUnmounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.lyric-toggle-button {
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 10px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lyric-toggle-button:hover {
|
||||||
|
color: var(--el-color-primary-light-3);
|
||||||
|
}
|
||||||
.music-detail-page {
|
.music-detail-page {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user