| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- //
- // IHLoginManager.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/10.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- import PKHUD
- class IHLoginManager: NSObject,IHViewManagerProtocolDelegate {
- var role:Int = 0
- private var vc = UIViewController()
- lazy var mainView: IHLoginView = {
- let mainView = Bundle.main.loadNibNamed("IHLoginView", owner: nil, options: nil)?.last as! IHLoginView
-
- mainView.loginDelegate = self
- return mainView
- }()
- //绑定控制器
- func bindController(_ vc: UIViewController) {
- self.vc = vc
- createUI()
- }
- //添加mainView
- func createUI() {
- self.vc.view.addSubview(mainView)
- }
- }
- //实现UI事件
- extension IHLoginManager:IHLoginViewDelegate{
- //快速安装
- func jumpToClassgatewayCtr(gatewayList list: [Any]) {
- let vcCtr = IHClassGatewayCtr()
- vcCtr.gatewayList = list as? [gatewayInfor]
- vcCtr.modalPresentationStyle = .fullScreen
- self.vc.present(vcCtr, animated: false, completion: nil)
-
-
- }
-
- func signIn(with account: String?, password: String?) {
- self.vc.view.endEditing(true)
- //输入验证
- if account == "" || password == "" || account?.isBlanck == true{
- HUD.flash(.error, delay: 1.5)
- return
- }
- g_showProgress() //带超时
- //将登陆信息上传到服务器,返回结果之后,再选择是管理员用户还是非管理员用户
- IHLoginService.share.getLogInfo(account!, password: password!, code: nil, requstSuccess: { (data) in
- self.loginSuccess(data, account: account, password: password)
-
- }) {
- HUD.flash(.error, delay: 1.5)
- }
-
- }
- //处理登录成功定义
- func loginSuccess(_ data:LoginData,account:String?,password:String?) {
- HUD.flash(.success, delay: 1.5)
- checkStorage(account!,password: password!)
- log.debug("返回数据 -- \(data)")
- if data.role == "4"{ //role 操作接口文档定义
- AppShare.tempRole = 0
- self.mainView.role = "0"
- //改变登录角色
- IHHotelStorage.shareInstance.storageRole("0")//持久化信息
- NotificationCenter.default.post(name: NSNotification.Name(kNotifactionIHLoginViewChangeRole), object: "0")
- let guestsVC = IHGuestsVCtr()
- let nav = IHNavigationController(rootViewController: guestsVC)
- nav.modalPresentationStyle = .fullScreen
- self.vc.present(nav, animated: true, completion: nil)
-
- }else{ //管理员登录
- self.mainView.role = "1"
- IHHotelStorage.shareInstance.storageRole("1")
- NotificationCenter.default.post(name: NSNotification.Name(kNotifactionIHLoginViewChangeRole), object: "1")
- AppShare.tempRole = 1
- let mainVC = IHTabBarController()
- mainVC.modalPresentationStyle = .fullScreen
- self.vc.present(mainVC, animated: true, completion: nil)
-
- }
- }
-
- func checkStorage(_ account:String,password:String) {
- //查找沙盒里边是否有已经存储的值
- let username = IHHotelStorage.shareInstance.getStorageUsername()
-
- if username != nil{//如果已经保存了值,判断是不是跟上次保存的值相同
- let info = IHHotelStorage.shareInstance.getHotelStore()
- log.debug("info - \(info)")
- if username == account {
- // 获取保存的酒店信息
- if let info = info {
- Intermediate.countryId = info.countryId ?? ""
- Intermediate.countryName = info.countryName ?? ""
- Intermediate.provinceId = info.provinceId ?? ""
- Intermediate.provinceName = info.provinceName ?? ""
- Intermediate.cityId = info.cityId ?? ""
- Intermediate.cityName = info.cityName ?? ""
- Intermediate.hotelId = info.hotelId ?? ""
- Intermediate.hotelName = info.hotelName ?? ""
- Intermediate.buildId = info.buildId ?? ""
- Intermediate.buildName = info.buildName ?? ""
- }
- }else{//如果不相等 ,先保存用户名
- if info != nil {//如果清空
- IHHotelStorage.shareInstance.clearStorage()
- }
- }
- }//保存内容
- IHHotelStorage.shareInstance.storageUserName(account)
- IHHotelStorage.shareInstance.storagePassword(password)
-
- }
- //注册
- func signUp() {
- let signupvc = IHSignUpVCtr()
- // let signupvc = IHGuestInfoVCtr()
- let nav = IHNavigationController(rootViewController: signupvc)
- nav.modalPresentationStyle = .fullScreen
- self.vc.present(nav, animated: true, completion: nil)
-
-
- }
- //修改角色
- func changeAuthority(_ role: Int) {
- self.role = role
- AppShare.tempRole = role
- }
- //隐私政策
- func goPrivacyPolicy() {
- let vc = IHPrivacyVCtr()
- let nav = IHNavigationController(rootViewController: vc)
- nav.modalPresentationStyle = .fullScreen
- self.vc.present(nav, animated: true, completion: nil)
- }
- }
|