Explorar o código

feat: 增加个人页点赞功能

陈文艺 hai 4 días
pai
achega
d0b564633c

+ 7 - 9
Lanu/Manager/Profile/LNProfileManager.swift

@@ -155,15 +155,13 @@ extension LNProfileManager {
         }
     }
     
-//    func getUserOnlineState(uids: [String], queue: DispatchQueue = .main, handler: @escaping ([String: Bool]) -> Void) {
-//        LNHttpManager.shared.getUserOnlineState(uids: uids) { res, err in
-//            queue.asyncIfNotGlobal {
-//                handler(res?.list.reduce(into: [String: Bool](), { partialResult, state in
-//                    partialResult[state.userNo] = state.online
-//                }) ?? [:])
-//            }
-//        }
-//    }
+    func likeUser(uid: String, queue: DispatchQueue = .main, handler: @escaping (Bool) -> Void) {
+        LNHttpManager.shared.likeUser(uid: uid) { err in
+            queue.asyncIfNotGlobal {
+                handler(err == nil)
+            }
+        }
+    }
 }
 
 extension LNProfileManager {

+ 4 - 5
Lanu/Manager/Profile/Network/LNHttpManager+Profile.swift

@@ -17,7 +17,7 @@ private let kNetPath_Profile_UsersInfo = "/user/get/infos"
 
 private let kNetPath_Profile_Random = "/user/info/random/profiles"
 
-private let kNetPath_Profile_Online = "/user/getUsersOnlineState"
+private let kNetPath_Profile_Like = ""
 
 private let kNetPath_Profile_Bind_Captcha = "/user/bind/mobile/sendCode"
 private let kNetPath_Profile_Bind_Phone = "/user/bind/mobile"
@@ -93,11 +93,10 @@ extension LNHttpManager {
         post(path: kNetPath_Profile_Random, completion: completion)
     }
     
-    func getUserOnlineState(uids: [String], completion: @escaping (LNUserOnlineStateResponse?, LNHttpError?) -> Void) {
-        post(path: kNetPath_Profile_Online, params: [
-            "userNos": uids
+    func likeUser(uid: String, completion: @escaping (LNHttpError?) -> Void) {
+        post(path: kNetPath_Profile_Like, params: [
+            "id": uid
         ], completion: completion)
-        
     }
 }
 

+ 3 - 0
Lanu/Manager/Profile/Network/LNProfileResponse.swift

@@ -58,6 +58,9 @@ class LNUserProfileVO: Decodable, Copyable {
     var birthday: Int = 0
     var rated: Bool = false
     var interests: [LNUserInterestVO] = []
+    var likeCount: Int = 0
+    var hasLike: Bool = false
+    var likeScore: Int = 0
     
     var isAvailable: Bool {
         !avatar.isEmpty

+ 15 - 4
Lanu/Views/Profile/Profile/LNProfileUserInfoView.swift

@@ -19,6 +19,7 @@ class LNProfileUserInfoView: UIView {
     private let likeCountLabel = UILabel()
     
     private let scoreLabel = UILabel()
+    private let likeIc = UIImageView()
     
     private var curDetail: LNUserProfileVO?
     
@@ -34,10 +35,14 @@ class LNProfileUserInfoView: UIView {
         idLabel.text = "ID \(detail.userNo)"
         
         followCountLabel.text = .init(key: "A00234", detail.fansCount.formattedAsShortNumber())
-//        likeCountLabel.text = detail.fansCount.formattedAsShortNumber() + .init(key: "A00301")
+        likeCountLabel.text = detail.likeCount.formattedAsShortNumber() + .init(key: "A00301")
         
-//        scoreLabel.text = detail.star.formattedAsShortNumber()
+        scoreLabel.text = detail.likeScore.formattedAsShortNumber()
         scoreLabel.superview?.isHidden = !detail.playmate
+        if detail.hasLike {
+            likeIc.image = .icLikeFilled
+            likeIc.superview?.isUserInteractionEnabled = false
+        }
         
         curDetail = detail
     }
@@ -138,10 +143,16 @@ extension LNProfileUserInfoView {
         let container = UIView()
         container.onTap { [weak self] in
             guard let self else { return }
-            
+            guard let curDetail else { return }
+            LNProfileManager.shared.likeUser(uid: curDetail.userNo)
+            { [weak self] success in
+                guard let self else { return }
+                guard success else { return }
+                likeIc.image = .icLikeFilled
+                likeIc.superview?.isUserInteractionEnabled = false
+            }
         }
         
-        let likeIc = UIImageView()
         likeIc.image = .icLikeEmpty.withTintColor(.text_1, renderingMode: .alwaysOriginal)
         container.addSubview(likeIc)
         likeIc.snp.makeConstraints { make in