feat(training): 为请求操作接入通用Loading
This commit is contained in:
@@ -281,12 +281,40 @@ final class TrainingRecordCell: UITableViewCell {
|
||||
/// 培训页面在账号或景区切换时立即关闭,停止展示旧身份记录。
|
||||
@MainActor
|
||||
class TrainingBaseViewController: BaseViewController {
|
||||
private var requestLoadingTokens: Set<UUID> = []
|
||||
|
||||
/// 展示本页面请求持有的 App 通用 Loading,在完成或离开页面时释放。
|
||||
func beginRequestLoading() -> UUID {
|
||||
let token = GlobalLoadingManager.shared.beginRequest()
|
||||
requestLoadingTokens.insert(token)
|
||||
return token
|
||||
}
|
||||
|
||||
/// 只释放本页面持有的令牌,迟到请求不能关闭其它页面的 Loading。
|
||||
func endRequestLoading(_ token: UUID) {
|
||||
guard requestLoadingTokens.remove(token) != nil else { return }
|
||||
GlobalLoadingManager.shared.endRequest(token)
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
endOwnedRequestLoading()
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
for name in [NotificationName.accountDidSwitch, NotificationName.scenicDidChange] {
|
||||
for name in [NotificationName.accountDidSwitch, NotificationName.scenicDidChange, NotificationName.userDidLogout] {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(contextChanged), name: name, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func contextChanged() { navigationController?.popToRootViewController(animated: false) }
|
||||
private func endOwnedRequestLoading() {
|
||||
for token in requestLoadingTokens { GlobalLoadingManager.shared.endRequest(token) }
|
||||
requestLoadingTokens = []
|
||||
}
|
||||
|
||||
@objc private func contextChanged() {
|
||||
endOwnedRequestLoading()
|
||||
navigationController?.popToRootViewController(animated: false)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user