Bläddra i källkod

增加字段webType

onecold 9 månader sedan
förälder
incheckning
215ee5d793

+ 24 - 5
entry/src/main/ets/common/util/WebdavManager.ets

@@ -159,6 +159,7 @@ export class WebdavManager {
         account.password = resultSet.getString(resultSet.getColumnIndex('password'));
         account.enableHttps = resultSet.getLong(resultSet.getColumnIndex('enableHttps')) === 1;
         account.coverPath = resultSet.getString(resultSet.getColumnIndex('coverPath'));
+        account.webType = resultSet.getLong(resultSet.getColumnIndex('webType'));
         account.isActivate = resultSet.getLong(resultSet.getColumnIndex('isActivate')) === 1;
 
         resultSet.close();
@@ -375,6 +376,7 @@ export class WebdavManager {
         account.password = resultSet.getString(resultSet.getColumnIndex('password'));
         account.enableHttps = resultSet.getLong(resultSet.getColumnIndex('enableHttps')) === 1;
         account.coverPath = resultSet.getString(resultSet.getColumnIndex('coverPath'));
+        account.webType = resultSet.getLong(resultSet.getColumnIndex('webType'));
         account.isActivate = resultSet.getLong(resultSet.getColumnIndex('isActivate')) === 1;
 
         resultSet.close();
@@ -407,7 +409,8 @@ export class WebdavManager {
       account TEXT,
       password TEXT,
       enableHttps INTEGER DEFAULT 0,
-      coverPath TEXT
+      coverPath TEXT,
+      webType INTEGER DEFAULT 0
     )`;
 
     return this.dataBaseUtil.executeSql(createTableSql)
@@ -436,6 +439,18 @@ export class WebdavManager {
       // 如果添加字段失败(可能字段已存在),记录但不阻止应用启动
       Logger.info(TAG, 'coverPath字段可能已存在或添加失败,继续正常运行');
     }
+    
+    try {
+      // 添加webType字段,用于标识WebDAV账户类型
+      Logger.info(TAG, '检查数据库表结构,尝试添加webType字段...');
+      const addWebTypeColumnSql = `ALTER TABLE ${this.webDavTable} ADD COLUMN webType INTEGER DEFAULT 0`;
+
+      await this.dataBaseUtil.executeSql(addWebTypeColumnSql);
+      Logger.info(TAG, 'webType字段添加成功,数据库升级完成');
+    } catch (error) {
+      // 如果添加字段失败(可能字段已存在),记录但不阻止应用启动
+      Logger.info(TAG, 'webType字段可能已存在或添加失败,继续正常运行');
+    }
   }
 
   // 从数据库查询所有账户
@@ -469,8 +484,9 @@ export class WebdavManager {
         account.account = resultSet.getString(resultSet.getColumnIndex('account'));
         account.password = resultSet.getString(resultSet.getColumnIndex('password'));
         account.enableHttps = resultSet.getLong(resultSet.getColumnIndex('enableHttps')) === 1;
-        // 设置coverPath为默认值undefined,稍后会尝试更新
+        // 设置coverPath和webType为默认值undefined,稍后会尝试更新
         account.coverPath = undefined;
+        account.webType = 0;
 
         this.webDavAccounts.push(account);
       }
@@ -528,7 +544,8 @@ export class WebdavManager {
     account: string,
     password: string,
     enableHttps: boolean,
-    coverPath?: string
+    coverPath?: string,
+    webType: number = 0
   ): Promise<void> {
     try {
       const values: relationalStore.ValuesBucket = {
@@ -545,7 +562,8 @@ export class WebdavManager {
         'account': account,
         'password': password,
         'enableHttps': enableHttps ? 1 : 0,
-        'coverPath': coverPath || null
+        'coverPath': coverPath || null,
+        'webType': webType
       };
 
       await this.dataBaseUtil.insertData(this.webDavTable, values);
@@ -578,7 +596,8 @@ export class WebdavManager {
         'account': account.account,
         'password': account.password,
         'enableHttps': account.enableHttps ? 1 : 0,
-        'coverPath': account.coverPath || null
+        'coverPath': account.coverPath || null,
+        'webType': account.webType
       };
 
       const predicates = new relationalStore.RdbPredicates(this.webDavTable);

+ 6 - 2
entry/src/main/ets/dialog/WebDavAccountDialog.ets

@@ -1,4 +1,4 @@
-import { ToastUtil } from '@pura/harmony-utils';
+import { StrUtil, ToastUtil } from '@pura/harmony-utils';
 import { CommonConstants } from '../common/constants/CommonConstants';
 import { WebDavAccount } from '../viewmodel/WebDavAccount';
 import { ImagePickerUtil } from '../common/util/ImagePickerUtil';
@@ -189,7 +189,11 @@ export struct WebDavAccountDialog {
           .maxLines(1)
           .type(InputType.Number)
           .onChange((value: string) => {
-            this.port = parseInt(value) || 80;
+            if(this.enableHttps){
+              this.port = parseInt(value) || 443;
+            }else{
+              this.port = parseInt(value) || 80;
+            }
           });
       }
       .alignItems(VerticalAlign.Center);

+ 51 - 23
entry/src/main/ets/pages/NewIndex.ets

@@ -675,41 +675,65 @@ struct NewIndex {
       .fontColor($r('app.color.text_color'))
       .align(Alignment.Start)
   }
-
+  @State ratioL: number = 1;
+  @State isRefreshing: boolean = false;
+  @State maxRefreshingHeight: number = 100.0;
+  private contentNode?: ComponentContent<Object> = undefined;
   /**
    * 动态生成抽屉菜单内容
    * 根据 isShowSponsorship 展示不同菜单项
    */
   @Builder
   getDrawerView() {
+    Refresh({ refreshing: $$this.isRefreshing, refreshingContent: this.contentNode }) {
+      List({ space: 0, scroller: this.scroller }) {
+        ListItemGroup({ header: this.buildUserInfoCard() }) {
+          if(this.tabSelectedIndexes[0]==0){//分类
+            this.buildTabCate()
+          }else if(this.tabSelectedIndexes[0]==1){//歌单
+            this.buildPlaylistTab()
+          }else if(this.tabSelectedIndexes[0]==2){//网盘
+            this.buildCloudStorageTab()
+          }
 
-    List({ space: 0, scroller: this.scroller }) {
-      ListItemGroup({ header: this.buildUserInfoCard() }) {
-        if(this.tabSelectedIndexes[0]==0){//分类
-          this.buildTabCate()
-        }else if(this.tabSelectedIndexes[0]==1){//歌单
-          this.buildPlaylistTab()
-        }else if(this.tabSelectedIndexes[0]==2){//网盘
-          this.buildCloudStorageTab()
         }
 
       }
+      .scrollBar(BarState.Off)
+      .width('86%')
+      .borderRadius(20)
+      .margin({
+        bottom: 20,
+        left: 10,
+        right: 10,
+        top: 10
+      })
+      .alignListItem(ListItemAlign.Center)
+      .layoutWeight(1)
+      .backgroundColor($r('app.color.left_draw_bg'))
 
+      .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
     }
-    .scrollBar(BarState.Off)
-    .width('86%')
-    .borderRadius(20)
-    .margin({
-      bottom: 20,
-      left: 10,
-      right: 10,
-      top: 10
+    .pullDownRatio(this.ratioL)
+    .pullToRefresh(true)
+    .refreshOffset(0)
+    .onOffsetChange((offset: number) => {
+      // 越接近最大距离,下拉跟手系数越小。
+      this.ratioL = 1 - Math.pow((offset / this.maxRefreshingHeight), 3);
+    })
+    .onStateChange((refreshStatus: RefreshStatus) => {
+      console.info('onecold Refresh onStatueChange state is ' + refreshStatus);
+    })
+    .onRefreshing(async () => {
+      if(this.tabSelectedIndexes[0]==0){//分类
+        this.isRefreshing = false
+      }else if(this.tabSelectedIndexes[0]==1){//歌单
+        this.loadPlaylistList()
+      }else if(this.tabSelectedIndexes[0]==2){//网盘
+        this.loadWebDavAccounts()
+      }
     })
-    .alignListItem(ListItemAlign.Center)
-    .layoutWeight(1)
-    .backgroundColor($r('app.color.left_draw_bg'))
 
-    .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
   }
 
 
@@ -1214,8 +1238,8 @@ struct NewIndex {
             // 账户封面或默认图标
             Stack() {
               Image(account.coverPath?account.coverPath:$r('app.media.cloudDisk'))
-                  .width(20)
-                  .height(20)
+                  .width(25)
+                  .height(25)
                   .borderRadius(4)
                   .fillColor(this.themeColor)
                   .objectFit(ImageFit.Cover)
@@ -1500,8 +1524,10 @@ struct NewIndex {
       } else {
         LogUtil.warn('heanup NewIndex', '歌单表未初始化')
       }
+      this.isRefreshing = false
     } catch (error) {
       LogUtil.error('heanup NewIndex', `加载歌单列表失败: ${(error as Error).message}`)
+      this.isRefreshing = false
     }
   }
 
@@ -1542,8 +1568,10 @@ struct NewIndex {
       await this.webdavManager.queryWebDavAccountsFromDB()
       // 强制触发UI更新
       this.webDavAccounts = this.webdavManager.getAllWebDavAccounts().slice()
+      this.isRefreshing = false
       LogUtil.info('heanup NewIndex', `成功加载 ${this.webDavAccounts.length} 个WebDAV账户`)
     } catch (error) {
+      this.isRefreshing = false
       LogUtil.error('heanup NewIndex', `加载WebDAV账户列表失败: ${(error as Error).message}`)
     }
   }

+ 3 - 1
entry/src/main/ets/pages/WebDavMainPage.ets

@@ -498,9 +498,11 @@ export struct WebDavMainPage {
         if (this.webdavManager.currentPath !== '') {
           Row({ space: 8 }) {
             Button({ type: ButtonType.Circle }) {
-              Image(this.webdavManager.canGoBack()?$r('app.media.back'):$r('app.media.cloudDisk'))
+              Image(this.webdavManager.canGoBack()?$r('app.media.back'):this.selectedAccount.coverPath)
                 .width(15)
                 .height(15)
+                .borderRadius(10)
+                .alt($r('app.media.cloudDisk'))
                 .fillColor(Color.White)
             }
             .width(20)

+ 20 - 18
entry/src/main/ets/view/DeleteComptent.ets

@@ -220,24 +220,6 @@ async function deleteMultipleFiles(
 
 
       } else {
-        // 先从所有歌单中移除这首歌(如果存在的话)
-        LogUtil.info('heanup DeleteComptent', `准备从歌单中移除歌曲: ${item.name}, filePath: ${item.filePath}`);
-        if (item.filePath) {
-          try {
-            const affectedPlaylists = await playlistTable.removeSongFromAllPlaylists(item.filePath);
-            LogUtil.info('heanup DeleteComptent', `removeSongFromAllPlaylists 返回了 ${affectedPlaylists.length} 个受影响的歌单`);
-            if (affectedPlaylists.length > 0) {
-              hasPlaylistChanges = true;
-              LogUtil.info('heanup DeleteComptent', `歌曲已从 ${affectedPlaylists.length} 个歌单中移除: ${item.name}`);
-            } else {
-              LogUtil.info('heanup DeleteComptent', `歌曲不在任何歌单中: ${item.name}`);
-            }
-          } catch (error) {
-            LogUtil.error('heanup DeleteComptent', `从歌单移除歌曲失败: ${(error as Error).message}`);
-          }
-        } else {
-          LogUtil.warn('heanup DeleteComptent', `歌曲 ${item.name} 的 filePath 为空`);
-        }
 
         table.deleteData(item, async () => {
           if(isDeleteYuan){
@@ -267,6 +249,26 @@ async function deleteMultipleFiles(
 
 
         });
+        // 先从所有歌单中移除这首歌(如果存在的话)
+        LogUtil.info('heanup DeleteComptent', `准备从歌单中移除歌曲: ${item.name}, filePath: ${item.filePath}`);
+        if (item.filePath) {
+          try {
+            const affectedPlaylists = await playlistTable.removeSongFromAllPlaylists(item.filePath);
+            LogUtil.info('heanup DeleteComptent', `removeSongFromAllPlaylists 返回了 ${affectedPlaylists.length} 个受影响的歌单`);
+            if (affectedPlaylists.length > 0) {
+              hasPlaylistChanges = true;
+              LogUtil.info('heanup DeleteComptent', `歌曲已从 ${affectedPlaylists.length} 个歌单中移除: ${item.name}`);
+            } else {
+              LogUtil.info('heanup DeleteComptent', `歌曲不在任何歌单中: ${item.name}`);
+            }
+          } catch (error) {
+            LogUtil.error('heanup DeleteComptent', `从歌单移除歌曲失败: ${(error as Error).message}`);
+          }
+        } else {
+          LogUtil.warn('heanup DeleteComptent', `歌曲 ${item.name} 的 filePath 为空`);
+        }
+
+
 
 
       }

+ 3 - 3
entry/src/main/ets/view/LocalMusic.ets

@@ -2425,7 +2425,7 @@ export struct LocalMusic {
                   emptyView(this.themeColor)
 
                 }
-                .position({ top:this.isShowCoverHeader() ? 260 : 180 })
+                .position({ top:this.isShowCoverHeader() ? 300 : 180 })
                 .transition(TransitionEffect.asymmetric(TransitionEffect.scale({ x: 1.2, y: 1.2 })
                   .animation({ duration: 500 }),
                   TransitionEffect.scale({ x: 0, y: 0 })))
@@ -9536,7 +9536,7 @@ export struct LocalMusic {
   @Builder
   private musicNameInfo(isHidden: boolean) {
     Column({ space: 8 }) {
-      Text(this.name)
+      Text(this.isShowFileName&&this.currentSong?this.currentSong.fileName :this.name)
         .fontSize(this.name.length >= 28 || this.isCoverOpacity() ? 18 : 22)
         .fontWeight(FontWeight.Bold)
         .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
@@ -9549,7 +9549,7 @@ export struct LocalMusic {
         .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
         .fontColor(Color.White)
         .textAlign(TextAlign.Center)
-        .visibility(StrUtil.isEmpty(this.artist)?Visibility.None:Visibility.Visible)
+        .visibility(StrUtil.isEmpty(this.artist)||this.isShowFileName?Visibility.None:Visibility.Visible)
         .width('99%')
         .maxLines(1)
     }

+ 1 - 0
entry/src/main/ets/viewmodel/WebDavAccount.ets

@@ -23,6 +23,7 @@ export class WebDavAccount{
   public imageFilePaths: string[] = []
   // 自定义封面路径
   public coverPath?: string
+  public webType : number = 0
 
   public setIsUseLocalHost(isuse: boolean){
     this.isUseLocalHost = isuse