70 lines
2.1 KiB
Swift
70 lines
2.1 KiB
Swift
//
|
||
// SignInVC.swift
|
||
// QuickLocation
|
||
//
|
||
// Created by 八条 on 2026/6/17.
|
||
//
|
||
|
||
import UIKit
|
||
import RxSwift
|
||
import RxCocoa
|
||
import CoreLocation
|
||
|
||
class SignInVC: BaseViewController {
|
||
|
||
fileprivate var rootView: SignInView!
|
||
|
||
override func loadView() {
|
||
rootView = SignInView(frame: UIScreen.main.bounds)
|
||
view = rootView
|
||
}
|
||
|
||
/// 当前用户坐标(由外部传入)
|
||
var lastLocation: CLLocation?
|
||
|
||
private let geocoder = CLGeocoder()
|
||
private var isSignIn: Bool = false
|
||
|
||
override func viewDidLoad() {
|
||
super.viewDidLoad()
|
||
|
||
requestSignInInfo()
|
||
|
||
rootView.signInLottieView.rx.tapGesture.subscribe(onNext: { [weak self] _ in
|
||
self?.dl.showLoading()
|
||
guard let self = self, let loc = self.lastLocation, isSignIn == false else { return }
|
||
self.geocoder.reverseGeocodeLocation(loc) { [weak self] placemarks, error in
|
||
self?.dl.dismiss()
|
||
guard let self = self else { return }
|
||
let address = placemarks?.first?.name
|
||
?? placemarks?.first?.thoroughfare
|
||
?? placemarks?.first?.locality
|
||
?? ""
|
||
MQTTService.shared.reportSignIn(lat: loc.coordinate.latitude, lon: loc.coordinate.longitude, addr: address)
|
||
self.dl.show(text: "签到成功") {
|
||
self.requestSignInInfo()
|
||
}
|
||
}
|
||
}).disposed(by: disposeBag)
|
||
}
|
||
|
||
// MARK: - API
|
||
private func requestSignInInfo() {
|
||
DLToast.showLoading()
|
||
UserService.signInInfo().subscribe(onNext: { response in
|
||
guard let model = response.model else { return }
|
||
self.isSignIn = model.signInStatus == 1
|
||
self.rootView.setupData(model)
|
||
}, onError: { _ in }).disposed(by: disposeBag)
|
||
}
|
||
|
||
init(lastLocation: CLLocation?) {
|
||
self.lastLocation = lastLocation
|
||
super.init(nibName: nil, bundle: nil)
|
||
}
|
||
|
||
required init?(coder: NSCoder) {
|
||
fatalError("init(coder:) has not been implemented")
|
||
}
|
||
}
|