126 lines
3.9 KiB
Swift
126 lines
3.9 KiB
Swift
//
|
|
// AccountVC.swift
|
|
// QuickLocation
|
|
//
|
|
// Created by 八条 on 2026/6/10.
|
|
//
|
|
|
|
import UIKit
|
|
import RxSwift
|
|
import RxCocoa
|
|
import RxDataSources
|
|
import Kingfisher
|
|
#if !targetEnvironment(simulator)
|
|
import GeYanSdk
|
|
import RxGesture
|
|
#endif
|
|
|
|
class AccountVC: BaseViewController {
|
|
|
|
fileprivate var rootView: AccountView!
|
|
|
|
override func loadView() {
|
|
rootView = AccountView(frame: UIScreen.main.bounds)
|
|
view = rootView
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
reactiveAction()
|
|
|
|
DispatchQueue.global(qos: .background).async {
|
|
let totalByte = AppCacheManager.totalCacheSize()
|
|
let cacheText = AppCacheManager.formatByte(totalByte)
|
|
DispatchQueue.main.async {
|
|
// 赋值给 Label 展示
|
|
self.rootView.cacheLab.text = "\(cacheText)"
|
|
}
|
|
}
|
|
}
|
|
|
|
private func reactiveAction() {
|
|
rootView.logoutBtn.rx.tap.subscribe(onNext: { _ in
|
|
self.showConfirmPop(title: "温馨提醒",
|
|
message: "确定要退出账号吗?",
|
|
confirmText: "否",
|
|
confirmBlock: { },
|
|
cancelText: "是") {
|
|
self.requestLogout()
|
|
}
|
|
}).disposed(by: disposeBag)
|
|
|
|
rootView.cancelledBtn.rx.tap.subscribe(onNext: { _ in
|
|
CancellationPopView.show {
|
|
self.deleteAccount()
|
|
}
|
|
}).disposed(by: disposeBag)
|
|
|
|
let tap = UITapGestureRecognizer(target: self, action: #selector(handleClearCacheTap))
|
|
rootView.clearView.addGestureRecognizer(tap)
|
|
|
|
let versionTap = UITapGestureRecognizer(target: self, action: #selector(handleVersionViewTap))
|
|
rootView.versionView.addGestureRecognizer(versionTap)
|
|
}
|
|
|
|
// MARK: - API
|
|
private func requestLogout() {
|
|
DLToast.showLoading()
|
|
UserService.logout().subscribe(onNext: { response in
|
|
DLToast.dismiss()
|
|
NotificationCenter.default.post(name: .invalidatePopupQueue, object: nil)
|
|
GeYanSdk.deletePreResultCache()
|
|
AppContextManager.shared.deleteAccount()
|
|
GroupIMService.shared.logout()
|
|
AppDelegate.shared.showMainViewController()
|
|
}, onError: { _ in }).disposed(by: disposeBag)
|
|
}
|
|
|
|
private func deleteAccount() {
|
|
DLToast.showLoading()
|
|
UserService.deleteAccount().subscribe(onNext: { response in
|
|
DLToast.show(text: "申请成功")
|
|
}, onError: { _ in }).disposed(by: disposeBag)
|
|
}
|
|
|
|
@objc private func handleClearCacheTap() {
|
|
clearCache()
|
|
}
|
|
|
|
@objc private func handleVersionViewTap() {
|
|
guard let upgrade = AppContextManager.shared.systemConfig?.versionUpgradeModel else {
|
|
DLToast.show(text: "已是最新版本")
|
|
return
|
|
}
|
|
self.showConfirmPop(
|
|
showCloseBtn: !upgrade.force,
|
|
title: upgrade.title,
|
|
message: upgrade.description,
|
|
confirmText: "立即更新",
|
|
confirmBlock: {
|
|
if let url = URL(string: upgrade.url) {
|
|
UIApplication.shared.open(url)
|
|
}
|
|
},
|
|
cancelText: upgrade.force ? nil : "稍后再说",
|
|
cancelBlock: nil
|
|
)
|
|
}
|
|
|
|
private func clearCache() {
|
|
DLToast.showLoading()
|
|
KingfisherManager.shared.cache.clearMemoryCache()
|
|
KingfisherManager.shared.cache.clearDiskCache {
|
|
AppCacheManager.clearCache {
|
|
DispatchQueue.main.async {
|
|
DLToast.dismiss()
|
|
DLToast.show(text: "缓存已清除")
|
|
self.rootView.cacheLab.text = "0 B"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|