| | |
| | | |
| | | |
| | | class LoginViewModel{ |
| | | enum LoginType{ |
| | | case pwd,code |
| | | } |
| | | |
| | | var loginType = BehaviorRelay<LoginType>(value:.pwd) |
| | | var loginPhone = BehaviorRelay<String>(value:"") |
| | | var loginContent = BehaviorRelay<String>(value:"") |
| | |
| | | @IBOutlet weak var btn_register: UIButton! |
| | | @IBOutlet weak var btn_login: UIButton! |
| | | @IBOutlet weak var btn_sendCode: UIButton! |
| | | @IBOutlet weak var btn_isRead: UIButton! |
| | | |
| | | |
| | | private var viewModel = LoginViewModel() |
| | |
| | | } |
| | | |
| | | override func setUI() { |
| | | btn_eye.isSelected = true |
| | | view.addSubview(unlineImageView) |
| | | unlineImageView.snp.makeConstraints { make in |
| | | make.top.equalTo(self.btn_loginByPwd.snp.bottom).offset(6) |
| | |
| | | |
| | | @IBAction func loginTypeAction(_ sender: UIButton) { |
| | | sender.tag == 10 ? viewModel.loginType.accept(.pwd):viewModel.loginType.accept(.code) |
| | | |
| | | switch viewModel.loginType.value{ |
| | | case .code: |
| | | tf_content.isSecureTextEntry = false |
| | | case .pwd: |
| | | tf_content.isSecureTextEntry = btn_eye.isSelected |
| | | } |
| | | } |
| | | |
| | | @IBAction func eyeAction(_ sender: UIButton) { |
| | | sender.isSelected = !sender.isSelected |
| | | tf_content.isSecureTextEntry = sender.isSelected |
| | | } |
| | | |
| | | @IBAction func isReadAction(_ sender: UIButton) { |
| | | sender.isSelected = !sender.isSelected |
| | | } |
| | | |
| | | |
| | | @IBAction func sendCodeAction(_ sender: UIButton) { |
| | | |
| | | guard !viewModel.loginPhone.value.isEmpty else {alert(msg: "请输入手机号");return} |
| | | guard viewModel.loginPhone.value.jq_isPhone else {alert(msg: "请输入正确手机号");return} |
| | | |
| | | sender.jq_openCountDown(60, defultTitle: "发送验证码") { |
| | | sender.titleLabel?.font = UIFont.systemFont(ofSize: 12) |
| | | sender.setTitleColor(.black.withAlphaComponent(0.3), for: .normal) |
| | | } completeClouse: { |
| | | sender.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .medium) |
| | | sender.setTitleColor(UIColor(hexStr: "#96AD81"), for: .normal) |
| | | } |
| | | Services.sendCode(type: .codeLogin).subscribe(onNext: {data in |
| | | if let _ = data.data{ |
| | | sender.jq_openCountDown(60, defultTitle: "发送验证码") { |
| | | sender.titleLabel?.font = UIFont.systemFont(ofSize: 12) |
| | | sender.setTitleColor(.black.withAlphaComponent(0.3), for: .normal) |
| | | } completeClouse: { |
| | | sender.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .medium) |
| | | sender.setTitleColor(UIColor(hexStr: "#96AD81"), for: .normal) |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | @IBAction func loginAction(_ sender: UIButton) { |
| | | |
| | | guard viewModel.checkSafe() else {return} |
| | | guard btn_isRead.isSelected else { |
| | | alertError(msg: "请阅读并同意《用户注册协议》和《用户隐私协议》");return |
| | | } |
| | | |
| | | Services.loginBy(phone: viewModel.loginPhone.value, content: viewModel.loginContent.value, type: viewModel.loginType.value).subscribe(onNext: { data in |
| | | if let model = data.data{ |
| | | UserViewModel.saveUserInfo(model) |
| | | sceneDelegate?.loginSuccess() |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | @IBAction func userRegisterTreatyAction(_ sender: UIButton) { |
| | | let vc = LoginTreatyVC() |
| | | vc.topIndex = 0 |
| | | vc.clickHandle {[unowned self] state in |
| | | self.btn_isRead.isSelected = state |
| | | } |
| | | vc.modalPresentationStyle = .custom |
| | | present(vc, animated: true) |
| | | } |
| | | |
| | | @IBAction func userPrivateTreatyAction(_ sender: UIButton) { |
| | | let vc = LoginTreatyVC() |
| | | vc.topIndex = 1 |
| | | vc.clickHandle {[unowned self] state in |
| | | self.btn_isRead.isSelected = state |
| | | } |
| | | vc.modalPresentationStyle = .custom |
| | | present(vc, animated: true) |
| | | } |