Quellcode durchsuchen

初步实现歌曲听歌次数统计功能

onecold vor 11 Monaten
Ursprung
Commit
c86df16de2

+ 30 - 0
entry/src/main/ets/common/util/MediaTable.ets

@@ -624,6 +624,36 @@ export default class MediaTable {
   }
 
 
+  /**
+   * 查询播放次数大于0的记录,并按播放次数降序排列
+   * @param limitCount 限制返回的记录数量,0表示返回全部
+   * @param callback 回调函数,返回VideoItem数组
+   */
+  public queryByPlayCountDesc(limitCount: number = 0, callback: (result: VideoItem[]) => void): void {
+    try {
+      // 1. 构建查询条件:playCount > 0,按playCount降序排列
+      const predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
+      predicates.greaterThan('playCount',  0);  // 播放次数大于0
+      predicates.orderByDesc('playCount');      // 按播放次数降序排列
+
+      // 只有当limitCount大于0时才设置限制
+      if (limitCount > 0) {
+        predicates.limitAs(limitCount);
+      }
+
+      // 2. 执行查询
+      this.accountTable.query(predicates,  (resultSet: relationalStore.ResultSet) => {
+        // 3. 解析结果集
+        const result = this.parseResultSetToVideoItems(resultSet);
+        callback(result);
+      });
+    } catch (err) {
+      Logger.error(`queryByPlayCountDesc  error: ${err.code}  - ${err.message}`);
+      callback([]);  // 发生错误时返回空数组
+    }
+  }
+
+
 
 }
 

+ 14 - 11
entry/src/main/ets/pages/NewIndex.ets

@@ -38,6 +38,7 @@ import { UpdateLogManager } from '../common/util/UpdateLogManager';
 import OnlineUpdateLogDialog from '../dialog/OnlineUpdateLog';
 import OnlineUpdateLog from '../dialog/OnlineUpdateLog';
 import { LocalMusic } from '../view/LocalMusic';
+import { ChartsCount } from './ChartsCount';
 
 // import { FFmpeg, FFProgressMessageParser } from '@sj/ffmpeg';
 
@@ -294,10 +295,14 @@ struct NewIndex {
             .visibility(this.mType === 1 ? Visibility.Visible : Visibility.None)
           ScanFilePage()
             .visibility(this.mType === 2 ? Visibility.Visible : Visibility.None)
-          SettingPage()
+
+          ChartsCount({isShowDrawer:this.isShowDrawer})
             .visibility(this.mType === 3 ? Visibility.Visible : Visibility.None)
-          AboutPage()
+
+          SettingPage()
             .visibility(this.mType === 4 ? Visibility.Visible : Visibility.None)
+          AboutPage()
+            .visibility(this.mType === 5 ? Visibility.Visible : Visibility.None)
           
           // 抽屉打开时的遮罩层,用于拦截点击事件  这个只能正常尺寸的手机竖屏的才能生效
           if (this.isShowDrawer&&this.isPhonePortrait()) {
@@ -624,13 +629,11 @@ struct NewIndex {
                   this.mType = 2
                   this.doShowDrawer()
                   break
-                // case MainViewModel.MENU_HOME:
-                //   this.mType = 0
-                //   this.modeType = 0
-                //   this.getUIContext()?.animateTo({ duration: 555 }, () => {
-                //     this.isShowDrawer = false
-                //   })
-                //   break
+                case MainViewModel.MENU_CHARTS:
+                  this.mType = 3
+                  this.modeType = 0
+                  this.doShowDrawer()
+                  break
                 case MainViewModel.MENU_MIEDIA_KU:
                   this.modeType = 1
                   this.mType = 0
@@ -647,7 +650,7 @@ struct NewIndex {
                   this.doShowDrawer()
                   break
                 case MainViewModel.MENU_SETTING:
-                  this.mType = 3
+                  this.mType = 4
                   this.doShowDrawer()
 
                   break
@@ -681,7 +684,7 @@ struct NewIndex {
                   break
 
                 case MainViewModel.MENU_ABOUT:
-                  this.mType = 4
+                  this.mType = 5
                   this.doShowDrawer()
                   break
                 case MainViewModel.MENU_UPDATE:

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

@@ -9485,7 +9485,7 @@ export struct LocalMusic {
 
     { id: 9, image: $r('app.media.volume_white'), title: '调整音量' },
 
-    { id: 6, image: $r('app.media.memory'), title: '记忆播放' },
+    // { id: 6, image: $r('app.media.memory'), title: '记忆播放' },
 
 
     { id: 13, image: $r('app.media.rectangle'), title: '封面方形' },

+ 6 - 0
entry/src/main/ets/viewmodel/MainViewModel.ets

@@ -43,6 +43,7 @@ export  class  MainViewModel{
   static readonly MENU_MIEDIA_ALBUM: number = 230;
   static readonly MENU_FILE_SCAN: number = 231;
   static readonly MENU_SHARE: number = 232;
+  static readonly MENU_CHARTS: number = 233;
   //测滑菜单的数据
   getDrawerData(): Array<ItemData> {
     let drawerGridData: ItemData[] = [
@@ -53,6 +54,9 @@ export  class  MainViewModel{
       new ItemData($r('app.string.album'), $r('app.media.llq'),MainViewModel.MENU_MIEDIA_ALBUM,false),
       new ItemData($r('app.string.user_center'), { type: 'symbol', value: $r('sys.symbol.person') }, MainViewModel.MENU_USER, false),
       new ItemData($r('app.string.file_scan'), { type: 'symbol', value: $r('sys.symbol.doc_text_badge_magnifyingglass') },MainViewModel.MENU_FILE_SCAN,false),
+
+      new ItemData($r('app.string.music_charts'), { type: 'symbol', value: $r('sys.symbol.doc_plaintext') },MainViewModel.MENU_CHARTS,false),
+
       new ItemData($r('app.string.setting'),  { type: 'symbol', value: $r('sys.symbol.gearshape') },MainViewModel.MENU_SETTING,false),
       new ItemData($r('app.string.about_me'), { type: 'symbol', value: $r('sys.symbol.info_shield') },MainViewModel.MENU_ABOUT,false),
       new ItemData($r('app.string.haoping'), { type: 'symbol', value: $r('sys.symbol.flower') },MainViewModel.MENU_HAOPING,false),
@@ -69,6 +73,8 @@ export  class  MainViewModel{
       new ItemData($r('app.string.local_music'), { type: 'symbol', value: $r('sys.symbol.music') }, MainViewModel.MENU_MUSIC, false),
       new ItemData($r('app.string.user_center'), { type: 'symbol', value: $r('sys.symbol.person') }, MainViewModel.MENU_USER, false),
       new ItemData($r('app.string.file_scan'), { type: 'symbol', value: $r('sys.symbol.doc_text_badge_magnifyingglass') },MainViewModel.MENU_FILE_SCAN,false),
+      new ItemData($r('app.string.music_charts'), { type: 'symbol', value: $r('sys.symbol.doc_plaintext') },MainViewModel.MENU_CHARTS,false),
+
       new ItemData($r('app.string.setting'),  { type: 'symbol', value: $r('sys.symbol.gearshape') },MainViewModel.MENU_SETTING,false),
       new ItemData($r('app.string.about_me'), { type: 'symbol', value: $r('sys.symbol.info_shield') },MainViewModel.MENU_ABOUT,false),
       // new ItemData($r('app.string.vip'), { type: 'symbol', value: $r('sys.symbol.vip_hand') }, MainViewModel.MENU_VIP, false),

+ 4 - 0
entry/src/main/resources/base/element/string.json

@@ -463,6 +463,10 @@
     {
       "name": "select_all",
       "value": "多选"
+    },
+    {
+      "name": "music_charts",
+      "value": "歌曲统计"
     }
   ]
 }