IHLoginManager.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // IHLoginManager.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/10.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import PKHUD
  10. class IHLoginManager: NSObject,IHViewManagerProtocolDelegate {
  11. var role:Int = 0
  12. private var vc = UIViewController()
  13. lazy var mainView: IHLoginView = {
  14. let mainView = Bundle.main.loadNibNamed("IHLoginView", owner: nil, options: nil)?.last as! IHLoginView
  15. mainView.loginDelegate = self
  16. return mainView
  17. }()
  18. //绑定控制器
  19. func bindController(_ vc: UIViewController) {
  20. self.vc = vc
  21. createUI()
  22. }
  23. //添加mainView
  24. func createUI() {
  25. self.vc.view.addSubview(mainView)
  26. }
  27. }
  28. //实现UI事件
  29. extension IHLoginManager:IHLoginViewDelegate{
  30. //快速安装
  31. func jumpToClassgatewayCtr(gatewayList list: [Any]) {
  32. let vcCtr = IHClassGatewayCtr()
  33. vcCtr.gatewayList = list as? [gatewayInfor]
  34. vcCtr.modalPresentationStyle = .fullScreen
  35. self.vc.present(vcCtr, animated: false, completion: nil)
  36. }
  37. func signIn(with account: String?, password: String?) {
  38. self.vc.view.endEditing(true)
  39. //输入验证
  40. if account == "" || password == "" || account?.isBlanck == true{
  41. HUD.flash(.error, delay: 1.5)
  42. return
  43. }
  44. g_showProgress() //带超时
  45. //将登陆信息上传到服务器,返回结果之后,再选择是管理员用户还是非管理员用户
  46. IHLoginService.share.getLogInfo(account!, password: password!, code: nil, requstSuccess: { (data) in
  47. self.loginSuccess(data, account: account, password: password)
  48. }) {
  49. HUD.flash(.error, delay: 1.5)
  50. }
  51. }
  52. //处理登录成功定义
  53. func loginSuccess(_ data:LoginData,account:String?,password:String?) {
  54. HUD.flash(.success, delay: 1.5)
  55. checkStorage(account!,password: password!)
  56. log.debug("返回数据 -- \(data)")
  57. if data.role == "4"{ //role 操作接口文档定义
  58. AppShare.tempRole = 0
  59. self.mainView.role = "0"
  60. //改变登录角色
  61. IHHotelStorage.shareInstance.storageRole("0")//持久化信息
  62. NotificationCenter.default.post(name: NSNotification.Name(kNotifactionIHLoginViewChangeRole), object: "0")
  63. let guestsVC = IHGuestsVCtr()
  64. let nav = IHNavigationController(rootViewController: guestsVC)
  65. nav.modalPresentationStyle = .fullScreen
  66. self.vc.present(nav, animated: true, completion: nil)
  67. }else{ //管理员登录
  68. self.mainView.role = "1"
  69. IHHotelStorage.shareInstance.storageRole("1")
  70. NotificationCenter.default.post(name: NSNotification.Name(kNotifactionIHLoginViewChangeRole), object: "1")
  71. AppShare.tempRole = 1
  72. let mainVC = IHTabBarController()
  73. mainVC.modalPresentationStyle = .fullScreen
  74. self.vc.present(mainVC, animated: true, completion: nil)
  75. }
  76. }
  77. func checkStorage(_ account:String,password:String) {
  78. //查找沙盒里边是否有已经存储的值
  79. let username = IHHotelStorage.shareInstance.getStorageUsername()
  80. if username != nil{//如果已经保存了值,判断是不是跟上次保存的值相同
  81. let info = IHHotelStorage.shareInstance.getHotelStore()
  82. log.debug("info - \(info)")
  83. if username == account {
  84. // 获取保存的酒店信息
  85. if let info = info {
  86. Intermediate.countryId = info.countryId ?? ""
  87. Intermediate.countryName = info.countryName ?? ""
  88. Intermediate.provinceId = info.provinceId ?? ""
  89. Intermediate.provinceName = info.provinceName ?? ""
  90. Intermediate.cityId = info.cityId ?? ""
  91. Intermediate.cityName = info.cityName ?? ""
  92. Intermediate.hotelId = info.hotelId ?? ""
  93. Intermediate.hotelName = info.hotelName ?? ""
  94. Intermediate.buildId = info.buildId ?? ""
  95. Intermediate.buildName = info.buildName ?? ""
  96. }
  97. }else{//如果不相等 ,先保存用户名
  98. if info != nil {//如果清空
  99. IHHotelStorage.shareInstance.clearStorage()
  100. }
  101. }
  102. }//保存内容
  103. IHHotelStorage.shareInstance.storageUserName(account)
  104. IHHotelStorage.shareInstance.storagePassword(password)
  105. }
  106. //注册
  107. func signUp() {
  108. let signupvc = IHSignUpVCtr()
  109. // let signupvc = IHGuestInfoVCtr()
  110. let nav = IHNavigationController(rootViewController: signupvc)
  111. nav.modalPresentationStyle = .fullScreen
  112. self.vc.present(nav, animated: true, completion: nil)
  113. }
  114. //修改角色
  115. func changeAuthority(_ role: Int) {
  116. self.role = role
  117. AppShare.tempRole = role
  118. }
  119. //隐私政策
  120. func goPrivacyPolicy() {
  121. let vc = IHPrivacyVCtr()
  122. let nav = IHNavigationController(rootViewController: vc)
  123. nav.modalPresentationStyle = .fullScreen
  124. self.vc.present(nav, animated: true, completion: nil)
  125. }
  126. }