Parcourir la source

切换webdav账号的问题

onecold il y a 9 mois
Parent
commit
9ced744e1e

+ 6 - 1
entry/src/main/ets/common/util/WebdavManager.ets

@@ -77,6 +77,8 @@ export class WebdavManager {
   public currentUploadTask: TransferTask | null = null;
   public isPauseUpload: boolean = true;
 
+  public currentAccount:WebDavAccount = new WebDavAccount();
+
   public constructor() {
     this.rcpSocket.subscribeHTTPDataTransfer((event: string) => {
       this.notifyObservers(event);
@@ -297,6 +299,8 @@ export class WebdavManager {
 
   // 获取激活的账户
   public getActivatedWebDavAccount(): WebDavAccount | null {
+    if(this.currentAccount)
+      return this.currentAccount;
     for (let i = 0; i < this.webDavAccounts.length; i++) {
       const account = this.webDavAccounts[i];
       if (account.isActivate) {
@@ -310,6 +314,7 @@ export class WebdavManager {
 
   // 从WebDAV加载文件列表
   public async loadFilesInfoFromWebdav(customPath?: string): Promise<void> {
+
     const account = this.getActivatedWebDavAccount();
     if (!account) {
       Logger.error(TAG, '没有激活的WebDAV账户');
@@ -375,7 +380,7 @@ export class WebdavManager {
 
 
   public async loadFilesInfoFromAccount(account: WebDavAccount,customPath?: string): Promise<void> {
-
+    this.currentAccount = account;
 
     try {
       this.notifyObservers(WebdavManagerStates.LoadFilesInfoStart);

+ 17 - 7
entry/src/main/ets/pages/WebDavMainPage.ets

@@ -70,12 +70,13 @@ export struct WebDavMainPage {
 
   @State visibleFoldersState: FileInfo[] = []; // 改为普通状态变量
 
-  onSwitchAccount(){
+  async onSwitchAccount(){
     console.log('onecold 切换账户:', this.selectedAccount.name);
     this.songs = [];
+    this.visibleFoldersState = [];
     this.updateListData(this.songs)
     this.isLoading = true;
-    this.webdavManager.loadFilesInfoFromAccount(this.selectedAccount)
+    await this.webdavManager.loadFilesInfoFromAccount(this.selectedAccount)
       .catch((error: Error) => {
         Logger.error(TAG, '加载文件失败: ' + error.message);
         this.isLoading = false;
@@ -174,9 +175,9 @@ export struct WebDavMainPage {
         // 更新可见文件夹列表
         this.updateVisibleFolders();
 
-        // promptAction.showToast({
-        //   message: '加载成功: ' + this.webDavFiles.filter(f => f.isDirectory).length + '个文件夹, ' + this.songs.length + '首歌曲'
-        // });
+        promptAction.showToast({
+          message: '加载成功: ' + this.webDavFiles.filter(f => f.isDirectory).length + '个文件夹, ' + this.songs.length + '首歌曲'
+        });
         break;
       case WebdavManagerStates.LoadFilesInfoFailed:
         this.isLoading = false;
@@ -577,6 +578,9 @@ export struct WebDavMainPage {
             ListItem() {
               this.buildFolderItem(folder)
             }
+            .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 600 }),
+              TransitionEffect.scale({ x: 0, y: 0 })))
+            .clickEffect({ level: ClickEffectLevel.MIDDLE })
           })
 
           // 显示歌曲
@@ -584,6 +588,9 @@ export struct WebDavMainPage {
             ListItem() {
               this.buildSongItem(song, index)
             }
+            .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 }).animation({ duration: 600 }),
+              TransitionEffect.scale({ x: 0, y: 0 })))
+            .clickEffect({ level: ClickEffectLevel.MIDDLE })
           })
         }
         .layoutWeight(1)
@@ -639,7 +646,8 @@ export struct WebDavMainPage {
     .reuseId('dir_item')
     .width('100%')
     .padding(12)
-    .backgroundColor($r('app.color.start_window_background'))
+    .backgroundColor(Color.Transparent)
+    // .backgroundColor($r('app.color.start_window_background'))
     .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.8 })
     .onClick(() => {
       this.enterFolder(folder);
@@ -658,7 +666,9 @@ export struct WebDavMainPage {
           .width(48)
           .height(48)
           .borderRadius(4)
+          .fillColor(this.themeColor)
           .objectFit(ImageFit.Cover)
+          .margin({ left: 8 })
 
         // 歌曲信息
         Column({ space: 4 }) {
@@ -689,7 +699,7 @@ export struct WebDavMainPage {
     .width('100%')
     .padding(12)
     .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.8 })
-    .backgroundColor($r('app.color.start_window_background'))
+    .backgroundColor(Color.Transparent)
     .onClick(() => {
       this.playSong(song, index);
     })