feat(search): 优化音乐源选择功能
Browse files- src/components/search/SearchBox.vue +64 -2
- src/main.js +0 -29
src/components/search/SearchBox.vue
CHANGED
|
@@ -27,12 +27,28 @@
|
|
| 27 |
</div>
|
| 28 |
|
| 29 |
<button
|
|
|
|
| 30 |
class="source-btn"
|
| 31 |
@click="showSourceSelector = true"
|
| 32 |
>
|
| 33 |
{{ currentSourceName }}
|
| 34 |
<i class="fas fa-chevron-down"></i>
|
| 35 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
</div>
|
| 37 |
|
| 38 |
<!-- 音乐源选择弹窗 -->
|
|
@@ -66,6 +82,14 @@ const currentSourceName = computed(() => {
|
|
| 66 |
return source ? source.name : '网易云音乐'
|
| 67 |
})
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
// 方法
|
| 70 |
const handleSearch = () => {
|
| 71 |
const keyword = searchKeyword.value.trim()
|
|
@@ -92,6 +116,10 @@ const handleSourceSelect = (sourceCode) => {
|
|
| 92 |
showSourceSelector.value = false
|
| 93 |
}
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
// 监听搜索关键词变化
|
| 96 |
watch(() => searchStore.keyword, (newKeyword) => {
|
| 97 |
if (newKeyword && newKeyword !== searchKeyword.value) {
|
|
@@ -212,12 +240,46 @@ defineExpose({
|
|
| 212 |
white-space: nowrap;
|
| 213 |
transition: var(--transition-fast);
|
| 214 |
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
| 215 |
-
flex-shrink: 0;
|
| 216 |
-
max-width: 120px;
|
| 217 |
overflow: hidden;
|
| 218 |
text-overflow: ellipsis;
|
| 219 |
}
|
| 220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
.source-btn:hover {
|
| 222 |
border-color: var(--accent-red);
|
| 223 |
color: var(--accent-red);
|
|
|
|
| 27 |
</div>
|
| 28 |
|
| 29 |
<button
|
| 30 |
+
v-if="isMobile"
|
| 31 |
class="source-btn"
|
| 32 |
@click="showSourceSelector = true"
|
| 33 |
>
|
| 34 |
{{ currentSourceName }}
|
| 35 |
<i class="fas fa-chevron-down"></i>
|
| 36 |
</button>
|
| 37 |
+
|
| 38 |
+
<select
|
| 39 |
+
v-else
|
| 40 |
+
:value="searchStore.currentSource"
|
| 41 |
+
@change="handleSourceChange"
|
| 42 |
+
class="pc-source-select"
|
| 43 |
+
>
|
| 44 |
+
<option
|
| 45 |
+
v-for="source in sortedSources"
|
| 46 |
+
:key="source.code"
|
| 47 |
+
:value="source.code"
|
| 48 |
+
>
|
| 49 |
+
{{ source.name }}
|
| 50 |
+
</option>
|
| 51 |
+
</select>
|
| 52 |
</div>
|
| 53 |
|
| 54 |
<!-- 音乐源选择弹窗 -->
|
|
|
|
| 82 |
return source ? source.name : '网易云音乐'
|
| 83 |
})
|
| 84 |
|
| 85 |
+
const sortedSources = computed(() =>
|
| 86 |
+
MUSIC_SOURCES.sort((a, b) => a.priority - b.priority)
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
const isMobile = computed(() => {
|
| 90 |
+
return window.innerWidth <= 768
|
| 91 |
+
})
|
| 92 |
+
|
| 93 |
// 方法
|
| 94 |
const handleSearch = () => {
|
| 95 |
const keyword = searchKeyword.value.trim()
|
|
|
|
| 116 |
showSourceSelector.value = false
|
| 117 |
}
|
| 118 |
|
| 119 |
+
const handleSourceChange = (event) => {
|
| 120 |
+
searchStore.setSource(event.target.value)
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
// 监听搜索关键词变化
|
| 124 |
watch(() => searchStore.keyword, (newKeyword) => {
|
| 125 |
if (newKeyword && newKeyword !== searchKeyword.value) {
|
|
|
|
| 240 |
white-space: nowrap;
|
| 241 |
transition: var(--transition-fast);
|
| 242 |
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
| 243 |
+
flex-shrink: 0;
|
| 244 |
+
max-width: 120px;
|
| 245 |
overflow: hidden;
|
| 246 |
text-overflow: ellipsis;
|
| 247 |
}
|
| 248 |
|
| 249 |
+
.pc-source-select {
|
| 250 |
+
height: 44px;
|
| 251 |
+
padding: 0 16px;
|
| 252 |
+
background: var(--bg-card);
|
| 253 |
+
border: 1px solid var(--border-light);
|
| 254 |
+
border-radius: 22px;
|
| 255 |
+
color: var(--text-primary);
|
| 256 |
+
font-size: 14px;
|
| 257 |
+
cursor: pointer;
|
| 258 |
+
outline: none;
|
| 259 |
+
transition: var(--transition-fast);
|
| 260 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
| 261 |
+
flex-shrink: 0;
|
| 262 |
+
min-width: 120px;
|
| 263 |
+
appearance: none;
|
| 264 |
+
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
|
| 265 |
+
background-repeat: no-repeat;
|
| 266 |
+
background-position: right 12px center;
|
| 267 |
+
background-size: 16px;
|
| 268 |
+
padding-right: 40px;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
.pc-source-select:hover {
|
| 272 |
+
border-color: var(--accent-red);
|
| 273 |
+
color: var(--accent-red);
|
| 274 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
| 275 |
+
transform: translateY(-1px);
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
.pc-source-select:focus {
|
| 279 |
+
border-color: var(--accent-red);
|
| 280 |
+
box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.1);
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
.source-btn:hover {
|
| 284 |
border-color: var(--accent-red);
|
| 285 |
color: var(--accent-red);
|
src/main.js
CHANGED
|
@@ -38,35 +38,6 @@ if ('mediaSession' in navigator) {
|
|
| 38 |
console.log('MediaSession API 不支持')
|
| 39 |
}
|
| 40 |
|
| 41 |
-
// PWA 安装提示
|
| 42 |
-
let deferredPrompt
|
| 43 |
-
window.addEventListener('beforeinstallprompt', (e) => {
|
| 44 |
-
console.log('PWA 可以安装')
|
| 45 |
-
e.preventDefault()
|
| 46 |
-
deferredPrompt = e
|
| 47 |
-
|
| 48 |
-
// 可以在这里显示安装提示
|
| 49 |
-
showInstallPrompt()
|
| 50 |
-
})
|
| 51 |
-
|
| 52 |
-
function showInstallPrompt() {
|
| 53 |
-
// 显示安装应用的提示
|
| 54 |
-
if (deferredPrompt) {
|
| 55 |
-
const shouldInstall = confirm('是否将云音乐添加到主屏幕?')
|
| 56 |
-
if (shouldInstall) {
|
| 57 |
-
deferredPrompt.prompt()
|
| 58 |
-
deferredPrompt.userChoice.then((choiceResult) => {
|
| 59 |
-
if (choiceResult.outcome === 'accepted') {
|
| 60 |
-
console.log('用户接受了安装')
|
| 61 |
-
} else {
|
| 62 |
-
console.log('用户拒绝了安装')
|
| 63 |
-
}
|
| 64 |
-
deferredPrompt = null
|
| 65 |
-
})
|
| 66 |
-
}
|
| 67 |
-
}
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
// 全局错误处理
|
| 71 |
app.config.errorHandler = (err, instance, info) => {
|
| 72 |
console.error('Global error:', err)
|
|
|
|
| 38 |
console.log('MediaSession API 不支持')
|
| 39 |
}
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
// 全局错误处理
|
| 42 |
app.config.errorHandler = (err, instance, info) => {
|
| 43 |
console.error('Global error:', err)
|