44 <div v-if =" !isEmpty(listData)" ref =" songListRef" class =" song-list" >
55 <Transition name="fade" mode="out-in">
66 <div
7- :key =" listKey"
7+ :key =" listKey + '_' + statusStore.listSort "
88 :style =" { height: height === 'auto' ? 'auto' : `${height || songListHeight}px` }"
99 class =" virtual-list-wrapper"
1010 >
3434 <n-text v-if =" data?.[0].size && !hiddenSize" class =" meta size" >大小</n-text >
3535 </div >
3636 <!-- 虚拟列表 -->
37- <n-virtual-list
37+ <VirtualScroll
3838 ref="listRef"
39- :item-size =" 94"
39+ :item-height =" 90 "
40+ :item-fixed =" true "
4041 :items =" virtualListItems "
41- :style = " { height: `calc(100% - 40px)` } "
42+ :height = " ` calc(100% - 40px) ` "
4243 :padding-bottom =" 80 "
43- item-resizable
4444 @scroll =" onScroll "
4545 >
4646 <template #default =" { item , index } " >
7777 <n-divider v-else dashed > 没有更多啦 ~ </n-divider >
7878 </div >
7979 </template >
80- </n-virtual-list >
80+ </VirtualScroll >
8181 </div >
8282 </Transition >
8383 <!-- 右键菜单 -->
108108</template >
109109
110110<script setup lang="ts">
111- import type { DropdownOption , VirtualListInst } from " naive-ui" ;
111+ import type { DropdownOption } from " naive-ui" ;
112112import { SongType , SortType } from " @/types/main" ;
113113import { useMusicStore , useStatusStore } from " @/stores" ;
114114import { entries , isEmpty } from " lodash-es" ;
115115import { sortOptions } from " @/utils/meta" ;
116116import { renderIcon } from " @/utils/helper" ;
117117import { usePlayerController } from " @/core/player/PlayerController" ;
118118import SongListMenu from " @/components/Menu/SongListMenu.vue" ;
119+ import VirtualScroll from " @/components/UI/VirtualScroll.vue" ;
119120
120121const props = withDefaults (
121122 defineProps <{
@@ -177,7 +178,7 @@ const scrollTop = ref<number>(0);
177178const scrollIndex = ref <number >(0 );
178179
179180// 列表元素
180- const listRef = ref <VirtualListInst | null >(null );
181+ const listRef = ref <InstanceType < typeof VirtualScroll > | null >(null );
181182const songListRef = ref <HTMLElement | null >(null );
182183
183184// 悬浮工具
@@ -286,7 +287,7 @@ const onScroll = (e: Event) => {
286287 const target = e .target as HTMLElement ;
287288 const top = target .scrollTop ;
288289 scrollTop .value = top ;
289- scrollIndex .value = Math .floor (top / 94 );
290+ scrollIndex .value = Math .floor (top / 90 );
290291
291292 // 触底检测
292293 const scrollHeight = target .scrollHeight ;
@@ -298,13 +299,13 @@ const onScroll = (e: Event) => {
298299
299300// 滚动到顶部
300301const scrollToTop = () => {
301- listRef .value ?.scrollTo ({ index: 0 } );
302+ listRef .value ?.scrollToIndex ( 0 );
302303};
303304
304305// 滚动到当前播放歌曲
305306const scrollToCurrentSong = () => {
306307 if (hasPlaySong .value >= 0 ) {
307- listRef .value ?.scrollTo ({ index: hasPlaySong .value } );
308+ listRef .value ?.scrollToIndex ( hasPlaySong .value );
308309 }
309310};
310311
@@ -321,9 +322,9 @@ const sortSelect = (key: SortType) => {
321322 // 滚动到当前播放歌曲或顶部
322323 nextTick (() => {
323324 if (hasPlaySong .value >= 0 ) {
324- listRef .value ?.scrollTo ({ index: hasPlaySong .value } );
325+ listRef .value ?.scrollToIndex ( hasPlaySong .value );
325326 } else {
326- listRef .value ?.scrollTo ({ index: 0 } );
327+ listRef .value ?.scrollToIndex ( 0 );
327328 }
328329 });
329330};
@@ -341,7 +342,7 @@ onActivated(() => {
341342 if (props .height === " auto" ) stopCalcHeight ();
342343 if (scrollIndex .value > 0 ) {
343344 nextTick (() => {
344- listRef .value ?.scrollTo ({ index: scrollIndex .value , behavior: " auto " } );
345+ listRef .value ?.scrollToIndex ( scrollIndex .value );
345346 });
346347 }
347348});
@@ -446,6 +447,10 @@ onBeforeUnmount(() => {
446447 .virtual-list-wrapper {
447448 height : 100% ;
448449 position : relative ;
450+ transition :
451+ height 0.3s ,
452+ transform 0.3s ,
453+ opacity 0.3s ;
449454 .sticky-header {
450455 position : sticky ;
451456 top : 0 ;
0 commit comments