完善睡眠页面
authorliangzhenying <867174124@qq.com>
Thu, 9 Oct 2025 10:16:24 +0000 (18:16 +0800)
committerliangzhenying <867174124@qq.com>
Thu, 9 Oct 2025 10:16:24 +0000 (18:16 +0800)
26 files changed:
ShenYin/ShenYin/Api/HttpClient2.swift
ShenYin/ShenYin/Assets.xcassets/logo.imageset/Contents.json [new file with mode: 0644]
ShenYin/ShenYin/Assets.xcassets/logo.imageset/logo.png [new file with mode: 0644]
ShenYin/ShenYin/Assets.xcassets/mine/arrow_back_white.imageset/Contents.json [new file with mode: 0644]
ShenYin/ShenYin/Assets.xcassets/mine/arrow_back_white.imageset/Frame 1985@2x.png [new file with mode: 0644]
ShenYin/ShenYin/Assets.xcassets/mine/arrow_back_white.imageset/Frame 1985@3x.png [new file with mode: 0644]
ShenYin/ShenYin/Assets.xcassets/sleep/music_pause.imageset/Contents.json [new file with mode: 0644]
ShenYin/ShenYin/Assets.xcassets/sleep/music_pause.imageset/Frame@2x.png [new file with mode: 0644]
ShenYin/ShenYin/Assets.xcassets/sleep/music_pause.imageset/Frame@3x.png [new file with mode: 0644]
ShenYin/ShenYin/Assets.xcassets/sleep/music_play.imageset/Contents.json [new file with mode: 0644]
ShenYin/ShenYin/Assets.xcassets/sleep/music_play.imageset/Frame@2x.png [new file with mode: 0644]
ShenYin/ShenYin/Assets.xcassets/sleep/music_play.imageset/Frame@3x.png [new file with mode: 0644]
ShenYin/ShenYin/Tools/Extensions/UIImage+Develop.swift
ShenYin/ShenYin/Tools/YLTools.swift
ShenYin/ShenYin/UI/Base/BaseTC.swift
ShenYin/ShenYin/UI/Base/BaseView.swift
ShenYin/ShenYin/UI/Launch/AppLaunch.swift
ShenYin/ShenYin/UI/Launch/SceneDelegate.swift
ShenYin/ShenYin/UI/Sleep/AudioPlayerManager.swift [new file with mode: 0644]
ShenYin/ShenYin/UI/Sleep/AudioPlayerVC.swift [new file with mode: 0644]
ShenYin/ShenYin/UI/Sleep/MusicModel.swift [new file with mode: 0644]
ShenYin/ShenYin/UI/Sleep/SleepCell.swift
ShenYin/ShenYin/UI/Sleep/SleepListView.swift
ShenYin/ShenYin/UI/Sleep/SleepPageVC.swift [deleted file]
ShenYin/ShenYin/UI/Sleep/SleepVC.swift
ShenYin/ShenYin/UI/Sleep/SleepVM.swift

index 6719e79..49477c7 100644 (file)
@@ -45,7 +45,9 @@ enum CommomApi
     /// 获取音乐分类
     case musicCategory
     /// 获取音乐列表
-    case muiscCategoryList(categoryId:String,page:Int)
+    case musicCategoryList(categoryId:String,page:Int)
+    /// 获取音乐地址
+    case musicUrl(filedId:String)
 }
 
 // 实现TargetType协议
@@ -90,9 +92,10 @@ extension CommomApi{
             return "/res/voice-file/storage-size"
         case .musicCategory:
             return "/res/music-category/list"
-        case .muiscCategoryList(let categoryId,let page):
+        case .musicCategoryList(let categoryId,let page):
             return "/res/sleep-music/list/\(page)?categoryId=\(categoryId)"
-            
+        case .musicUrl( let id):
+            return "/res/voice-file/play/\(id)"
         }
     }
     
diff --git a/ShenYin/ShenYin/Assets.xcassets/logo.imageset/Contents.json b/ShenYin/ShenYin/Assets.xcassets/logo.imageset/Contents.json
new file mode 100644 (file)
index 0000000..5f670ca
--- /dev/null
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "logo.png",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
diff --git a/ShenYin/ShenYin/Assets.xcassets/logo.imageset/logo.png b/ShenYin/ShenYin/Assets.xcassets/logo.imageset/logo.png
new file mode 100644 (file)
index 0000000..2bc9514
Binary files /dev/null and b/ShenYin/ShenYin/Assets.xcassets/logo.imageset/logo.png differ
diff --git a/ShenYin/ShenYin/Assets.xcassets/mine/arrow_back_white.imageset/Contents.json b/ShenYin/ShenYin/Assets.xcassets/mine/arrow_back_white.imageset/Contents.json
new file mode 100644 (file)
index 0000000..d12af74
--- /dev/null
@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "Frame 1985@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "Frame 1985@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
diff --git a/ShenYin/ShenYin/Assets.xcassets/mine/arrow_back_white.imageset/Frame 1985@2x.png b/ShenYin/ShenYin/Assets.xcassets/mine/arrow_back_white.imageset/Frame 1985@2x.png
new file mode 100644 (file)
index 0000000..8d18a47
Binary files /dev/null and b/ShenYin/ShenYin/Assets.xcassets/mine/arrow_back_white.imageset/Frame 1985@2x.png differ
diff --git a/ShenYin/ShenYin/Assets.xcassets/mine/arrow_back_white.imageset/Frame 1985@3x.png b/ShenYin/ShenYin/Assets.xcassets/mine/arrow_back_white.imageset/Frame 1985@3x.png
new file mode 100644 (file)
index 0000000..bd0131b
Binary files /dev/null and b/ShenYin/ShenYin/Assets.xcassets/mine/arrow_back_white.imageset/Frame 1985@3x.png differ
diff --git a/ShenYin/ShenYin/Assets.xcassets/sleep/music_pause.imageset/Contents.json b/ShenYin/ShenYin/Assets.xcassets/sleep/music_pause.imageset/Contents.json
new file mode 100644 (file)
index 0000000..5c4d3b1
--- /dev/null
@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "Frame@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "Frame@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
diff --git a/ShenYin/ShenYin/Assets.xcassets/sleep/music_pause.imageset/Frame@2x.png b/ShenYin/ShenYin/Assets.xcassets/sleep/music_pause.imageset/Frame@2x.png
new file mode 100644 (file)
index 0000000..3cd60ad
Binary files /dev/null and b/ShenYin/ShenYin/Assets.xcassets/sleep/music_pause.imageset/Frame@2x.png differ
diff --git a/ShenYin/ShenYin/Assets.xcassets/sleep/music_pause.imageset/Frame@3x.png b/ShenYin/ShenYin/Assets.xcassets/sleep/music_pause.imageset/Frame@3x.png
new file mode 100644 (file)
index 0000000..1db7e59
Binary files /dev/null and b/ShenYin/ShenYin/Assets.xcassets/sleep/music_pause.imageset/Frame@3x.png differ
diff --git a/ShenYin/ShenYin/Assets.xcassets/sleep/music_play.imageset/Contents.json b/ShenYin/ShenYin/Assets.xcassets/sleep/music_play.imageset/Contents.json
new file mode 100644 (file)
index 0000000..5c4d3b1
--- /dev/null
@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "filename" : "Frame@2x.png",
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "filename" : "Frame@3x.png",
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
diff --git a/ShenYin/ShenYin/Assets.xcassets/sleep/music_play.imageset/Frame@2x.png b/ShenYin/ShenYin/Assets.xcassets/sleep/music_play.imageset/Frame@2x.png
new file mode 100644 (file)
index 0000000..6c10f00
Binary files /dev/null and b/ShenYin/ShenYin/Assets.xcassets/sleep/music_play.imageset/Frame@2x.png differ
diff --git a/ShenYin/ShenYin/Assets.xcassets/sleep/music_play.imageset/Frame@3x.png b/ShenYin/ShenYin/Assets.xcassets/sleep/music_play.imageset/Frame@3x.png
new file mode 100644 (file)
index 0000000..460e575
Binary files /dev/null and b/ShenYin/ShenYin/Assets.xcassets/sleep/music_play.imageset/Frame@3x.png differ
index ff013a1..d64deb2 100644 (file)
@@ -129,6 +129,35 @@ public extension YCDevelop where Base: UIImage {
     }
 }
 
+
+extension UIColor {
+    func image(with size: CGSize = CGSize(width: 1, height: 1)) -> UIImage? {
+        UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale)
+        defer {
+            UIGraphicsEndImageContext()
+        }
+        let context = UIGraphicsGetCurrentContext()
+        context?.setFillColor(self.cgColor)
+        context?.fill(CGRect(origin:.zero, size: size))
+        return UIGraphicsGetImageFromCurrentImageContext()
+    }
+    func imageCircle(with size: CGSize = CGSize(width: 1, height: 1)) -> UIImage? {
+        UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale)
+        defer {
+            UIGraphicsEndImageContext()
+        }
+        let context = UIGraphicsGetCurrentContext()
+        let rect = CGRect(origin:.zero, size: size)
+        // 创建圆形路径
+        let circularPath = UIBezierPath(ovalIn: rect)
+        context?.addPath(circularPath.cgPath)
+        context?.clip()
+        context?.setFillColor(self.cgColor)
+        context?.fill(rect)
+        return UIGraphicsGetImageFromCurrentImageContext()
+    }
+}
+
 // MARK: - ********* 压缩图片
 public extension YCDevelop where Base: UIImage {
     
index 03dacb5..6a22c20 100644 (file)
@@ -13,4 +13,9 @@ class YLToos {
         let seconds = totalSeconds % 60
         return String(format: "%02d:%02d:%02d", hours, minutes, seconds)
     }
+    static func formatSeconds1(_ totalSeconds: Int) -> String {
+        let minutes = (totalSeconds) / 60
+        let seconds = totalSeconds % 60
+        return String(format: "%02d:%02d", minutes, seconds)
+    }
 }
index 06eddf7..383c318 100644 (file)
@@ -55,6 +55,6 @@ class BaseTC:UITabBarController{
         self.tabBar.backgroundColor = .white
         view.backgroundColor = .color(.bgColor)
 
-        self.selectedIndex = 0
+        self.selectedIndex = 2
     }
 }
index 643eb55..e650d19 100644 (file)
@@ -13,6 +13,7 @@ class BaseView: UIView {
         super.init(frame: frame)
         setupViews()
         setupLayout()
+        setupData()
     }
     
     required init?(coder: NSCoder) {
@@ -24,5 +25,8 @@ class BaseView: UIView {
     }
     func setupLayout(){
         
+    }
+    func setupData(){
+        
     }
 }
index 635358a..de4a113 100644 (file)
@@ -7,12 +7,16 @@
 
 import UIKit
 import IQKeyboardManagerSwift
-
+import netfox
 class AppLaunch:NSObject{
     @MainActor static func start(){
+        NFX.sharedInstance().start()
+        
         JoySdkManager.shared.setupSdk()
         setupKeyboard()
         loadCache()
+        
+        
     }
     
     @MainActor static func setupKeyboard(){
index fa3008b..f6032c7 100644 (file)
@@ -18,7 +18,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
         
         App.shared.window = window
         window?.rootViewController = BaseTC()
-        window?.rootViewController = UINavigationController(rootViewController: LoginVC())
+//        window?.rootViewController = UINavigationController(rootViewController: AudioPlayerVC())
         AppLaunch.start()
     }
 
diff --git a/ShenYin/ShenYin/UI/Sleep/AudioPlayerManager.swift b/ShenYin/ShenYin/UI/Sleep/AudioPlayerManager.swift
new file mode 100644 (file)
index 0000000..74225cc
--- /dev/null
@@ -0,0 +1,29 @@
+//
+//  AudioPlayer.swift
+//  ShenYin
+//
+//  Created by liangshi on 2025/10/9.
+//
+
+import AVFoundation
+
+class AudioPlayerManager {
+    var player: AVPlayer?
+    var playerItem: AVPlayerItem?
+    
+    func play(url: URL) {
+        playerItem = AVPlayerItem(url: url)
+        player = AVPlayer(playerItem: playerItem)
+        player?.play()
+    }
+    
+    func pause() {
+        player?.pause()
+    }
+    
+    func setProgress(_ progress: Float) {
+        let duration = CMTimeGetSeconds((player?.currentItem?.duration)!)
+        let seekTime = CMTimeMakeWithSeconds(Float64(progress) * duration, preferredTimescale: 1)
+        player?.seek(to: seekTime)
+    }
+}
diff --git a/ShenYin/ShenYin/UI/Sleep/AudioPlayerVC.swift b/ShenYin/ShenYin/UI/Sleep/AudioPlayerVC.swift
new file mode 100644 (file)
index 0000000..257b629
--- /dev/null
@@ -0,0 +1,141 @@
+//
+//  AudioPlayerVC.swift
+//  ShenYin
+//
+//  Created by liangshi on 2025/10/9.
+//
+
+import UIKit
+
+class AudioPlayerVC:BaseVC{
+    
+    let bgView = UIImageView()
+    let musicView = UIImageView()
+    let slider = UISlider()
+    let nameLabel = UILabel()
+    let titleLabel = UILabel()
+    let valueLabel = UILabel()
+    let playBtn = UIButton(type: .custom)
+    let musicModel:MusicModel
+    
+    init(model:MusicModel) {
+        self.musicModel = model
+        super.init()
+    }
+    
+    
+    override func setupViews() {
+        navBar.leftView.setImage(UIImage(named: "arrow_back_white"), for: .normal)
+        navBar.backgroundColor = .clear
+        view.addSubviews([bgView,musicView,slider,nameLabel,titleLabel,valueLabel,playBtn])
+        view.bringSubviewToFront(navBar)
+        
+        
+        bgView.do { v in
+//            v.image = UIImage(named: "logo")
+            v.kf.setImage(with: musicModel.cover.yc.asUrl)
+            // 创建虚化效果
+            let blurEffect = UIBlurEffect(style:.light)
+            let blurEffectView = UIVisualEffectView(effect: blurEffect)
+            blurEffectView.frame = UIScreen.main.bounds
+            v.addSubview(blurEffectView)
+        }
+        musicView.do { v in
+            v.kf.setImage(with: musicModel.cover.yc.asUrl)
+            v.yc.setCornerRadius(121)
+        }
+        
+        slider.do { v in
+            //            v.backgroundColor = .red
+            v.minimumValue = 0
+            v.maximumValue = Float(musicModel.duration)
+            v.value = 0
+            v.minimumTrackTintColor = .white
+            v.setThumbImage(UIColor.white.imageCircle(with:  CGSize(width: 20, height: 20)), for: .normal)
+            v.addTarget(self, action: #selector(sliderChanged(_:)), for: .valueChanged) // continuous changes
+            
+        }
+        nameLabel.do { v in
+            v.text = musicModel.name
+            v.textColor = .white
+            v.textAlignment = .center
+            v.font = .medium(18)
+        }
+        titleLabel.do { v in
+            v.text = "00:00"
+            v.textColor = .white
+            v.textAlignment = .center
+            v.font = .regular(12)
+        }
+        valueLabel.do { v in
+            v.text = YLToos.formatSeconds1(musicModel.duration)
+            v.textColor = .white
+            v.textAlignment = .center
+            v.font = .regular(12)
+        }
+        playBtn.do { v in
+            v.setImage(UIImage(named: "music_play"), for: .normal)
+            v.setImage(UIImage(named: "music_pause"), for: .selected)
+            v.addTarget(self, action: #selector(btnAction), for: .touchUpInside)
+        }
+    }
+    override func setupLayout() {
+        bgView.snp.makeConstraints { make in
+            make.edges.equalToSuperview()
+        }
+        musicView.snp.makeConstraints { make in
+            make.size.equalTo(242)
+            make.top.equalToSuperview().inset(kNavBtm + 100)
+            make.centerX.equalToSuperview()
+        }
+        nameLabel.snp.makeConstraints { make in
+            make.centerX.equalToSuperview()
+            make.top.equalTo(musicView.snp.bottom).offset(40)
+        }
+        slider.snp.makeConstraints { make in
+//            make.width.equalTo(200)
+            make.height.equalTo(40)
+            make.centerX.equalToSuperview()
+            make.left.right.equalToSuperview().inset(40)
+            make.top.equalTo(musicView.snp.bottom).offset(100)
+        }
+        titleLabel.snp.makeConstraints { make in
+            make.left.equalTo(slider)
+            make.top.equalTo(slider.snp.bottom)
+        }
+        valueLabel.snp.makeConstraints { make in
+            make.right.equalTo(slider)
+            make.top.equalTo(slider.snp.bottom)
+        }
+        playBtn.snp.makeConstraints { make in
+            make.size.equalTo(66)
+            make.centerX.equalToSuperview()
+            make.top.equalTo(slider.snp.bottom).offset(40)
+        }
+    }
+    override func setupData() {
+
+        SleepVM.getMusicUrl(filedId: musicModel.fileId) { [weak self] model in
+            guard let self = self else{return}
+            
+        }
+    }
+    
+    override func navRightViewTapped() {
+        
+    }
+    @objc func addAction(){
+        
+    }
+    @objc func btnAction(){
+        playBtn.isSelected = !playBtn.isSelected
+    }
+    @objc func sliderChanged(_ slider:UISlider){
+        let value = YLToos.formatSeconds1(Int(slider.value))
+        Logger.debug(slider.value)
+        if let text = titleLabel.text, text != value {
+            titleLabel.text = value
+        }
+    }
+    
+}
diff --git a/ShenYin/ShenYin/UI/Sleep/MusicModel.swift b/ShenYin/ShenYin/UI/Sleep/MusicModel.swift
new file mode 100644 (file)
index 0000000..5ff12e3
--- /dev/null
@@ -0,0 +1,31 @@
+//
+//  Music.swift
+//  ShenYin
+//
+//  Created by liangshi on 2025/10/9.
+//
+import HandyJSON
+
+class MusicModelRoot:ResponseBaseModel {
+    var data = MusicData()
+}
+class MusicData:HandyJSON {
+    var list = [MusicModel]()
+    var total = 0
+    var pageSize = 0
+    var currentPage = 0
+    var totalPage = 0
+    var hasNext = false
+    var hasPre = false
+    
+    required public init() { }
+}
+class MusicModel:HandyJSON {
+    var id = ""
+    var name = ""
+    var cover = ""
+    var fileId = ""
+    var duration = 0
+    var categoryId = ""
+    required public init() { }
+}
index 75bd374..097ba1f 100644 (file)
@@ -54,4 +54,11 @@ class SleepCell: BaseCollectionViewCell {
     required init?(coder: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }
+    
+    var model:MusicModel!{
+        didSet{
+            titleLab.text = model.name
+            imgV.kf.setImage(with: model.cover.yc.asUrl)
+        }
+    }
 }
index 93633b1..e890734 100644 (file)
@@ -12,17 +12,17 @@ import MJRefresh
 
  class SleepListView: BaseView,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout {
     private var collectionView:UICollectionView!
+     let vm:SleepVM
      
-    init(selectType type:Int){
+    init(selectType type:MusicCategory){
+        vm = SleepVM(category: type)
         super.init(frame: .zero)
+        
 //        setupLayout()
 //        setupStyle()
-        //        tableView.mj_header?.beginRefreshing()
+        collectionView.mj_header?.beginRefreshing()
     }
 
-    override init(frame: CGRect) {
-        super.init(frame: frame)
-    }
     override func setupViews() {
         let layout = UICollectionViewFlowLayout()
         //        layout.minimumInteritemSpacing = 10.fitR
@@ -38,19 +38,43 @@ import MJRefresh
             v.bounces = true
             v.contentInset = UIEdgeInsets(top: 0, left: 18, bottom: 0, right: 18)
             v.register(SleepCell.self, forCellWithReuseIdentifier: SleepCell.reuseID)
-//            v.register(VipHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier:VipHeaderView.reuseID )
-//            v.register(VipSectionHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier:VipSectionHeader.reuseID )
+            v.mj_header = MJRefreshNormalHeader(refreshingTarget: self, refreshingAction: #selector(refreshAction))
+            v.mj_footer = MJRefreshBackNormalFooter(refreshingTarget: self, refreshingAction: #selector(loadMoreAction))
         }
     }
-    override func setupLayout() {
 
-        
+    override func setupLayout() {
         collectionView.snp.makeConstraints { (m) in
             m.top.equalToSuperview().inset(10)
             m.left.right.bottom.equalToSuperview()
         }
     }
-    
+     
+     @objc func refreshAction(){
+         vm.refresh {[weak self] result in
+             guard let self = self else {return}
+             collectionView.mj_header?.endRefreshing()
+             if result.success{
+                 collectionView.reloadData()
+             }
+             
+             if result.success,result.data.hasNext == false{
+                 collectionView.mj_footer?.endRefreshingWithNoMoreData()
+             }
+             else{
+                 collectionView.mj_footer?.endRefreshing()
+             }
+         }
+     }
+     @objc func loadMoreAction(){
+         vm.loadMore {[weak self] result in
+             guard let self = self else {return}
+             if result.success{
+                 collectionView.reloadData()
+             }
+         }
+     }
+
     @MainActor required init?(coder: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }
@@ -59,37 +83,17 @@ import MJRefresh
             return 1
         }
         func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-            return 30
+            return vm.list.count
         }
-//        func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView{
-//            if indexPath.section == 0 {
-//                let header = VipHeaderView.header(with: collectionView, indexPath: indexPath)
-//                header.banner.config(list: vm.bannerList)
-//                return header
-//            }
-//            else{
-//                let header = VipSectionHeader.header(with: collectionView, indexPath: indexPath)
-//                return header
-//            }
-//        }
-        
-//        func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
-//            if section == 0 {
-//                return CGSize(width: kScreenWid, height: 320.fitR)
-//            }
-//            else{
-//                return CGSize(width: kScreenWid, height: 50.fitR)
-//            }
-//        }
-        
         func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
             let cell = SleepCell.cell(withCollectionView: collectionView, indexPath: indexPath)
-//            cell.model = self.vm.cellList[indexPath.row]
+            cell.model = vm.list[indexPath.row]
             return cell
         }
-        
-    
-
+     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
+         let model = vm.list[indexPath.row]
+         App.shared.goToPage(AudioPlayerVC(model: model))
+     }
 }
 
 extension SleepListView: JXSegmentedListContainerViewListDelegate {
diff --git a/ShenYin/ShenYin/UI/Sleep/SleepPageVC.swift b/ShenYin/ShenYin/UI/Sleep/SleepPageVC.swift
deleted file mode 100644 (file)
index 806cac7..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-////
-////  SleepPageVC.swift
-////  ShenYin
-////
-////  Created by liangshi on 2025/8/6.
-////
-//
-//import UIKit
-//
-//class SleepPageVC:UIViewController{
-//    
-//    override func viewDidLoad() {
-//        super.viewDidLoad()
-//        view.backgroundColor = UIColor.random()
-//    }
-//
-//}
-//extension UIColor {
-//    static func random() -> UIColor {
-//        let red = CGFloat.random(in: 0...1)
-//        let green = CGFloat.random(in: 0...1)
-//        let blue = CGFloat.random(in: 0...1)
-//        return UIColor(red: red, green: green, blue: blue, alpha: 1.0)
-//    }
-//}
index 64083a9..810df3f 100644 (file)
@@ -11,7 +11,7 @@ class SleepVC: BaseVC {
         return view
     }()
     
-    let vm = SleepVM()
+    var list = [MusicCategory]()
     override func viewDidLoad() {
         super.viewDidLoad()
 
@@ -47,7 +47,7 @@ class SleepVC: BaseVC {
             segmentedDataSource.isItemSpacingAverageEnabled = true
             segmentedDataSource.isTitleColorGradientEnabled = true
 //            segmentedDataSource.titles = titles.map{"\($0.name)"}
-            segmentedDataSource.titles = vm.catogory.map{"\($0.name)"}
+            segmentedDataSource.titles = list.map{"\($0.name)"}
             segmentedView.backgroundColor = .clear
             
             //配置指示器
@@ -64,15 +64,16 @@ class SleepVC: BaseVC {
     }
     
     override func setupData() {
-        vm.getCagory { [weak self ]model in
+        SleepVM.getCagory { [weak self ]model in
             guard let self = self else{return}
-            
-            segmentedDataSource.titles = vm.catogory.map{"\($0.name)"}
-            segmentedView.dataSource = segmentedDataSource
-            
-            listContainerView.reloadData()
-            segmentedView.reloadData()
-            
+            if model.isSuccess{
+                list = model.data
+                segmentedDataSource.titles = model.data.map{"\($0.name)"}
+                segmentedView.dataSource = segmentedDataSource
+                
+                listContainerView.reloadData()
+                segmentedView.reloadData()
+            }
         }
     }
 }
@@ -93,7 +94,8 @@ extension SleepVC: JXSegmentedListContainerViewDataSource {
     
     func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
 //        let dele = SleepListView(selectType: titles[index])
-        let dele = SleepListView(selectType: index)
+        
+        let dele = SleepListView(selectType: list[index])
 
 //        dele.popToRoot = { [unowned self] in
 //            navigationController?.popToRootViewController(animated: true)
index 4776958..b0eeb1e 100644 (file)
@@ -6,26 +6,61 @@
 //
 
 class SleepVM:BaseVM{
-    var catogory = [MusicCategory]()
+    var category = MusicCategory()
+    var list = [MusicModel]()
+    var page = 0
     
-    public func getCagory( completion:@escaping (_ result:MusicCategoryRoot) ->Void) {
-        let api = CommomApi.musicCategory
-        HttpClient.request(api) {[weak self] (model:MusicCategoryRoot,res) in
+    init(category: MusicCategory) {
+        self.category = category
+    }
+
+    public func refresh(completion:@escaping (_ result:MusicModelRoot) ->Void) {
+        self.page = 1
+        let api = CommomApi.musicCategoryList(categoryId: category.id, page: self.page)
+        HttpClient.request(api) {[weak self] (model:MusicModelRoot,res) in
             guard let self = self else {return}
             if model.isSuccess{
-                catogory = model.data
+                page = model.data.currentPage
+                if model.data.currentPage == 1 {
+                    list = model.data.list
+                }
+                else{
+                    list += model.data.list
+                }
             }
             completion(model)
         }
     }
-    
-    public func getCagoryList(categoryId:String,page:Int, completion:@escaping (_ result:ResponseBaseModel) ->Void) {
-        let api = CommomApi.muiscCategoryList(categoryId: categoryId, page: 1)
-        HttpClient.request(api) {[weak self] (model:ResponseBaseModel,res) in
+    public func loadMore(completion:@escaping (_ result:MusicModelRoot) ->Void) {
+        self.page += 1
+        let api = CommomApi.musicCategoryList(categoryId: category.id, page: self.page)
+        HttpClient.request(api) {[weak self] (model:MusicModelRoot,res) in
             guard let self = self else {return}
             if model.isSuccess{
+                page = model.data.currentPage
+                if model.data.currentPage == 1 {
+                    list = model.data.list
+                }
+                else{
+                    list += model.data.list
+                }
             }
             completion(model)
         }
     }
 }
+
+extension SleepVM{
+    static public func getCagory( completion:@escaping (_ result:MusicCategoryRoot) ->Void) {
+        let api = CommomApi.musicCategory
+        HttpClient.request(api) { (model:MusicCategoryRoot,res) in
+            completion(model)
+        }
+    }
+    static public func getMusicUrl(filedId id:String, completion:@escaping (_ result:ResponseBaseModel) ->Void) {
+        let api = CommomApi.musicUrl(filedId: id)
+        HttpClient.request(api) { (model:MusicCategoryRoot,res) in
+            completion(model)
+        }
+    }
+}