LocalManager.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // LocalManager.swift
  3. // SwiftBilibili
  4. //
  5. // Created by 罗文 on 2021/3/23.
  6. // Copyright © 2021年 罗文. All rights reserved.
  7. //
  8. import UIKit
  9. import SwiftyUserDefaults
  10. import RxSwift
  11. class LocalManager {
  12. static var disposeBag = DisposeBag()
  13. static let loginService: LoginServiceType = LoginService(networking: LoginNetworking())
  14. //本地用户信息
  15. static var userInfo: UserInfo = UserInfo()
  16. //清理
  17. class func clearUserInfo() {
  18. }
  19. //判断是否登录了
  20. static func isOpenLogin()->Bool{
  21. if !LocalManager.userInfo.isLogin {
  22. NYSwRouter.open(NYSwOpenType.login.rawValue)
  23. return false
  24. }
  25. return true
  26. }
  27. //自动登录
  28. static func autoLogin(){
  29. if LocalManager.userInfo.isLogin {
  30. let account = LocalManager.userInfo.userAccount!
  31. let password = LocalManager.userInfo.password!
  32. let city = LocalManager.userInfo.city!
  33. LocalManager.loginService.loginRequest(user_name: account, user_password: password,city: city)
  34. .subscribe(onSuccess: { userinfo in
  35. NYTips.hide()
  36. LocalManager.userInfo = userinfo
  37. }, onError: { error in
  38. })
  39. .disposed(by: LocalManager.disposeBag)
  40. }
  41. }
  42. }