Files
suixinkan_uikit/suixinkan/Features/Home/ViewModels/PermissionApplyStatusViewModel.swift
汉秋 005349f8e6 模块化 AppStore 并完善素材管理与个人空间设置。
将会话、权限、位置、收款与排队存储拆分为独立模块,同步更新各 ViewModel 与单元测试,并补充素材管理 UI 与个人空间设置交互。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-13 11:01:08 +08:00

49 lines
1.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// PermissionApplyStatusViewModel.swift
// suixinkan
//
import Foundation
/// ViewModel Android `PermissionApplyStatusViewModel`
final class PermissionApplyStatusViewModel {
private(set) var pendingData: RoleApplyPendingResponse?
private(set) var isLoading = false
private(set) var rolePermissionList: [RolePermissionResponse] = []
var onStateChange: (() -> Void)?
var onNavigateToEdit: ((RoleApplyPendingResponse) -> Void)?
private let applyCode: String
private let appStore: AppStore
init(applyCode: String, appStore: AppStore = .shared) {
self.applyCode = applyCode
self.appStore = appStore
rolePermissionList = appStore.permissions.rolePermissionList()
}
func loadPendingData(api: HomeAPI) async {
isLoading = true
notifyStateChange()
do {
let pendingList = try await api.roleApplyPending()
pendingData = pendingList.first { $0.code == applyCode }
} catch {
pendingData = nil
}
isLoading = false
notifyStateChange()
}
func navigateToEditIfRejected() {
guard let pendingData, pendingData.status == PermissionApplyPendingStatus.rejected else { return }
onNavigateToEdit?(pendingData)
}
private func notifyStateChange() {
onStateChange?()
}
}