YMVerifyCodeLoginView.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. //
  2. // YMVerifyCodeLoginView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/4.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMVerifyCodeLoginView.h"
  9. #import "YMVerifyCodeLoginViewModel.h"
  10. @interface YMVerifyCodeLoginView ()
  11. /// 验证码登录VM
  12. @property (nonatomic, strong) YMVerifyCodeLoginViewModel *viewModel;
  13. /// 手机视图
  14. @property (nonatomic, strong) UIView *mobileView;
  15. /// 手机号标签
  16. @property (nonatomic, strong) UILabel *mobileLb;
  17. /// 手机号输入框
  18. @property (nonatomic, strong) UITextField *mobileInputBox;
  19. /// 验证码视图
  20. @property (nonatomic, strong) UIView *verifyCodeView;
  21. /// 验证码标签
  22. @property (nonatomic, strong) UILabel *verifyCodeLb;
  23. /// 验证码输入框
  24. @property (nonatomic, strong) UITextField *verifyCodeInputBox;
  25. /// 获取验证码
  26. @property (nonatomic, strong) YMCaptchaCountdownButton *getVerifyCodeBtn;
  27. /// 协议视图
  28. @property (nonatomic, strong) UIView *agreementView;
  29. /// 单选按钮
  30. @property (nonatomic, strong) UIButton *radioBtn;
  31. /// 协议标签
  32. @property (nonatomic, strong) YYLabel *agreementLb;
  33. /// 登录按钮
  34. @property (nonatomic, strong) UIButton *loginBtn;
  35. /** 注册按钮*/
  36. @property (nonatomic, strong) UIButton *registerBtn;
  37. @end
  38. @implementation YMVerifyCodeLoginView
  39. - (void)ym_setupViews{
  40. [self addSubview:self.mobileView];
  41. [self.mobileView addSubview:self.mobileLb];
  42. [self.mobileView addSubview:self.mobileInputBox];
  43. [self addSubview:self.verifyCodeView];
  44. [self.verifyCodeView addSubview:self.verifyCodeLb];
  45. [self.verifyCodeView addSubview:self.verifyCodeInputBox];
  46. [self.verifyCodeView addSubview:self.getVerifyCodeBtn];
  47. [self addSubview:self.agreementView];
  48. [self.agreementView addSubview:self.radioBtn];
  49. [self.agreementView addSubview:self.agreementLb];
  50. [self addSubview:self.loginBtn];
  51. [self addSubview:self.registerBtn];
  52. [self setNeedsUpdateConstraints];
  53. [self updateConstraintsIfNeeded];
  54. }
  55. - (void)updateConstraints{
  56. [self.mobileView mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.top.equalTo(self).offset(adapt(24));
  58. make.left.equalTo(self).offset(adapt(28));
  59. make.right.equalTo(self).offset(adapt(-28));
  60. }];
  61. [self.mobileLb mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.top.equalTo(self.mobileView);
  63. make.left.equalTo(self.mobileView);
  64. }];
  65. [self.mobileInputBox mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.top.equalTo(self.mobileLb.mas_bottom).offset(adapt(10));
  67. make.left.equalTo(self.mobileView);
  68. make.right.equalTo(self.mobileView);
  69. make.bottom.equalTo(self.mobileView);
  70. make.height.mas_equalTo(adapt(30));
  71. }];
  72. [self.verifyCodeView mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.top.equalTo(self.mobileView.mas_bottom).offset(adapt(24));
  74. make.left.equalTo(self.mobileView.mas_left);
  75. make.right.equalTo(self.mobileView.mas_right);
  76. }];
  77. [self.verifyCodeLb mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.top.equalTo(self.verifyCodeView);
  79. make.left.equalTo(self.verifyCodeView);
  80. }];
  81. [self.verifyCodeInputBox mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.top.equalTo(self.verifyCodeLb.mas_bottom).offset(adapt(10));
  83. make.left.equalTo(self.verifyCodeView);
  84. make.bottom.equalTo(self.verifyCodeView);
  85. make.height.mas_equalTo(adapt(30));
  86. }];
  87. [self.getVerifyCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.top.equalTo(self.verifyCodeLb.mas_bottom).offset(adapt(10));
  89. make.left.equalTo(self.verifyCodeInputBox.mas_right).offset(adapt(5));
  90. make.right.equalTo(self.verifyCodeView);
  91. make.bottom.equalTo(self.verifyCodeView);
  92. make.width.mas_equalTo(adapt(100));
  93. }];
  94. [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.top.equalTo(self.verifyCodeView.mas_bottom).offset(adapt(24));
  96. make.left.equalTo(self.mobileView.mas_left);
  97. make.right.equalTo(self.mobileView.mas_right);
  98. make.height.mas_equalTo(adapt(40));
  99. }];
  100. [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.centerX.equalTo(self.loginBtn.mas_centerX);
  102. make.top.equalTo(self.loginBtn.mas_bottom).offset(adapt(16));
  103. make.height.mas_equalTo(adapt(25));
  104. }];
  105. [self.agreementView mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.centerX.equalTo(self.mas_centerX);
  107. make.bottom.equalTo(self).offset(Is_iPhoneX ? adapt(-32) : adapt(-12));
  108. }];
  109. [self.radioBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.centerY.equalTo(self.agreementLb.mas_centerY);
  111. make.left.equalTo(self.agreementView).offset(adapt(5));
  112. make.width.height.mas_equalTo(adapt(12));
  113. }];
  114. [self.agreementLb mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.top.equalTo(self.agreementView).offset(adapt(10));
  116. make.left.equalTo(self.radioBtn.mas_right).offset(adapt(5));
  117. make.right.equalTo(self.agreementView).offset(adapt(-5));
  118. make.bottom.equalTo(self.agreementView).offset(adapt(-10));
  119. }];
  120. [super updateConstraints];
  121. }
  122. - (void)ym_bindViewModel:(YMVerifyCodeLoginViewModel *)viewModel{
  123. if (!viewModel) {
  124. return;
  125. }
  126. _viewModel = viewModel;
  127. RAC(self.viewModel , mobile) = [[RACSignal merge:@[RACObserve(self.mobileInputBox, text),self.mobileInputBox.rac_textSignal]] takeUntil:self.rac_willDeallocSignal];
  128. RAC(self.viewModel , verifyCode) = [[RACSignal merge:@[RACObserve(self.verifyCodeInputBox, text),self.verifyCodeInputBox.rac_textSignal]]takeUntil:self.rac_willDeallocSignal];
  129. RAC(self.loginBtn , enabled) = self.viewModel.validLoginSignal;
  130. [self.viewModel.validLoginSignal subscribeNext:^(id _Nullable value) {
  131. self.loginBtn.enabled = [value boolValue];
  132. if ([value boolValue]) {
  133. self.loginBtn.alpha = 1;
  134. } else {
  135. self.loginBtn.alpha = 0.5;
  136. }
  137. }];
  138. }
  139. - (UIView *)mobileView{
  140. if (!_mobileView) {
  141. _mobileView = [[UIView alloc]init];
  142. }
  143. return _mobileView;
  144. }
  145. - (UILabel *)mobileLb{
  146. if (!_mobileLb) {
  147. _mobileLb = [[UILabel alloc]init];
  148. _mobileLb.font = LCBoldFont(17);
  149. _mobileLb.textColor = HexColorFromRGB(0x1B2739);
  150. _mobileLb.textAlignment = NSTextAlignmentLeft;
  151. _mobileLb.text = @"手机号";
  152. }
  153. return _mobileLb;
  154. }
  155. - (UITextField *)mobileInputBox{
  156. if (!_mobileInputBox) {
  157. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  158. style.minimumLineHeight = 0;
  159. NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入手机号"];
  160. placeholderAttributed.yy_paragraphStyle = style;
  161. placeholderAttributed.yy_font = LCFont(14);
  162. placeholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  163. _mobileInputBox = [[UITextField alloc]init];
  164. _mobileInputBox.attributedPlaceholder = placeholderAttributed;
  165. _mobileInputBox.clearButtonMode = UITextFieldViewModeWhileEditing;
  166. _mobileInputBox.autocorrectionType = UITextAutocorrectionTypeDefault;
  167. _mobileInputBox.autocapitalizationType = UITextAutocapitalizationTypeNone;
  168. _mobileInputBox.keyboardType = UIKeyboardTypePhonePad;
  169. _mobileInputBox.ba_maxLength = 11;
  170. }
  171. return _mobileInputBox;
  172. }
  173. - (UIView *)verifyCodeView{
  174. if (!_verifyCodeView) {
  175. _verifyCodeView = [[UIView alloc]init];
  176. }
  177. return _verifyCodeView;
  178. }
  179. - (UILabel *)verifyCodeLb{
  180. if (!_verifyCodeLb) {
  181. _verifyCodeLb = [[UILabel alloc]init];
  182. _verifyCodeLb.font = LCBoldFont(17);
  183. _verifyCodeLb.textColor = HexColorFromRGB(0x1B2739);
  184. _verifyCodeLb.textAlignment = NSTextAlignmentLeft;
  185. _verifyCodeLb.text = @"验证码";
  186. }
  187. return _verifyCodeLb;
  188. }
  189. - (UITextField *)verifyCodeInputBox{
  190. if (!_verifyCodeInputBox) {
  191. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  192. style.minimumLineHeight = 0;
  193. NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入验证码"];
  194. placeholderAttributed.yy_paragraphStyle = style;
  195. placeholderAttributed.yy_font = LCFont(14);
  196. placeholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  197. _verifyCodeInputBox = [[UITextField alloc]init];
  198. _verifyCodeInputBox.attributedPlaceholder = placeholderAttributed;
  199. _verifyCodeInputBox.clearButtonMode = UITextFieldViewModeWhileEditing;
  200. _verifyCodeInputBox.autocorrectionType = UITextAutocorrectionTypeDefault;
  201. _verifyCodeInputBox.autocapitalizationType = UITextAutocapitalizationTypeNone;
  202. _verifyCodeInputBox.keyboardType = UIKeyboardTypeDecimalPad;
  203. _verifyCodeInputBox.ba_maxLength = 4;
  204. }
  205. return _verifyCodeInputBox;
  206. }
  207. - (YMCaptchaCountdownButton *)getVerifyCodeBtn{
  208. if (!_getVerifyCodeBtn) {
  209. _getVerifyCodeBtn = [YMCaptchaCountdownButton buttonWithType:UIButtonTypeCustom];
  210. _getVerifyCodeBtn.titleLabel.font = LCFont(14);
  211. [_getVerifyCodeBtn setTitleColor:MainColor forState:UIControlStateNormal];
  212. [_getVerifyCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
  213. [_getVerifyCodeBtn countDownButtonHandler:^(YMCaptchaCountdownButton *sender, NSInteger tag) {
  214. if (OCStringIsEmpty(self.mobileInputBox.text)) {
  215. [ZCHUDHelper showTitle:@"请输入手机号"];
  216. return;
  217. }
  218. [self.mobileInputBox resignFirstResponder];
  219. [self.verifyCodeInputBox resignFirstResponder];
  220. [self.verifyCodeInputBox resignFirstResponder];
  221. [self.viewModel getVerifyCodeHandler:^(NSDictionary * _Nonnull dic, NSError * _Nullable error) {
  222. sender.enabled = NO;
  223. [sender startCountDownWithSecond:59];
  224. [sender countDownChanging:^NSString *(YMCaptchaCountdownButton *countDownButton, NSUInteger second) {
  225. NSString *title = [NSString stringWithFormat:@"重新发送(%zds)",second];
  226. return title;
  227. }];
  228. [sender countDownFinished:^NSString *(YMCaptchaCountdownButton *countDownButton, NSUInteger second) {
  229. countDownButton.enabled = YES;
  230. return @"重新发送";
  231. }];
  232. }];
  233. }];
  234. }
  235. return _getVerifyCodeBtn;
  236. }
  237. - (UIView *)agreementView{
  238. if (!_agreementView) {
  239. _agreementView = [[UIView alloc]init];
  240. }
  241. return _agreementView;
  242. }
  243. - (UIButton *)radioBtn{
  244. if (!_radioBtn) {
  245. _radioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  246. [_radioBtn setBackgroundImage:ImageByName(@"ym_login_auth_normal_icon") forState:UIControlStateNormal];
  247. [_radioBtn setBackgroundImage:ImageByName(@"ym_login_auth_selected_icon") forState:UIControlStateSelected];
  248. WS(weakSelf)
  249. [[[_radioBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  250. sender.selected = !sender.selected;
  251. }];
  252. }
  253. return _radioBtn;
  254. }
  255. - (YYLabel *)agreementLb{
  256. if (!_agreementLb) {
  257. _agreementLb = [[YYLabel alloc] init];
  258. _agreementLb.numberOfLines = 0;
  259. _agreementLb.preferredMaxLayoutWidth = kFrameWidth - adapt(55);
  260. NSString *agreementText = @"同意《用户协议》和《隐私协议》";
  261. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
  262. paragraphStyle.alignment = NSTextAlignmentLeft;
  263. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:agreementText];
  264. attributedString.yy_font = LCFont(11);
  265. attributedString.yy_color = HexColorFromRGB(0x7E848D);
  266. attributedString.yy_paragraphStyle = paragraphStyle;
  267. //设置高亮色和点击事件
  268. [attributedString yy_setTextHighlightRange:[agreementText rangeOfString:@"《用户协议》"] color:HexColorFromRGB(0xB26AFD) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  269. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  270. ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserProtocolH5]
  271. }];
  272. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  273. RouterViewModel:webArticleVM
  274. } completion:nil];
  275. }];
  276. //设置高亮色和点击事件
  277. [attributedString yy_setTextHighlightRange:[[attributedString string] rangeOfString:@"《隐私协议》"] color:HexColorFromRGB(0xB26AFD) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  278. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  279. ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserPrivacyH5]
  280. }];
  281. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  282. RouterViewModel:webArticleVM
  283. } completion:nil];
  284. }];
  285. _agreementLb.attributedText = attributedString;
  286. }
  287. return _agreementLb;
  288. }
  289. - (UIButton *)loginBtn{
  290. if (!_loginBtn) {
  291. _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  292. _loginBtn.titleLabel.font = LCBoldFont(15);
  293. [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
  294. [_loginBtn setTitleColor:kMainGradTitleC forState:UIControlStateNormal];
  295. [_loginBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  296. _loginBtn.layer.cornerRadius = adapt(40)/2;
  297. WS(weakSelf)
  298. [[[_loginBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  299. if (OCStringIsEmpty(weakSelf.mobileInputBox.text)) {
  300. [ZCHUDHelper showTitle:@"请输入手机号"];
  301. return;
  302. }
  303. if (OCStringIsEmpty(weakSelf.verifyCodeInputBox.text)) {
  304. [ZCHUDHelper showTitle:@"请输入验证码"];
  305. return;
  306. }
  307. if (!weakSelf.radioBtn.selected) {
  308. YMLoginRegistrAgreementPopupView *customView = [[YMLoginRegistrAgreementPopupView alloc]init];
  309. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  310. popupView.priority = 999;
  311. popupView.cornerRadius = adapt(10);
  312. popupView.rectCorners = UIRectCornerAllCorners;
  313. popupView.positionStyle = YMPositionStyleCenter;
  314. popupView.isHideBg = NO;
  315. popupView.bgAlpha = 0.3;
  316. [popupView pop];
  317. @weakify(popupView)
  318. customView.buttonBlock = ^(BOOL isConfirm) {
  319. @strongify(popupView)
  320. if (isConfirm) {
  321. weakSelf.radioBtn.selected = YES;
  322. [weakSelf.viewModel loginRequest];
  323. }
  324. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  325. };
  326. customView.dismissBlock = ^{
  327. @strongify(popupView)
  328. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  329. };
  330. return;
  331. }
  332. [weakSelf.viewModel loginRequest];
  333. }];
  334. }
  335. return _loginBtn;
  336. }
  337. - (UIButton *)registerBtn{
  338. if (!_registerBtn) {
  339. _registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  340. _registerBtn.titleLabel.font = LCFont(14);
  341. [_registerBtn setTitle:@"新用户注册" forState:UIControlStateNormal];
  342. [_registerBtn setTitleColor:HexColorFromRGB(0xB26AFD) forState:UIControlStateNormal];
  343. WS(weakSelf)
  344. [[[_registerBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  345. [weakSelf.viewModel gotoRegisterVC];
  346. }];
  347. }
  348. return _registerBtn;
  349. }
  350. @end