JCLoginViewController.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. //
  2. // JCLoginViewController.swift
  3. // JChat
  4. //
  5. // Created by deng on 2017/2/16.
  6. // Copyright © 2017年 HXHG. All rights reserved.
  7. //
  8. //import UIKit
  9. //import RxSwift
  10. //import RxCocoa
  11. //
  12. //
  13. //class JCLoginViewController: UIViewController {
  14. //
  15. // //MARK: - life cycle
  16. // override func viewDidLoad() {
  17. // super.viewDidLoad()
  18. // _init()
  19. // }
  20. //
  21. // override func viewWillAppear(_ animated: Bool) {
  22. // super.viewWillAppear(animated)
  23. // if UserDefaults.standard.object(forKey: kLastUserName) != nil {
  24. // lastUserName = UserDefaults.standard.object(forKey: kLastUserName) as? String
  25. // textValue.value = lastUserName!
  26. // }
  27. // avator = UIImage.getMyAvator()
  28. // avatorView.image = avator
  29. // }
  30. //
  31. // fileprivate let textValue = Variable("")
  32. // fileprivate let disposeBag = DisposeBag()
  33. // fileprivate var avator: UIImage?
  34. // fileprivate var lastUserName: String?
  35. //
  36. // fileprivate lazy var headerView: UIView = {
  37. // let view = UIView(frame: CGRect(x: 0, y: -64, width: self.view.width, height: 64))
  38. // view.backgroundColor = UIColor(netHex: 0x2DD0CF)
  39. // let title = UILabel(frame: CGRect(x: self.view.centerX - 10, y: 20, width: 200, height: 44))
  40. // title.font = UIFont.systemFont(ofSize: 18)
  41. // title.textColor = .white
  42. // title.text = "JChat"
  43. // view.addSubview(title)
  44. //
  45. // var rightButton = UIButton(frame: CGRect(x: view.width - 50 - 15, y: 20 + 7, width: 50, height: 30))
  46. // rightButton.setTitle("新用户", for: .normal)
  47. // rightButton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
  48. // rightButton.addTarget(self, action: #selector(_clickRegisterButton), for: .touchUpInside)
  49. // view.addSubview(rightButton)
  50. //
  51. // return view
  52. // }()
  53. //
  54. // private lazy var passwordTextField: UITextField = {
  55. // var textField = UITextField()
  56. // textField.addTarget(self, action: #selector(textFieldDidChanged(_ :)), for: .editingChanged)
  57. // textField.clearButtonMode = .whileEditing
  58. // textField.tag = 1002
  59. // textField.delegate = self
  60. // textField.placeholder = "请输入密码"
  61. // textField.isSecureTextEntry = true
  62. // textField.font = UIFont.systemFont(ofSize: 16)
  63. // textField.frame = CGRect(x: 38 + 18 + 15, y: 108 + 80 + 60 + 27 + 30, width: self.view.width - 76 - 33, height: 40)
  64. // return textField
  65. // }()
  66. //
  67. // private lazy var userNameTextField: UITextField = {
  68. // var textField = UITextField()
  69. // textField.addTarget(self, action: #selector(textFieldDidChanged(_ :)), for: .editingChanged)
  70. // textField.clearButtonMode = .whileEditing
  71. // textField.tag = 1001
  72. // textField.delegate = self
  73. // textField.placeholder = "请输入用户名"
  74. // textField.font = UIFont.systemFont(ofSize: 16)
  75. // textField.frame = CGRect(x: 38 + 18 + 15, y: 108 + 80 + 60, width: self.view.width - 76 - 33, height: 40)
  76. // return textField
  77. // }()
  78. //
  79. // fileprivate lazy var avatorView: UIImageView = {
  80. // var avatorView = UIImageView()
  81. // avatorView.frame = CGRect(x: self.view.centerX - 40, y: 108, width: 80, height: 80)
  82. // avatorView.image = UIImage.loadImage("com_icon_80")
  83. // return avatorView
  84. // }()
  85. //
  86. // private lazy var registerButton: UIButton = {
  87. // var button = UIButton()
  88. // button.frame = CGRect(x: self.view.centerX + 12, y: self.view.height - 42, width: 50, height: 16.5)
  89. // button.setTitle("立即注册", for: .normal)
  90. // button.titleLabel?.font = UIFont.systemFont(ofSize: 12)
  91. // button.setTitleColor(UIColor(netHex: 0x2DD0CF), for: .normal)
  92. // button.addTarget(self, action: #selector(_clickRegisterButton), for: .touchUpInside)
  93. // return button
  94. // }()
  95. //
  96. // private lazy var loginButton: UIButton = {
  97. // var button = UIButton()
  98. // button.backgroundColor = UIColor(netHex: 0x2DD0CF)
  99. // button.frame = CGRect(x: 38, y: 108 + 185 + 80, width: self.view.width - 76, height: 40)
  100. // button.layer.cornerRadius = 3.0
  101. // button.layer.masksToBounds = true
  102. // button.setTitle("登录", for: .normal)
  103. // button.addTarget(self, action: #selector(_userLogin), for: .touchUpInside)
  104. // return button
  105. // }()
  106. //
  107. // private lazy var tipsLabel: UILabel = {
  108. // var label = UILabel()
  109. // label.frame = CGRect(x: self.view.centerX - 62, y: self.view.height - 42, width: 74, height: 16.5)
  110. // label.text = "还没有账号?"
  111. // label.textColor = UIColor(netHex: 0x999999)
  112. // label.font = UIFont.systemFont(ofSize: 12)
  113. // return label
  114. // }()
  115. //
  116. // fileprivate lazy var passwordIcon: UIImageView = {
  117. // let imageView = UIImageView()
  118. // imageView.frame = CGRect(x: 38, y: 108 + 80 + 60 + 27 + 30 + 11 , width: 18, height: 18)
  119. // imageView.image = UIImage.loadImage("com_icon_password")
  120. // return imageView
  121. // }()
  122. //
  123. // fileprivate lazy var usernameIcon: UIImageView = {
  124. // let imageView = UIImageView()
  125. // imageView.frame = CGRect(x: 38, y: 108 + 80 + 60 + 11 , width: 18, height: 18)
  126. // imageView.image = UIImage.loadImage("com_icon_user_18")
  127. // return imageView
  128. // }()
  129. //
  130. // fileprivate lazy var usernameLine: UILabel = {
  131. // var line = UILabel()
  132. // line.backgroundColor = UIColor(netHex: 0x2DD0CF)
  133. // line.alpha = 0.4
  134. // line.frame = CGRect(x: 38, y: self.userNameTextField.y + 40, width: self.view.width - 76, height: 1)
  135. // return line
  136. // }()
  137. //
  138. // fileprivate lazy var passwordLine: UILabel = {
  139. // var line = UILabel()
  140. // line.backgroundColor = UIColor(netHex: 0x2DD0CF)
  141. // line.alpha = 0.4
  142. // line.frame = CGRect(x: 38, y: self.passwordTextField.y + 40, width: self.view.width - 76, height: 1)
  143. // return line
  144. // }()
  145. //
  146. // fileprivate lazy var bgView: UIView = UIView(frame: self.view.frame)
  147. //
  148. // //MARK: - private func
  149. // private func _init() {
  150. // self.title = "JChat"
  151. // view.backgroundColor = .white
  152. // UIApplication.shared.setStatusBarStyle(.default, animated: false)
  153. // automaticallyAdjustsScrollViewInsets = false
  154. // navigationController?.setNavigationBarHidden(true, animated: false)
  155. //
  156. // view.addSubview(bgView)
  157. // view.addSubview(headerView)
  158. // bgView.addSubview(avatorView)
  159. // bgView.addSubview(tipsLabel)
  160. // bgView.addSubview(userNameTextField)
  161. // bgView.addSubview(passwordTextField)
  162. // bgView.addSubview(loginButton)
  163. // bgView.addSubview(registerButton)
  164. // bgView.addSubview(usernameIcon)
  165. // bgView.addSubview(passwordIcon)
  166. // bgView.addSubview(usernameLine)
  167. // bgView.addSubview(passwordLine)
  168. //
  169. //
  170. // let tap = UITapGestureRecognizer(target: self, action: #selector(_tapView))
  171. // bgView.addGestureRecognizer(tap)
  172. //
  173. // _updateLoginButton()
  174. // }
  175. //
  176. // func _tapView() {
  177. // view.endEditing(true)
  178. // }
  179. //
  180. // //MARK: - click event
  181. // func _userLogin() {
  182. // let username = userNameTextField.text!.trim()
  183. // let password = passwordTextField.text!.trim()
  184. //
  185. // let validateUsername = UserDefaultValidationService.sharedValidationService.validateUsername(username)
  186. // if !(validateUsername == .ok) {
  187. // MBProgressHUD_JChat.show(text: validateUsername.description, view: view)
  188. // return
  189. // }
  190. //
  191. // let validatePassword = UserDefaultValidationService.sharedValidationService.validatePassword(password)
  192. // if !(validatePassword == .ok) {
  193. // MBProgressHUD_JChat.show(text: validatePassword.description, view: view)
  194. // return
  195. // }
  196. //
  197. // MBProgressHUD_JChat.showMessage(message: "登录中", toView: view)
  198. // JMSGUser.login(withUsername: username, password: password) { (result, error) in
  199. // MBProgressHUD_JChat.hide(forView: self.view, animated: true)
  200. // if error == nil {
  201. // UserDefaults.standard.set(username, forKey: kLastUserName)
  202. // JMSGUser.myInfo().thumbAvatarData({ (data, id, error) in
  203. // if let data = data {
  204. // let imageData = NSKeyedArchiver.archivedData(withRootObject: data)
  205. // UserDefaults.standard.set(imageData, forKey: kLastUserAvator)
  206. // } else {
  207. // UserDefaults.standard.removeObject(forKey: kLastUserAvator)
  208. // }
  209. // })
  210. // UserDefaults.standard.set(username, forKey: kCurrentUserName)
  211. // UserDefaults.standard.set(password, forKey: kCurrentUserPassword)
  212. // let appDelegate = UIApplication.shared.delegate
  213. // let window = appDelegate?.window!
  214. // window?.rootViewController = JCMainTabBarController()
  215. // } else {
  216. // MBProgressHUD_JChat.show(text: "\(String.errorAlert(error! as NSError))", view: self.view)
  217. // }
  218. // }
  219. // }
  220. //
  221. // func _clickRegisterButton() {
  222. // userNameTextField.resignFirstResponder()
  223. // passwordTextField.resignFirstResponder()
  224. // navigationController?.pushViewController(JCRegisterViewController(), animated: true)
  225. // }
  226. //
  227. // func textFieldDidChanged(_ textField: UITextField) {
  228. // if userNameTextField.text == lastUserName {
  229. // if avator != nil {
  230. // avatorView.image = avator
  231. // }
  232. // } else {
  233. // avatorView.image = UIImage.loadImage("com_icon_80")
  234. // }
  235. // }
  236. //
  237. // func _updateLoginButton() {
  238. // _ = userNameTextField.rx.textInput <-> textValue
  239. // let nameObserable = textValue.asObservable().map({$0.length > 0})
  240. // let pwdObserable = passwordTextField.rx.text.orEmpty.asObservable().shareReplay(1).map({$0.length > 0})
  241. // _ = Observable.combineLatest(nameObserable, pwdObserable) {$0 && $1}.subscribe(onNext: { (valid) in
  242. // if valid {
  243. // self.loginButton.isEnabled = true
  244. // self.loginButton.alpha = 1.0
  245. // } else {
  246. // self.loginButton.isEnabled = false
  247. // self.loginButton.alpha = 0.4
  248. // }
  249. // }).disposed(by: disposeBag)
  250. // }
  251. //
  252. //}
  253. //
  254. //extension JCLoginViewController: UITextFieldDelegate {
  255. // func textFieldDidBeginEditing(_ textField: UITextField) {
  256. // if textField.tag == 1001 {
  257. // usernameLine.alpha = 1.0
  258. // usernameIcon.image = UIImage.loadImage("com_icon_user_18_pre")
  259. // } else {
  260. // passwordLine.alpha = 1.0
  261. // passwordIcon.image = UIImage.loadImage("com_icon_password_pre")
  262. // }
  263. //
  264. // UIView.animate(withDuration: 0.3, animations: {
  265. // self.avatorView.isHidden = true
  266. // self.headerView.frame = CGRect(x: 0, y: 0, width: self.view.width, height: 64)
  267. // self.bgView.frame = CGRect(x: 0, y: -100, width: self.view.width, height: self.view.height)
  268. // })
  269. // }
  270. //
  271. // func textFieldDidEndEditing(_ textField: UITextField) {
  272. // if textField.tag == 1001 {
  273. // usernameLine.alpha = 0.4
  274. // usernameIcon.image = UIImage.loadImage("com_icon_user_18")
  275. // } else {
  276. // passwordLine.alpha = 0.4
  277. // passwordIcon.image = UIImage.loadImage("com_icon_password")
  278. // }
  279. //
  280. // UIView.animate(withDuration: 0.3) {
  281. // self.avatorView.isHidden = false
  282. // self.headerView.frame = CGRect(x: 0, y: -64, width: self.view.width, height: 64)
  283. // self.bgView.frame = CGRect(x: 0, y: 0, width: self.view.width, height: self.view.height)
  284. // }
  285. // }
  286. //
  287. //}