Sfoglia il codice sorgente

优化webdav界面

onecold 9 mesi fa
parent
commit
7b8e30d7ac

+ 10 - 10
entry/src/main/ets/pages/NewIndex.ets

@@ -1507,7 +1507,7 @@ struct NewIndex {
       await this.webdavManager.createWebDavTableInDB()
 
       // 订阅WebDAV管理器事件
-      this.webdavManager.webdavManager((event: string) => {
+      this.webdavManager.subscribe((event: string) => {
         LogUtil.info('heanup NewIndex', '收到WebDAV事件:', event)
         if (event === 'QueryAccountsSucceed') {
           this.webDavAccounts = this.webdavManager.getAllWebDavAccounts().slice()
@@ -1557,12 +1557,12 @@ struct NewIndex {
 
         // 更新数据库中的激活状态
         this.webdavManager.editAccount(account).then(() => {
-          LogUtil.info('heanup NewIndex', 'WebDAV账户激活成功:', account.name)
-          // 重新加载账户列表
-          this.loadWebDavAccounts()
+          LogUtil.info('heanup NewIndex', 'WebDAV账户编辑成功:', account.name)
+          // 重新加载账户列表,观察着模式通知更新了,这里不需要更新
+          // this.loadWebDavAccounts()
         }).catch((error: Error) => {
-          LogUtil.error('heanup NewIndex', `激活WebDAV账户失败: ${error.message}`)
-          ToastUtil.showToast('激活账户失败')
+          LogUtil.error('heanup NewIndex', `编辑WebDAV账户失败: ${error.message}`)
+          ToastUtil.showToast('编辑账户失败')
         })
       }
 
@@ -1611,8 +1611,8 @@ struct NewIndex {
            // 编辑模式:更新现有账户
            this.webdavManager.editAccount(account).then(() => {
              ToastUtil.showToast('修改成功')
-             // 重新加载WebDAV账户列表
-             this.loadWebDavAccounts()
+             // 重新加载WebDAV账户列表,观察着模式去更新了,所以这里不需要更新,先注释掉
+             // this.loadWebDavAccounts()
              LogUtil.info('heanup NewIndex', 'WebDAV账户修改成功:', account.name)
            }).catch((error: Error) => {
              LogUtil.error('heanup NewIndex', `修改WebDAV账户失败: ${error.message}`)
@@ -1635,8 +1635,8 @@ struct NewIndex {
              account.enableHttps
            ).then(() => {
              ToastUtil.showToast('添加成功')
-             // 重新加载WebDAV账户列表
-             this.loadWebDavAccounts()
+             // 重新加载WebDAV账户列表 观察着模式去更新了,所以这里不需要更新,先注释掉
+             // this.loadWebDavAccounts()
              LogUtil.info('heanup NewIndex', 'WebDAV账户添加成功:', account.name)
            }).catch((error: Error) => {
              LogUtil.error('heanup NewIndex', `添加WebDAV账户失败: ${error.message}`)

+ 2 - 129
entry/src/main/ets/pages/WebDavMainPage.ets

@@ -113,6 +113,8 @@ export struct WebDavMainPage {
     // 加载账户列表
     this.loadAccounts();
 
+    this.loadFiles()
+
     // 订阅WebDAV状态变化
     this.webdavManager.subscribe(this.eventHandler);
   }
@@ -235,87 +237,7 @@ export struct WebDavMainPage {
     this.songs = [];
   }
 
-  // 显示添加账户对话框
-  private showAddAccountDialog(): void {
-    this.accountDialogController = new CustomDialogController({
-      builder: WebDavAccountDialog({
-        isEditMode: false,
-        account: new WebDavAccount(),
-        onConfirm: (account: WebDavAccount) => {
-          this.webdavManager.insertAccount(
-            account.name,
-            account.host,
-            account.localHost,
-            account.isUseLocalHost,
-            account.port,
-            account.filepath,
-            account.lyricFilePath,
-            account.uploadFilePath,
-            account.imageFilePath,
-            account.account,
-            account.password,
-            account.enableHttps
-          ).then(() => {
-            promptAction.showToast({ message: '添加成功' });
-          }).catch((error: Error) => {
-            Logger.error(TAG, '添加账户失败: ' + error.message);
-            promptAction.showToast({ message: '添加失败' });
-          });
-        }
-      }),
-      autoCancel: true,
-      customStyle: true
-    });
-    this.accountDialogController.open();
-  }
 
-  // 显示编辑账户对话框
-  private showEditAccountDialog(account: WebDavAccount): void {
-    this.accountDialogController = new CustomDialogController({
-      builder: WebDavAccountDialog({
-        isEditMode: true,
-        account: account,
-        onConfirm: (updatedAccount: WebDavAccount) => {
-          this.webdavManager.editAccount(updatedAccount)
-            .then(() => {
-              promptAction.showToast({ message: '更新成功' });
-            }).catch((error: Error) => {
-              Logger.error(TAG, '更新账户失败: ' + error.message);
-              promptAction.showToast({ message: '更新失败' });
-            });
-        }
-      }),
-      autoCancel: true,
-      customStyle: true
-    });
-    this.accountDialogController.open();
-  }
-
-  // 显示账户选择对话框
-  private showAccountSelectDialog(): void {
-    if (this.accounts.length === 0) {
-      promptAction.showToast({ message: '没有可用的账户' });
-      return;
-    }
-
-    // 构建按钮数组,至少1个,最多6个
-    const button1: promptAction.Button = { text: this.accounts[0].name, color: '#000000' };
-    const button2: promptAction.Button | undefined = this.accounts.length > 1 ? { text: this.accounts[1].name, color: '#000000' } : undefined;
-    const button3: promptAction.Button | undefined = this.accounts.length > 2 ? { text: this.accounts[2].name, color: '#000000' } : undefined;
-    const button4: promptAction.Button | undefined = this.accounts.length > 3 ? { text: this.accounts[3].name, color: '#000000' } : undefined;
-    const button5: promptAction.Button | undefined = this.accounts.length > 4 ? { text: this.accounts[4].name, color: '#000000' } : undefined;
-    const button6: promptAction.Button | undefined = this.accounts.length > 5 ? { text: this.accounts[5].name, color: '#000000' } : undefined;
-
-    promptAction.showActionMenu({
-      title: '选择账户',
-      buttons: [button1, button2, button3, button4, button5, button6]
-    }).then((result) => {
-      if (result.index >= 0 && result.index < this.accounts.length) {
-        this.switchAccount(this.accounts[result.index]);
-        promptAction.showToast({ message: '已切换到: ' + this.accounts[result.index].name });
-      }
-    });
-  }
 
   // 将Song转换为VideoItem
   private convertSongToVideoItem(song: Song, index: number): VideoItem {
@@ -469,12 +391,6 @@ export struct WebDavMainPage {
             .layoutWeight(1)
             .textAlign(TextAlign.Center)
 
-          // 添加账户按钮
-          Image($r('app.media.add'))
-            .width(24)
-            .height(24)
-            .margin({ right: 12 })
-            .onClick(() => this.showAddAccountDialog())
         }
         .height(48)
         .width('100%')
@@ -522,54 +438,11 @@ export struct WebDavMainPage {
   @Builder
   buildContentView() {
     Column() {
-      // 账户选择器
-      if (this.accounts.length > 0) {
-        Row() {
-          Text('当前账户:')
-            .fontSize(14)
-            .fontColor($r('app.color.index_tab_font_color'))
-            .margin({ right: 8 })
 
-          Text(this.selectedAccount?.name || '未选择')
-            .fontSize(14)
-            .fontColor(this.themeColor)
-            .layoutWeight(1)
-
-          Button('切换', { type: ButtonType.Normal, stateEffect: true })
-            .fontSize(12)
-            .padding({ left: 12, right: 12, top: 6, bottom: 6 })
-            .backgroundColor(this.themeColor)
-            .onClick(() => {
-              this.showAccountSelectDialog();
-            })
-
-          Button('编辑', { type: ButtonType.Normal, stateEffect: true })
-            .fontSize(12)
-            .padding({ left: 12, right: 12, top: 6, bottom: 6 })
-            .backgroundColor($r('app.color.input_background'))
-            .fontColor($r('app.color.index_tab_font_color'))
-            .margin({ left: 8 })
-            .onClick(() => {
-              if (this.selectedAccount) {
-                this.showEditAccountDialog(this.selectedAccount);
-              }
-            })
-        }
-        .width('100%')
-        .padding(12)
-        .backgroundColor($r('app.color.input_background'))
-        .borderRadius(8)
-        .margin({ left: 12, right: 12, top: 8 })
-      }
 
       // 加载按钮和面包屑导航
       Column({ space: 8 }) {
         Row({ space: 12 }) {
-          Button('加载文件列表', { type: ButtonType.Capsule, stateEffect: true })
-            .layoutWeight(1)
-            .backgroundColor(this.themeColor)
-            .enabled(!this.isLoading)
-            .onClick(() => this.loadFiles())
 
           // 返回上级按钮
           if (this.webdavManager.canGoBack()) {