Skip to content

Commit d89be48

Browse files
committed
修复列表问题 #569 #568
1 parent 4bf986b commit d89be48

3 files changed

Lines changed: 39 additions & 16 deletions

File tree

src/components/List/SongList.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,13 @@ const listData = computed<SongType[]>(() => {
234234
const listKey = computed(() => {
235235
// 每日推荐
236236
if (props.isDailyRecommend) {
237-
return musicStore.dailySongsData.timestamp || 0;
237+
return `daily-${musicStore.dailySongsData.timestamp || 0}`;
238238
}
239-
// 其他列表长度(检测增删操作)
240-
return listData.value?.length || 0;
239+
// 使用 playListId 作为主要 key
240+
if (props.playListId) {
241+
return `playlist-${props.playListId}`;
242+
}
243+
return `type-${props.type}`;
241244
});
242245
243246
// 列表是否具有播放歌曲
@@ -261,7 +264,9 @@ const sortMenuOptions = computed<DropdownOption[]>(() =>
261264
// 列表滚动
262265
const onScroll = (e: Event) => {
263266
emit("scroll", e);
264-
scrollTop.value = (e.target as HTMLElement).scrollTop;
267+
const top = (e.target as HTMLElement).scrollTop;
268+
scrollTop.value = top;
269+
offset.value = top;
265270
};
266271
267272
// 列表触底

src/components/Player/MainLyric.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const lyricsScroll = (index: number) => {
205205
const container = lrcItemDom.parentElement;
206206
if (!container) return;
207207
// 调整滚动的距离
208-
const scrollDistance = lrcItemDom.offsetTop - container.offsetTop - 80;
208+
const scrollDistance = lrcItemDom.offsetTop - container.offsetTop - 100;
209209
// 开始滚动
210210
if (settingStore.lyricsScrollPosition === "center") {
211211
lrcItemDom?.scrollIntoView({ behavior: "smooth", block: "center" });
@@ -399,8 +399,8 @@ onBeforeUnmount(() => {
399399
top: 0;
400400
transform: none;
401401
will-change: -webkit-mask-position-x, transform, opacity;
402-
// padding: 2px 8px;
403-
// margin: -2px -8px;
402+
padding: 0.3em 0;
403+
margin: -0.3em 0;
404404
mask-image: linear-gradient(
405405
to right,
406406
rgb(0, 0, 0) 45.4545454545%,

src/views/Search/layout.vue

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div :key="searchKeyword" class="search">
2+
<div class="search">
33
<div class="title">
44
<n-text class="keyword">{{ searchKeyword }}</n-text>
55
<n-text depth="3">的相关搜索</n-text>
@@ -17,9 +17,20 @@
1717
<RouterView v-slot="{ Component }">
1818
<Transition :name="`router-${settingStore.routeAnimation}`" mode="out-in">
1919
<KeepAlive v-if="settingStore.useKeepAlive">
20-
<component :is="Component" :keyword="searchKeyword" class="router-view" />
20+
<component
21+
:is="Component"
22+
:key="route.fullPath"
23+
:keyword="searchKeyword"
24+
class="router-view"
25+
/>
2126
</KeepAlive>
22-
<component v-else :is="Component" :keyword="searchKeyword" class="router-view" />
27+
<component
28+
v-else
29+
:is="Component"
30+
:key="route.fullPath"
31+
:keyword="searchKeyword"
32+
class="router-view"
33+
/>
2334
</Transition>
2435
</RouterView>
2536
</div>
@@ -28,14 +39,15 @@
2839
<script setup lang="ts">
2940
import { useSettingStore } from "@/stores";
3041
42+
const route = useRoute();
3143
const router = useRouter();
3244
const settingStore = useSettingStore();
3345
3446
// 搜索关键词
35-
const searchKeyword = computed(() => router.currentRoute.value.query.keyword as string);
47+
const searchKeyword = computed(() => route.query.keyword as string);
3648
3749
// 搜索分类
38-
const searchType = ref<string>((router.currentRoute.value?.name as string) || "search-songs");
50+
const searchType = ref<string>("search-songs");
3951
4052
// Tabs 改变
4153
const tabChange = (value: string) => {
@@ -47,10 +59,16 @@ const tabChange = (value: string) => {
4759
});
4860
};
4961
50-
onBeforeRouteUpdate((to) => {
51-
if (to.matched[0].name !== "search") return;
52-
searchType.value = to.name as string;
53-
});
62+
// 监听路由变化,同步 Tab 状态
63+
watch(
64+
() => route.name,
65+
(name) => {
66+
if (name && name.toString().startsWith("search-")) {
67+
searchType.value = name as string;
68+
}
69+
},
70+
{ immediate: true },
71+
);
5472
</script>
5573

5674
<style lang="scss" scoped>

0 commit comments

Comments
 (0)