Pārlūkot izejas kodu

webdav的歌曲list改成懒加载

onecold 9 mēneši atpakaļ
vecāks
revīzija
40a9746be4

+ 5 - 2
entry/src/main/ets/Constants.ets

@@ -10,7 +10,10 @@ export class Constants {
   public static readonly CHUNK_SIZE: number = 100
 
   // 音频文件扩展名
-  public static readonly AUDIO_EXTENSIONS = ['.mp3', '.aac', '.m4a', '.wav', '.ogg', '.flac', '.ape', '.wma', '.alac', '.opus']
+  public static readonly AUDIO_EXTENSIONS = ['.mp3','.mp3','.wma','.mp2','.mov','.flac',
+    '.midi','.ra','.aac','.ape','.cda','.alac','.m4a','.ogg','.opus','.wv','.aiff','.amr','.aif','.dff'
+    ,'.aif','.au','.eac3','.mlp','.tak','.thd','.tta','.wv','.ac3','.amr','.mka','.mpc','.ra',
+    '.asf','.m2ts','.m4b','.mts','.rm','.wtv','.dts','.av3a','.dsd','.dsf']
 
   // 图片扩展名
   public static readonly IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.webp', '.bmp']
@@ -27,5 +30,5 @@ export class Constants {
   public static readonly UNKNOWN_MIME_TYPE: string = 'audio/mpeg'
 
   // 默认封面
-  public static readonly COMMON_SONG_DEFAULT_IMAGE: ResourceStr = $r('app.media.icon')
+  public static readonly COMMON_SONG_DEFAULT_IMAGE: ResourceStr = $r('app.media.music_red')
 }

+ 1 - 1
entry/src/main/ets/common/constants/CommonConstants.ets

@@ -91,7 +91,7 @@ export class CommonConstants {
   static readonly REAL_MUSIC_FORMAT = ['.mp3','.mp3','.wma','.mp2','.mov','.flac',
     '.midi','.ra','.aac','.ape','.cda','.lrc','.alac','.m4a','.ogg','.opus','.wv','.aiff','.amr','.aif','.dff'
     ,'.aif','.au','.eac3','.mlp','.tak','.thd','.tta','.wv','.ac3','.amr','.mka','.mpc','.ra',
-    '.asf','.m2ts','.m4b','.mts','.rm','.wtv','.dts','.av3a','.dsd']
+    '.asf','.m2ts','.m4b','.mts','.rm','.wtv','.dts','.av3a','.dsd','.dsf']
 
 
   // 倍数格式支持列表

+ 29 - 24
entry/src/main/ets/pages/WebDavMainPage.ets

@@ -11,6 +11,7 @@ import { display } from '@kit.ArkUI';
 import { FileInfo } from '../viewmodel/FileInfo';
 import { emitter } from '@kit.BasicServicesKit';
 import { EventConstants } from '../common/constants/EventConstants';
+import { LazyDataSource } from '../common/util/LazyDataSource';
 
 /**
  * 歌单播放事件数据
@@ -56,7 +57,10 @@ export struct WebDavMainPage {
   @State accounts: WebDavAccount[] = [];
   @Prop @Watch('onSwitchAccount') selectedAccount: WebDavAccount;
   @State songs: Song[] = [];
+  @State  dataSource:LazyDataSource<Song> = new LazyDataSource(this.songs)
   @Link mType: number;
+  @Link offsetX: number;
+  @Link isShowDrawer: boolean;
   @State isLoading: boolean = false;
   @State webDavFiles: FileInfo[] = []; // 直接在页面中保存文件列表副本
   @StorageProp('themeColor') themeColor: string = CommonConstants.DEFAULT_THEME_COLOR;
@@ -69,6 +73,7 @@ export struct WebDavMainPage {
   onSwitchAccount(){
     console.log('onecold 切换账户:', this.selectedAccount.name);
     this.songs = [];
+    this.updateListData(this.songs)
     this.isLoading = true;
     this.webdavManager.loadFilesInfoFromAccount(this.selectedAccount)
       .catch((error: Error) => {
@@ -78,6 +83,10 @@ export struct WebDavMainPage {
     this.breadcrumbs = this.webdavManager.getBreadcrumbs();
   }
 
+  updateListData(mList:Array<Song>){
+    this.dataSource.pushArrayData(mList)
+  }
+
   // 更新可见文件夹列表
   private updateVisibleFolders(): void {
     try {
@@ -157,6 +166,7 @@ export struct WebDavMainPage {
     switch (event) {
       case WebdavManagerStates.LoadFilesInfoSucceed:
         this.songs = this.webdavManager.webDavSongs;
+        this.updateListData(this.songs)
         // 直接引用webdavManager的数组,避免@Observed序列化问题
         this.webDavFiles = this.webdavManager.webDavFiles;
         this.isLoading = false;
@@ -252,6 +262,7 @@ export struct WebDavMainPage {
   private switchAccount(account: WebDavAccount): void {
     this.selectedAccount = account;
     this.songs = [];
+    this.updateListData(this.songs)
   }
 
 
@@ -363,15 +374,15 @@ export struct WebDavMainPage {
       emitter.emit(eventPlaylistPlay, eventData);
 
       // 跳转到首页播放器
-      // router.pushUrl({
-      //   url: 'pages/NewIndex',
-      //   params: {
-      //     fromWebDAV: true
-      //   }
-      // }).catch((error: Error) => {
-      //   Logger.error(TAG, '跳转首页失败: ' + error.message);
-      //   this.getUIContext().getPromptAction().showToast({ message: '跳转失败' });
-      // });
+      router.pushUrl({
+        url: 'pages/NewIndex',
+        params: {
+          fromWebDAV: true
+        }
+      }).catch((error: Error) => {
+        Logger.error(TAG, '跳转首页失败: ' + error.message);
+        this.getUIContext().getPromptAction().showToast({ message: '跳转失败' });
+      });
     } catch (error) {
       const err = error as Error;
       Logger.error(TAG, '播放歌曲失败: ' + err.message);
@@ -408,13 +419,15 @@ export struct WebDavMainPage {
 
         // 标题栏
         Row() {
-          Image($r('app.media.back'))
+          Image($r('app.media.menu'))
             .width(24)
             .height(24)
             .margin({ left: 12, right: 8 })
             .onClick(() => {
               this.getUIContext()?.animateTo({ duration: 555 }, () => {
-                this.mType =0
+                // this.mType =0
+                this.isShowDrawer = !this.isShowDrawer
+                this.offsetX = 0
               })
               });
 
@@ -567,7 +580,7 @@ export struct WebDavMainPage {
           })
 
           // 显示歌曲
-          ForEach(this.songs, (song: Song, index: number) => {
+          LazyForEach(this.dataSource, (song: Song, index: number) => {
             ListItem() {
               this.buildSongItem(song, index)
             }
@@ -599,10 +612,10 @@ export struct WebDavMainPage {
   @Builder
   buildFolderItem(folder: FileInfo) {
     Row({ space: 2 }) {
-      Image($r('app.media.dir'))
-        .width(32)
-        .height(32)
-        .fillColor(this.themeColor)
+      SymbolGlyph($r('sys.symbol.folder'))
+        .fontSize(48)
+        .fontColor([this.themeColor])
+        .alignSelf(ItemAlign.Center)
         .margin({ left: 8, right: 6 })
 
       // 文件夹信息
@@ -635,18 +648,10 @@ export struct WebDavMainPage {
   buildSongItem(song: Song, index: number) {
     Row({ space: 12 }) {
       // 序号
-      // Text((index + 1).toString())
-      //   .fontSize(14)
-      //   .fontColor($r('app.color.index_tab_font_color'))
-      //   .opacity(0.6)
-      //   .width(30)
-      //   .textAlign(TextAlign.Center)
-
       // 歌曲封面
       Image(song.img)
         .width(48)
         .height(48)
-        .alt($r('app.media.new_music'))
         .borderRadius(4)
         .objectFit(ImageFit.Cover)