Quellcode durchsuchen

分页加载音乐数据

jsonwang vor 3 Jahren
Ursprung
Commit
aa5b0dd33a
1 geänderte Dateien mit 20 neuen und 5 gelöschten Zeilen
  1. 20 5
      BFFramework/Classes/Stuckpoint/View/PQSelecteMusicView.swift

+ 20 - 5
BFFramework/Classes/Stuckpoint/View/PQSelecteMusicView.swift

@@ -26,6 +26,8 @@ class PQSelecteMusicView: UIView {
     
     // 点击播放一个歌,回调
     var didSelectItemHandle:((_ isPlaying:Bool) -> Void)?
+    // 当前选择的分类
+    var currentSelectTag:PQStuckPointMusicTagsModel?
  
     lazy var avPlayer: AVPlayer = {
         let avPlayer = AVPlayer()
@@ -159,15 +161,17 @@ class PQSelecteMusicView: UIView {
     func requestPageListData(isRefresh: Bool = true, isHotPage _: Bool = false, tagId: Int64) {
         if isRefresh {
             pageNum = 1
+            musicDatas = []
         }
         PQStuckPointViewModel.stuckPointMusicPageList(tagId: tagId, pageNum: pageNum, videoCount: 0, imageCount: 0, totalDuration: 0) { [weak self] musicInfo, _ in
-
+            BFLog(message: "请求音乐列表 pageNum\(String(describing: self?.pageNum)) tagId \(tagId) 返回条数\(musicInfo.count)")
             if musicInfo.count > 0 {
                 self?.pageNum = (self?.pageNum ?? 0) + 1
+                
+                self?.musicDatas = self!.musicDatas + musicInfo
+                self?.selectMusicCollection.reloadData()
             }
 
-            self?.musicDatas = musicInfo
-            self?.selectMusicCollection.reloadData()
         }
     }
     
@@ -263,7 +267,12 @@ extension PQSelecteMusicView: UICollectionViewDelegate, UICollectionViewDataSour
                     
                 }
             }
-         
+            
+            //自动请求下一页数据
+            if(indexPath.row == musicDatas.count - 5){
+                // 请求这个分类的歌单
+                requestPageListData(isRefresh: false, tagId:   currentSelectTag?.tagId ?? 0)
+            }
             return cell
         }
         let itemData: Any = catageryDatas[indexPath.item]
@@ -310,11 +319,17 @@ extension PQSelecteMusicView: UICollectionViewDelegate, UICollectionViewDataSour
             }
             catageryDatas[indexPath.item].isSelected = true
             categoryCollection.reloadData()
+            currentSelectTag = catageryDatas[indexPath.item]
+            // 请求这个分类的歌单
+            requestPageListData(isRefresh: true, tagId:   currentSelectTag?.tagId ?? 0)
         }
    
     }
 
-    func collectionView(_: UICollectionView, willDisplay _: UICollectionViewCell, forItemAt indexPath: IndexPath) {}
+    func collectionView(_: UICollectionView, willDisplay _: UICollectionViewCell, forItemAt indexPath: IndexPath) {
+        
+        
+    }
 }
 
 // 分类 cell