From d0209d298b70a7b57cccd39ddd02c98cd51d2152 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Tue, 15 Apr 2025 16:18:08 +0800 Subject: [PATCH] fix view --- dimensionhub/Core/API.swift | 7 +++++++ dimensionhub/Views/FlexImage.swift | 2 +- dimensionhub/Views/Index/IndexMainView.swift | 3 +++ dimensionhub/Views/Index/IndexModel.swift | 13 +++++++++++++ dimensionhub/dimensionhubApp.swift | 4 ++-- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/dimensionhub/Core/API.swift b/dimensionhub/Core/API.swift index 86501b8..bb4b7c2 100644 --- a/dimensionhub/Core/API.swift +++ b/dimensionhub/Core/API.swift @@ -61,6 +61,13 @@ struct API { return await doRequest(request: request, as: T.self) } + // 获取用户的关注数 + static func getFlowNum(userId: String, as: T.Type) async -> APIResponse { + let request = URLRequest(url: URL(string: baseUrl + "/api/follow_num?user_id=\(userId)")!) + + return await doRequest(request: request, as: T.self) + } + // 前后刷新获取数据 static func loadMoreUpdateDramas(userId: String, mode: LoadMode, id: Int, as: T.Type) async -> APIResponse { let request = URLRequest(url: URL(string: baseUrl + "/api/load_more_dramas?user_id=\(userId)&mode=\(mode.rawValue)&id=\(id)")!) diff --git a/dimensionhub/Views/FlexImage.swift b/dimensionhub/Views/FlexImage.swift index f159339..a14cdc9 100644 --- a/dimensionhub/Views/FlexImage.swift +++ b/dimensionhub/Views/FlexImage.swift @@ -28,7 +28,7 @@ struct FlexImage: View { let cacheManager = CacheManager.shared if let data = cacheManager.readFileContents(urlString: urlString) { - print("url: \(urlString), hit cache") + //print("url: \(urlString), hit cache") self.mode = .local(data) } else { self.mode = .remote(urlString) diff --git a/dimensionhub/Views/Index/IndexMainView.swift b/dimensionhub/Views/Index/IndexMainView.swift index 6b0752b..f19f357 100644 --- a/dimensionhub/Views/Index/IndexMainView.swift +++ b/dimensionhub/Views/Index/IndexMainView.swift @@ -52,6 +52,9 @@ struct IndexMainView: View { } ) .zIndex(1) + .task { + await indexModel.reloadFollowNum(userId: userId) + } } .padding([.leading, .trailing], 15) .frame(height: 50) diff --git a/dimensionhub/Views/Index/IndexModel.swift b/dimensionhub/Views/Index/IndexModel.swift index 651211b..71cfca5 100644 --- a/dimensionhub/Views/Index/IndexModel.swift +++ b/dimensionhub/Views/Index/IndexModel.swift @@ -145,6 +145,19 @@ final class IndexModel { self.isLoaded = true } + func reloadFollowNum(userId: String) async { + let response = await API.getFlowNum(userId: userId, as: Int.self) + switch response { + case .error(let code, let message): + print("reloadFollowNum get error: \(code), message: \(message)") + case .result(let follow_num): + await MainActor.run { + self.follow_num = follow_num >= 100 ? "99+" : "\(follow_num)" + } + } + self.isLoaded = true + } + func setFixedDrameGroup(groupId: String) { if let newFixedDramaGroup = self.updateDramaGroups.first(where: {$0.group_id == groupId}), newFixedDramaGroup.group_id != self.fixedDramaGroup?.group_id { diff --git a/dimensionhub/dimensionhubApp.swift b/dimensionhub/dimensionhubApp.swift index 60f8cd6..66fc8df 100644 --- a/dimensionhub/dimensionhubApp.swift +++ b/dimensionhub/dimensionhubApp.swift @@ -146,9 +146,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { - //let userInfo = notification.request.content.userInfo + let userInfo = notification.request.content.userInfo // 处理通知数据 - //handleRemoteNotification(userInfo: userInfo) + handleRemoteNotification(userInfo: userInfo) // 设置如何显示通知 completionHandler([.banner, .sound])