修复音乐/歌单/歌手页搜索清空与标签筛选逻辑
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted, watch } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { Search } from '@element-plus/icons-vue'
|
import { Search } from '@element-plus/icons-vue'
|
||||||
import { getMusicList, getHotMusic, getLatestMusic, processMusicUrl, getMusicStatus } from '../api/music'
|
import { getMusicList, getHotMusic, getLatestMusic, processMusicUrl, getMusicStatus } from '../api/music'
|
||||||
@@ -73,7 +73,10 @@ const fetchMusicTypes = async () => {
|
|||||||
try {
|
try {
|
||||||
const res = await getMusicTypeList()
|
const res = await getMusicTypeList()
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
musicTypes.value = res.data || []
|
musicTypes.value = [
|
||||||
|
{ id: null, name: '全部' },
|
||||||
|
...(res.data || [])
|
||||||
|
]
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取音乐类型失败:', error)
|
console.error('获取音乐类型失败:', error)
|
||||||
@@ -82,12 +85,27 @@ const fetchMusicTypes = async () => {
|
|||||||
|
|
||||||
// 处理搜索
|
// 处理搜索
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
|
if (activeTab.value !== 'all') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
currentPage.value = 1
|
||||||
|
fetchMusicList()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleKeywordClear = () => {
|
||||||
|
if (activeTab.value !== 'all') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
keyword.value = ''
|
||||||
currentPage.value = 1
|
currentPage.value = 1
|
||||||
fetchMusicList()
|
fetchMusicList()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理类型变化
|
// 处理类型变化
|
||||||
const handleTypeChange = () => {
|
const handleTypeChange = () => {
|
||||||
|
if (activeTab.value !== 'all') {
|
||||||
|
return
|
||||||
|
}
|
||||||
currentPage.value = 1
|
currentPage.value = 1
|
||||||
fetchMusicList()
|
fetchMusicList()
|
||||||
}
|
}
|
||||||
@@ -199,6 +217,14 @@ const handleTabChange = (tab) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
watch(keyword, (val) => {
|
||||||
|
if (val === '' && activeTab.value === 'all') {
|
||||||
|
currentPage.value = 1
|
||||||
|
fetchMusicList()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchMusicList()
|
fetchMusicList()
|
||||||
@@ -210,7 +236,7 @@ onMounted(() => {
|
|||||||
<div class="music-page">
|
<div class="music-page">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>音乐库</h1>
|
<h1>音乐库</h1>
|
||||||
<div class="filter-container">
|
<div class="filter-container" v-if="activeTab === 'all'">
|
||||||
<el-select v-model="selectedType" placeholder="音乐类型" clearable @change="handleTypeChange">
|
<el-select v-model="selectedType" placeholder="音乐类型" clearable @change="handleTypeChange">
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in musicTypes"
|
v-for="item in musicTypes"
|
||||||
@@ -224,6 +250,7 @@ onMounted(() => {
|
|||||||
v-model="keyword"
|
v-model="keyword"
|
||||||
placeholder="搜索音乐"
|
placeholder="搜索音乐"
|
||||||
clearable
|
clearable
|
||||||
|
@clear="handleKeywordClear"
|
||||||
@keyup.enter="handleSearch"
|
@keyup.enter="handleSearch"
|
||||||
>
|
>
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted, watch } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useUserStore } from '../stores/user'
|
import { useUserStore } from '../stores/user'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
@@ -129,6 +129,13 @@ const handleSearch = () => {
|
|||||||
fetchPlaylists()
|
fetchPlaylists()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleKeywordClear = () => {
|
||||||
|
keyword.value = ''
|
||||||
|
searchedKeyword.value = ''
|
||||||
|
currentPage.value = 1
|
||||||
|
fetchPlaylists()
|
||||||
|
}
|
||||||
|
|
||||||
// 处理分页变化
|
// 处理分页变化
|
||||||
const handlePageChange = (page) => {
|
const handlePageChange = (page) => {
|
||||||
currentPage.value = page
|
currentPage.value = page
|
||||||
@@ -205,6 +212,15 @@ const formatPlayCount = (count) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
watch(keyword, (val) => {
|
||||||
|
if (val === '' && searchedKeyword.value !== '') {
|
||||||
|
searchedKeyword.value = ''
|
||||||
|
currentPage.value = 1
|
||||||
|
fetchPlaylists()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchPlaylistTypes()
|
fetchPlaylistTypes()
|
||||||
fetchPlaylists()
|
fetchPlaylists()
|
||||||
@@ -221,6 +237,7 @@ onMounted(() => {
|
|||||||
v-model="keyword"
|
v-model="keyword"
|
||||||
placeholder="搜索歌单"
|
placeholder="搜索歌单"
|
||||||
clearable
|
clearable
|
||||||
|
@clear="handleKeywordClear"
|
||||||
@keyup.enter="handleSearch"
|
@keyup.enter="handleSearch"
|
||||||
>
|
>
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted, watch } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useUserStore } from '../stores/user'
|
import { useUserStore } from '../stores/user'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
@@ -127,6 +127,13 @@ const handleSearch = () => {
|
|||||||
fetchSingers()
|
fetchSingers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleKeywordClear = () => {
|
||||||
|
keyword.value = ''
|
||||||
|
searchedKeyword.value = ''
|
||||||
|
currentPage.value = 1
|
||||||
|
fetchSingers()
|
||||||
|
}
|
||||||
|
|
||||||
// 处理分页变化
|
// 处理分页变化
|
||||||
const handlePageChange = (page) => {
|
const handlePageChange = (page) => {
|
||||||
currentPage.value = page
|
currentPage.value = page
|
||||||
@@ -205,6 +212,15 @@ const formatFans = (count) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
watch(keyword, (val) => {
|
||||||
|
if (val === '' && searchedKeyword.value !== '') {
|
||||||
|
searchedKeyword.value = ''
|
||||||
|
currentPage.value = 1
|
||||||
|
fetchSingers()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchSingerTypes()
|
fetchSingerTypes()
|
||||||
fetchSingers()
|
fetchSingers()
|
||||||
@@ -221,6 +237,7 @@ onMounted(() => {
|
|||||||
v-model="keyword"
|
v-model="keyword"
|
||||||
placeholder="搜索歌手"
|
placeholder="搜索歌手"
|
||||||
clearable
|
clearable
|
||||||
|
@clear="handleKeywordClear"
|
||||||
@keyup.enter="handleSearch"
|
@keyup.enter="handleSearch"
|
||||||
>
|
>
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
|
|||||||
Reference in New Issue
Block a user