Skip to content

Commit 5070a08

Browse files
committed
feat: 优化收藏和历史列表组件,添加加载状态管理和动画效果
1 parent e5adb8a commit 5070a08

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

src/renderer/views/favorite/index.vue

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
:key="song.id"
8181
:item="song"
8282
:favorite="false"
83+
class="favorite-list-item"
8384
:class="setAnimationClass('animate__bounceInLeft')"
8485
:style="getItemAnimationDelay(index)"
8586
:selectable="isSelecting"
@@ -103,7 +104,7 @@
103104
</template>
104105

105106
<script setup lang="ts">
106-
import { computed, onMounted, ref, watch } from 'vue';
107+
import { computed, ref, watch, onMounted } from 'vue';
107108
import { useI18n } from 'vue-i18n';
108109
import { useRouter } from 'vue-router';
109110
@@ -339,20 +340,27 @@ const handleBatchDownload = async () => {
339340
}
340341
};
341342
343+
const hasLoaded = ref(false);
344+
342345
onMounted(async () => {
343-
await playerStore.initializeFavoriteList();
344-
await getFavoriteSongs();
346+
if (!hasLoaded.value) {
347+
await playerStore.initializeFavoriteList();
348+
await getFavoriteSongs();
349+
hasLoaded.value = true;
350+
}
345351
});
346352
347-
// 监听收藏列表变化
353+
// 监听收藏列表变化,变化时重置并重新加载
348354
watch(
349355
favoriteList,
350-
() => {
356+
async () => {
357+
hasLoaded.value = false;
351358
currentPage.value = 1;
352359
noMore.value = false;
353-
getFavoriteSongs();
360+
await getFavoriteSongs();
361+
hasLoaded.value = true;
354362
},
355-
{ deep: true, immediate: true }
363+
{ deep: true }
356364
);
357365
358366
const handlePlay = () => {
@@ -505,7 +513,9 @@ const handleBatchDownload = async () => {
505513
506514
.favorite-list {
507515
@apply space-y-2 pb-4 px-4;
508-
516+
&-item {
517+
@apply bg-light-100 dark:bg-dark-100 hover:bg-light-200 dark:hover:bg-dark-200 transition-all;
518+
}
509519
&-more {
510520
@apply mt-4;
511521

src/renderer/views/history/index.vue

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</template>
3333

3434
<script setup lang="ts">
35-
import { onMounted, ref } from 'vue';
35+
import { ref, onMounted, watch } from 'vue';
3636
import { useI18n } from 'vue-i18n';
3737
3838
import { getBilibiliProxyUrl, getBilibiliVideoDetail } from '@/api/bilibili';
@@ -42,18 +42,14 @@ import { useMusicHistory } from '@/hooks/MusicHistoryHook';
4242
import { usePlayerStore } from '@/store/modules/player';
4343
import type { SongResult } from '@/type/music';
4444
import { setAnimationClass, setAnimationDelay } from '@/utils';
45-
46-
defineOptions({
47-
name: 'History'
48-
});
49-
5045
const { t } = useI18n();
5146
const { delMusic, musicList } = useMusicHistory();
5247
const scrollbarRef = ref();
5348
const loading = ref(false);
5449
const noMore = ref(false);
5550
const displayList = ref<SongResult[]>([]);
5651
const playerStore = usePlayerStore();
52+
const hasLoaded = ref(false);
5753
5854
// 无限滚动相关配置
5955
const pageSize = 100;
@@ -178,10 +174,26 @@ const handlePlay = () => {
178174
playerStore.setPlayList(displayList.value);
179175
};
180176
181-
onMounted(() => {
182-
getHistorySongs();
177+
onMounted(async () => {
178+
if (!hasLoaded.value) {
179+
await getHistorySongs();
180+
hasLoaded.value = true;
181+
}
183182
});
184183
184+
// 监听历史列表变化,变化时重置并重新加载
185+
watch(
186+
musicList,
187+
async () => {
188+
hasLoaded.value = false;
189+
currentPage.value = 1;
190+
noMore.value = false;
191+
await getHistorySongs();
192+
hasLoaded.value = true;
193+
},
194+
{ deep: true }
195+
);
196+
185197
// 重写删除方法,需要同时更新 displayList
186198
const handleDelMusic = async (item: SongResult) => {
187199
delMusic(item);
@@ -205,7 +217,7 @@ const handleDelMusic = async (item: SongResult) => {
205217
.history-item {
206218
@apply flex items-center justify-between;
207219
&-content {
208-
@apply flex-1;
220+
@apply flex-1 bg-light-100 dark:bg-dark-100 hover:bg-light-200 dark:hover:bg-dark-200 transition-all;
209221
}
210222
&-count {
211223
@apply px-4 text-lg text-center;

src/renderer/views/historyAndFavorite/index.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<template>
22
<div class="flex gap-4 h-full pb-4">
33
<favorite class="flex-item" />
4-
<history class="flex-item" />
4+
<history-list class="flex-item" />
55
</div>
66
</template>
77

88
<script setup lang="ts">
9+
defineOptions({
10+
name: 'History'
11+
});
12+
913
import Favorite from '@/views/favorite/index.vue';
10-
import History from '@/views/history/index.vue';
14+
import HistoryList from '@/views/history/index.vue';
1115
</script>
1216

1317
<style scoped>

0 commit comments

Comments
 (0)