YMRetrievePasswordView.m 19 KB

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