MOLoginPhoneVC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. //
  2. // MOLoginPhoneVC.m
  3. // MiMoLive
  4. //
  5. // Created by MiMo on 2025/6/3.
  6. //
  7. #import "MOLoginPhoneVC.h"
  8. #import "UIImage+YYAdd.h"
  9. #import "MOSelectPartitionVC.h"
  10. #import "MOVerifyCodeVC.h"
  11. #import "MOThirdPartyLoginView.h"
  12. #import "MOLoginPasswordVC.h"
  13. #import "MOLoginManager.h"
  14. #import "UITextField+CustomClearButton.h"
  15. @interface MOLoginPhoneVC ()
  16. @property (nonatomic, strong) UIImageView *bgImgView;
  17. @property (nonatomic, strong) BigBtn *backButton;
  18. @property (nonatomic, strong) UILabel *titleLabel;
  19. @property (nonatomic, strong) UILabel *subTitleLabel;
  20. @property (nonatomic, strong) UIImageView *phoneView;
  21. @property (nonatomic, strong) UIButton *chooseCountryBtn;
  22. @property (nonatomic, strong) UITextField *phoneField;
  23. @property (nonatomic, strong) UILabel *descLabel;
  24. @property (nonatomic, strong) UIButton *getCodeButton;
  25. @property (nonatomic, strong) UIButton *passwordLoginButton;
  26. @property (nonatomic, strong) UILabel *loginTypeLabel;
  27. @property (nonatomic, strong) MOThirdPartyLoginView *loginTypeView;
  28. @property (nonatomic, copy) NSString *countryIp;
  29. @end
  30. @implementation MOLoginPhoneVC
  31. - (void)viewWillAppear:(BOOL)animated {
  32. [super viewWillAppear:animated];
  33. [self.navigationController setNavigationBarHidden:YES animated:animated];
  34. }
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. [self setupUI];
  38. [self setupCountryCode];
  39. }
  40. - (void)setupCountryCode {
  41. WEAKSELF
  42. [[MOLoginManager shareManager] getCountryIpComplete:^(NSString * _Nonnull ip) {
  43. [weakSelf.chooseCountryBtn setTitle:ip forState:UIControlStateNormal];
  44. weakSelf.countryIp = ip;
  45. }];
  46. }
  47. - (void)setupUI {
  48. [self.view addSubview:self.bgImgView];
  49. [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.edges.mas_equalTo(0);
  51. }];
  52. [self.view addSubview:self.backButton];
  53. [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.mas_equalTo(kTopSafeAreaInset + 10);
  55. make.left.mas_equalTo(12);
  56. make.size.mas_equalTo(CGSizeMake(30, 30));
  57. }];
  58. [self.view addSubview:self.titleLabel];
  59. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.equalTo(self.backButton.mas_bottom).offset(36);
  61. make.left.mas_equalTo(24);
  62. make.right.mas_equalTo(-15);
  63. }];
  64. [self.view addSubview:self.subTitleLabel];
  65. [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.top.equalTo(self.titleLabel.mas_bottom).offset(8);
  67. make.left.mas_equalTo(24);
  68. make.right.mas_equalTo(-15);
  69. }];
  70. [self.view addSubview:self.phoneView];
  71. [self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.top.equalTo(self.subTitleLabel.mas_bottom).offset(24);
  73. make.left.mas_equalTo(24);
  74. make.right.mas_equalTo(-24);
  75. make.height.mas_equalTo(52);
  76. }];
  77. [self.view addSubview:self.descLabel];
  78. [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.top.equalTo(self.phoneView.mas_bottom).offset(4);
  80. make.left.mas_equalTo(24);
  81. make.right.mas_equalTo(-24);
  82. }];
  83. [self.view addSubview:self.getCodeButton];
  84. [self.getCodeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.top.equalTo(self.descLabel.mas_bottom).offset(24);
  86. make.left.mas_equalTo(24);
  87. make.right.mas_equalTo(-24);
  88. }];
  89. [self.view addSubview:self.passwordLoginButton];
  90. [self.passwordLoginButton mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.top.equalTo(self.getCodeButton.mas_bottom).offset(10);
  92. make.left.mas_equalTo(24);
  93. }];
  94. [self.view addSubview:self.loginTypeView];
  95. [self.loginTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.bottom.mas_equalTo(-kBottomSafeAreaInset - 16);
  97. make.centerX.mas_equalTo(0);
  98. make.height.mas_equalTo(42);
  99. }];
  100. [self.view addSubview:self.loginTypeLabel];
  101. [self.loginTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.centerX.mas_equalTo(0);
  103. make.bottom.equalTo(self.loginTypeView.mas_top).offset(-20);
  104. }];
  105. }
  106. #pragma mark - Actions
  107. - (void)phoneFieldDidChange:(UITextField *)textField {
  108. NSString *text = textField.text;
  109. // self.getCodeButton.enabled = text.length > 0;
  110. self.getCodeButton.alpha = text.length > 0 ? 1.0 : 0.5;
  111. }
  112. - (void)backButtonAction {
  113. [self.navigationController popViewControllerAnimated:YES];
  114. }
  115. - (void)passwordLoginButtonAction {
  116. MOLoginPasswordVC *vc = [[MOLoginPasswordVC alloc] init];
  117. vc.countryIp = self.countryIp;
  118. WEAKSELF
  119. vc.chooseBlock = ^(NSString * _Nonnull countryIp) {
  120. weakSelf.countryIp = countryIp;
  121. CGFloat textWidth = countryIp.length * 15 + 8;
  122. if (textWidth < 55) {
  123. textWidth = 55;
  124. }
  125. [self.chooseCountryBtn mas_updateConstraints:^(MASConstraintMaker *make) {
  126. make.width.mas_equalTo(textWidth);
  127. }];
  128. [weakSelf.chooseCountryBtn setTitle:countryIp forState:UIControlStateNormal];
  129. };
  130. [self.navigationController pushViewController:vc animated:YES];
  131. }
  132. - (void)chooseCountryBtnAction {
  133. MOSelectPartitionVC *vc = [[MOSelectPartitionVC alloc] init];
  134. //MARK: 选择区号回调
  135. WEAKSELF
  136. vc.selectCellBlock = ^(MOCountryList * _Nonnull model) {
  137. CGFloat textWidth = model.num.length * 15 + 8;
  138. [self.chooseCountryBtn mas_updateConstraints:^(MASConstraintMaker *make) {
  139. make.width.mas_equalTo(textWidth);
  140. }];
  141. [weakSelf.chooseCountryBtn setTitle:model.num forState:UIControlStateNormal];
  142. weakSelf.countryIp = model.num;
  143. };
  144. [self.navigationController pushViewController:vc animated:YES];
  145. }
  146. - (void)getCodeButtonAction {
  147. WEAKSELF
  148. [self sendSmsClickAndBlock:^(BOOL isSuccess) {
  149. if (isSuccess) {
  150. MOVerifyCodeVC *vc = [[MOVerifyCodeVC alloc] init];
  151. [vc setupCountryCode:self.chooseCountryBtn.currentTitle phone:self.phoneField.text];
  152. [weakSelf.navigationController pushViewController:vc animated:YES];
  153. }
  154. }];
  155. }
  156. -(void)sendSmsClickAndBlock:(void (^)(BOOL isSuccess))block{
  157. if(self.phoneField.text.length == 0)
  158. {
  159. [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_phone")];
  160. return;
  161. }
  162. [MBProgressHUD showActivityMessageInView:@""];
  163. WEAKSELF
  164. NSDictionary *dic = @{@"code":self.chooseCountryBtn.titleLabel.text,
  165. @"num":self.phoneField.text};
  166. [kHttpManager loginAndGetMobileCodeWithParams:dic andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  167. [MBProgressHUD hideHUD];
  168. if(kCode_Success){
  169. // [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_verify_code")];
  170. block ? block(YES) : nil;
  171. }
  172. else{
  173. kShowNetError(data)
  174. block ? block(NO) : nil;
  175. }
  176. }];
  177. }
  178. - (UIImageView *)bgImgView {
  179. if (!_bgImgView) {
  180. _bgImgView = [[UIImageView alloc] init];
  181. _bgImgView.image = [UIImage imageNamed:@"img_login_bg"];
  182. }
  183. return _bgImgView;
  184. }
  185. - (BigBtn *)backButton {
  186. if (!_backButton) {
  187. _backButton = [[BigBtn alloc] init];
  188. [_backButton setImage:[UIImage imageNamed:@"icon_login_back_white"] forState:UIControlStateNormal];
  189. [_backButton addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
  190. }
  191. return _backButton;
  192. }
  193. - (UILabel *)titleLabel {
  194. if (!_titleLabel) {
  195. _titleLabel = [[UILabel alloc] init];
  196. _titleLabel.text = NSLocalString(@"mimo_login_title");
  197. _titleLabel.font = [MOTextTools poppinsBoldFont:24];
  198. _titleLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
  199. _titleLabel.numberOfLines = 1;
  200. _titleLabel.adjustsFontSizeToFitWidth = YES;
  201. }
  202. return _titleLabel;
  203. }
  204. - (UILabel *)subTitleLabel {
  205. if (!_subTitleLabel) {
  206. _subTitleLabel = [[UILabel alloc] init];
  207. _subTitleLabel.text = NSLocalString(@"mimo_login_subtitle");
  208. _subTitleLabel.font = [MOTextTools poppinsBoldFont:24];
  209. _subTitleLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
  210. _subTitleLabel.numberOfLines = 1;
  211. _subTitleLabel.adjustsFontSizeToFitWidth = YES;
  212. }
  213. return _subTitleLabel;
  214. }
  215. - (UIImageView *)phoneView {
  216. if (!_phoneView) {
  217. _phoneView = [[UIImageView alloc] init];
  218. _phoneView.image = [[UIImage imageNamed:@"img_login_tf_bg"] resizeImageByCenter];
  219. _phoneView.userInteractionEnabled = YES;
  220. [_phoneView addSubview:self.chooseCountryBtn];
  221. [self.chooseCountryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  222. make.left.mas_equalTo(12);
  223. make.centerY.mas_equalTo(0);
  224. make.width.mas_equalTo(55);
  225. }];
  226. [_phoneView addSubview:self.phoneField];
  227. [self.phoneField mas_makeConstraints:^(MASConstraintMaker *make) {
  228. make.left.equalTo(self.chooseCountryBtn.mas_right).offset(5);
  229. make.right.mas_equalTo(-12);
  230. make.centerY.mas_equalTo(0);
  231. }];
  232. }
  233. return _phoneView;
  234. }
  235. - (UIButton *)chooseCountryBtn {
  236. if (!_chooseCountryBtn) {
  237. _chooseCountryBtn = [[UIButton alloc] init];
  238. _chooseCountryBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  239. _chooseCountryBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0);
  240. _chooseCountryBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 4);
  241. [_chooseCountryBtn setImage:[UIImage imageNamed:@"icon_login_arrow_down"] forState:UIControlStateNormal];
  242. _chooseCountryBtn.titleLabel.font = [MOTextTools poppinsMediumFont:18];
  243. [_chooseCountryBtn setTitleColor:[MOTools colorWithHexString:@"#111111"] forState:UIControlStateNormal];
  244. [_chooseCountryBtn addTarget:self action:@selector(chooseCountryBtnAction) forControlEvents:UIControlEventTouchUpInside];
  245. [_chooseCountryBtn setTitle:@"+62" forState:UIControlStateNormal];
  246. }
  247. return _chooseCountryBtn;
  248. }
  249. - (UITextField *)phoneField {
  250. if (!_phoneField) {
  251. _phoneField = [[UITextField alloc] init];
  252. _phoneField.keyboardType = UIKeyboardTypeNumberPad;
  253. _phoneField.textColor = [MOTools colorWithHexString:@"#111111"];
  254. _phoneField.font = [MOTextTools poppinsMediumFont:18];
  255. _phoneField.clearButtonMode = UITextFieldViewModeNever;
  256. UIImage *clearIcon = [UIImage imageNamed:@"icon_textfield_clear"];
  257. [_phoneField enableCustomClearButtonWithImage:clearIcon];
  258. NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:NSLocalString(@"mimo_login_hint_phone") attributes:@{
  259. NSForegroundColorAttributeName : [MOTools colorWithHexString:@"#DADCE6"],
  260. NSFontAttributeName : [MOTextTools poppinsRegularFont:16]
  261. }];
  262. _phoneField.attributedPlaceholder = placeholderString;
  263. [_phoneField addTarget:self action:@selector(phoneFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  264. }
  265. return _phoneField;
  266. }
  267. - (UILabel *)descLabel {
  268. if (!_descLabel) {
  269. _descLabel = [[UILabel alloc] init];
  270. _descLabel.text = NSLocalString(@"mimo_login_hint_register_tip");
  271. _descLabel.textColor = kBaseTextColor_3;
  272. _descLabel.font = [MOTextTools regularFont:11];
  273. _descLabel.numberOfLines = 0;
  274. }
  275. return _descLabel;
  276. }
  277. - (UIButton *)getCodeButton {
  278. if (!_getCodeButton) {
  279. _getCodeButton = [[UIButton alloc] init];
  280. NSArray *loginColorArr = @[kBaseColorLeft,kBaseColorRight];
  281. UIImage *loginImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 24.0 * 2), 48.0) Colors:loginColorArr GradientType:0];
  282. [_getCodeButton setBackgroundImage:loginImage forState:UIControlStateNormal];
  283. _getCodeButton.layer.cornerRadius = 12;
  284. _getCodeButton.layer.masksToBounds = YES;
  285. [_getCodeButton setTitle:NSLocalString(@"mimo_verify_code_get") forState:UIControlStateNormal];
  286. [_getCodeButton setTitleColor:[MOTools colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  287. _getCodeButton.titleLabel.font = [MOTextTools poppinsSemiBoldFont:16];
  288. [_getCodeButton addTarget:self action:@selector(getCodeButtonAction) forControlEvents:UIControlEventTouchUpInside];
  289. _getCodeButton.alpha = 0.5;
  290. }
  291. return _getCodeButton;
  292. }
  293. - (UIButton *)passwordLoginButton {
  294. if (!_passwordLoginButton) {
  295. _passwordLoginButton = [[UIButton alloc] init];
  296. _passwordLoginButton.titleLabel.font = [MOTextTools regularFont:14];
  297. [_passwordLoginButton setTitleColor:kBaseTextColor_3 forState:UIControlStateNormal];
  298. [_passwordLoginButton setTitle:NSLocalString(@"mimo_login_pwd") forState:UIControlStateNormal];
  299. [_passwordLoginButton addTarget:self action:@selector(passwordLoginButtonAction) forControlEvents:UIControlEventTouchUpInside];
  300. }
  301. return _passwordLoginButton;
  302. }
  303. - (UILabel *)loginTypeLabel {
  304. if (!_loginTypeLabel) {
  305. _loginTypeLabel = [[UILabel alloc] init];
  306. _loginTypeLabel.text = NSLocalString(@"mimo_login_third_party");
  307. _loginTypeLabel.font = [MOTextTools regularFont:14];
  308. _loginTypeLabel.textColor = kBaseTextColor_3;
  309. }
  310. return _loginTypeLabel;
  311. }
  312. - (MOThirdPartyLoginView *)loginTypeView {
  313. if (!_loginTypeView) {
  314. _loginTypeView = [[MOThirdPartyLoginView alloc] init];
  315. _loginTypeView.loginChooseBlock = ^(MOThirdPartyType type) {
  316. if (type == MOThirdPartyTypeAp) {
  317. [[MOLoginManager shareManager] loginWithApple];
  318. } else if (type == MOThirdPartyTypeFb) {
  319. [[MOLoginManager shareManager] loginWithFacebook];
  320. } else if (type == MOThirdPartyTypeGg) {
  321. [[MOLoginManager shareManager] loginWithGoogle];
  322. }
  323. };
  324. }
  325. return _loginTypeView;
  326. }
  327. @end