YMRegisterView.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. //
  2. // YMRegisterView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/5.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMRegisterView.h"
  9. #import "YMRegisterViewModel.h"
  10. #import "YMCaptchaPopupView.h"
  11. #import "CaptchaCenter.h"
  12. @interface YMRegisterView ()
  13. /// 注册VM
  14. @property (nonatomic, strong) YMRegisterViewModel *viewModel;
  15. /// 背景图
  16. @property (nonatomic, strong) UIImageView *bgImgv;
  17. /// 注册提示
  18. /// 注册提示标签
  19. @property (nonatomic, strong) UILabel *registerTipsLb1;
  20. /// 注册提示标签
  21. @property (nonatomic, strong) UILabel *registerTipsLb2;
  22. @property (nonatomic, strong) UILabel *titleLb;
  23. @property (nonatomic, strong) UILabel *titleLine;
  24. /// 手机视图
  25. @property (nonatomic, strong) UIView *mobileView;
  26. /// 手机号标签
  27. @property (nonatomic, strong) UILabel *mobileLb;
  28. /// 手机号输入框
  29. @property (nonatomic, strong) UITextField *mobileInputBox;
  30. /// 验证码视图
  31. @property (nonatomic, strong) UIView *verifyCodeView;
  32. /// 验证码标签
  33. @property (nonatomic, strong) UILabel *verifyCodeLb;
  34. /// 验证码输入框
  35. @property (nonatomic, strong) UITextField *verifyCodeInputBox;
  36. /// 获取验证码
  37. @property (nonatomic, strong) YMCaptchaCountdownButton *getVerifyCodeBtn;
  38. /// 密码视图
  39. @property (nonatomic, strong) UIView *passwordView;
  40. /// 密码标签
  41. @property (nonatomic, strong) UILabel *passwordLb;
  42. /// 密码输入框
  43. @property (nonatomic, strong) UITextField *passwordInputBox;
  44. /// 协议视图
  45. @property (nonatomic, strong) UIView *agreementView;
  46. /// 单选按钮
  47. @property (nonatomic, strong) UIButton *radioBtn;
  48. /// 协议标签
  49. @property (nonatomic, strong) YYLabel *agreementLb;
  50. /// 确定按钮
  51. @property (nonatomic, strong) UIButton *registerBtn;
  52. @end
  53. @implementation YMRegisterView
  54. - (instancetype)initWithFrame:(CGRect)frame{
  55. self = [super initWithFrame:frame];
  56. if (self) {
  57. }
  58. return self;
  59. }
  60. - (void)ym_setupViews{
  61. [self addSubview:self.bgImgv];
  62. [self addSubview:self.registerTipsLb1];
  63. [self addSubview:self.registerTipsLb2];
  64. [self addSubview:self.titleLb];
  65. [self addSubview:self.titleLine];
  66. [self addSubview:self.mobileLb];
  67. [self addSubview:self.mobileView];
  68. [self addSubview:self.mobileInputBox];
  69. [self addSubview:self.verifyCodeView];
  70. [self addSubview:self.verifyCodeLb];
  71. [self addSubview:self.verifyCodeInputBox];
  72. [self addSubview:self.getVerifyCodeBtn];
  73. [self addSubview:self.passwordView];
  74. [self addSubview:self.passwordLb];
  75. [self addSubview:self.passwordInputBox];
  76. [self addSubview:self.agreementView];
  77. [self.agreementView addSubview:self.radioBtn];
  78. [self.agreementView addSubview:self.agreementLb];
  79. [self addSubview:self.registerBtn];
  80. [self setNeedsUpdateConstraints];
  81. [self updateConstraintsIfNeeded];
  82. }
  83. - (void)updateConstraints{
  84. [self.registerTipsLb1 mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.top.equalTo(self).offset(adapt(96));
  86. make.left.equalTo(self).offset(adapt(30));
  87. make.right.equalTo(self).offset(adapt(-30));
  88. }];
  89. [self.registerTipsLb2 mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.top.equalTo(self.registerTipsLb1.mas_bottom).offset(adapt(5));
  91. make.left.equalTo(self).offset(adapt(30));
  92. make.right.equalTo(self).offset(adapt(-30));
  93. }];
  94. [self.bgImgv mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.top.equalTo(self).offset(adapt(193));
  96. make.left.right.equalTo(self).inset(adapt(20));
  97. make.height.mas_equalTo(adapt(277));
  98. }];
  99. [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.top.equalTo(self.bgImgv).offset(adapt(10));
  101. make.centerX.equalTo(self.bgImgv);
  102. }];
  103. [self.titleLine mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.top.equalTo(self.titleLb.mas_bottom).offset(adapt(5));
  105. make.centerX.equalTo(self.bgImgv);
  106. make.width.mas_equalTo(adapt(28));
  107. make.height.mas_equalTo(adapt(2));
  108. }];
  109. [self.mobileLb mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.top.equalTo(self.bgImgv).offset(adapt(67));
  111. make.left.equalTo(self.bgImgv).offset(adapt(20));
  112. make.right.equalTo(self.bgImgv).offset(adapt(-20));
  113. }];
  114. [self.mobileView mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.top.equalTo(self.mobileLb.mas_bottom).offset(adapt(5));
  116. make.left.equalTo(self.bgImgv).offset(adapt(20));
  117. make.right.equalTo(self.bgImgv).offset(adapt(-20));
  118. make.height.mas_equalTo(adapt(48));
  119. }];
  120. [self.mobileInputBox mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.top.equalTo(self.mobileView);
  122. make.left.equalTo(self.mobileView).offset(adapt(30));
  123. make.right.equalTo(self.mobileView);
  124. make.bottom.equalTo(self.mobileView);
  125. }];
  126. [self.verifyCodeLb mas_makeConstraints:^(MASConstraintMaker *make) {
  127. make.top.equalTo(self.mobileView.mas_bottom).offset(adapt(20));
  128. make.left.equalTo(self.bgImgv).offset(adapt(20));
  129. make.right.equalTo(self.bgImgv).offset(adapt(-20));
  130. }];
  131. [self.verifyCodeView mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.top.equalTo(self.verifyCodeLb.mas_bottom).offset(adapt(5));
  133. make.left.equalTo(self.bgImgv).offset(adapt(20));
  134. make.right.equalTo(self.bgImgv).offset(adapt(-20));
  135. make.height.mas_equalTo(adapt(48));
  136. }];
  137. [self.verifyCodeInputBox mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.top.equalTo(self.verifyCodeView);
  139. make.left.equalTo(self.verifyCodeView).offset(adapt(30));
  140. make.bottom.equalTo(self.verifyCodeView);
  141. }];
  142. [self.verifyCodeInputBox setContentCompressionResistancePriority:(UILayoutPriorityDefaultLow) forAxis:(UILayoutConstraintAxisHorizontal)];
  143. [self.getVerifyCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  144. make.left.equalTo(self.verifyCodeInputBox.mas_right).offset(adapt(10));
  145. make.right.equalTo(self.verifyCodeView).offset(-20);
  146. make.top.equalTo(self.verifyCodeView);
  147. make.bottom.equalTo(self.verifyCodeView);
  148. }];
  149. [self.passwordLb mas_makeConstraints:^(MASConstraintMaker *make) {
  150. make.top.equalTo(self.verifyCodeView.mas_bottom).offset(adapt(20));
  151. make.left.equalTo(self.bgImgv).offset(adapt(20));
  152. make.right.equalTo(self.bgImgv).offset(adapt(-20));
  153. }];
  154. [self.passwordView mas_makeConstraints:^(MASConstraintMaker *make) {
  155. make.top.equalTo(self.passwordLb.mas_bottom).offset(adapt(5));
  156. make.left.equalTo(self.bgImgv).offset(adapt(20));
  157. make.right.equalTo(self.bgImgv).offset(adapt(-20));
  158. make.height.mas_equalTo(adapt(48));
  159. }];
  160. [self.passwordInputBox mas_makeConstraints:^(MASConstraintMaker *make) {
  161. make.top.equalTo(self.passwordView);
  162. make.left.equalTo(self.passwordView).offset(adapt(30));
  163. make.right.equalTo(self.passwordView);
  164. make.bottom.equalTo(self.passwordView);
  165. }];
  166. [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  167. make.top.equalTo(self.passwordView.mas_bottom).offset(adapt(40));
  168. make.left.equalTo(self.bgImgv).offset(adapt(20));
  169. make.right.equalTo(self.bgImgv).offset(adapt(-20));
  170. make.height.mas_equalTo(adapt(48));
  171. }];
  172. [self.agreementView mas_makeConstraints:^(MASConstraintMaker *make) {
  173. make.centerX.equalTo(self.mas_centerX);
  174. make.bottom.equalTo(self).offset(Is_iPhoneX ? adapt(-32) : adapt(-12));
  175. }];
  176. [self.radioBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  177. make.centerY.equalTo(self.agreementLb.mas_centerY);
  178. make.left.equalTo(self.agreementView).offset(adapt(5));
  179. make.width.height.mas_equalTo(adapt(17));
  180. }];
  181. [self.agreementLb mas_makeConstraints:^(MASConstraintMaker *make) {
  182. make.top.equalTo(self.agreementView).offset(adapt(10));
  183. make.left.equalTo(self.radioBtn.mas_right).offset(adapt(5));
  184. make.right.equalTo(self.agreementView).offset(adapt(-5));
  185. make.bottom.equalTo(self.agreementView).offset(adapt(-10));
  186. }];
  187. [super updateConstraints];
  188. }
  189. - (void)ym_bindViewModel:(YMRegisterViewModel *)viewModel{
  190. if (!viewModel) {
  191. return;
  192. }
  193. _viewModel = viewModel;
  194. RAC(self.viewModel , mobile) = [[RACSignal merge:@[RACObserve(self.mobileInputBox, text),self.mobileInputBox.rac_textSignal]] takeUntil:self.rac_willDeallocSignal];
  195. RAC(self.viewModel , verifyCode) = [[RACSignal merge:@[RACObserve(self.verifyCodeInputBox, text),self.verifyCodeInputBox.rac_textSignal]]takeUntil:self.rac_willDeallocSignal];
  196. RAC(self.viewModel , password) = [[RACSignal merge:@[RACObserve(self.passwordInputBox, text),self.passwordInputBox.rac_textSignal]]takeUntil:self.rac_willDeallocSignal];
  197. [self.viewModel.validRegisterSignal subscribeNext:^(id _Nullable value) {
  198. self.registerBtn.enabled = [value boolValue];
  199. if ([value boolValue]) {
  200. self.registerBtn.alpha = 1;
  201. } else {
  202. self.registerBtn.alpha = 0.5;
  203. }
  204. }];
  205. }
  206. - (UIImageView *)bgImgv {
  207. if (!_bgImgv) {
  208. _bgImgv = [[UIImageView alloc] init];
  209. _bgImgv.backgroundColor = HexColorFromRGB(0xFFFFFF);
  210. _bgImgv.layer.masksToBounds = YES;
  211. _bgImgv.layer.cornerRadius = adapt(20);
  212. }
  213. return _bgImgv;
  214. }
  215. - (UIView *)mobileView{
  216. if (!_mobileView) {
  217. _mobileView = [[UIView alloc]init];
  218. _mobileView.backgroundColor = HexColorFromRGB(0xF2F5FF);
  219. _mobileView.layer.masksToBounds = YES;
  220. _mobileView.layer.cornerRadius = adapt(16);
  221. }
  222. return _mobileView;
  223. }
  224. - (UILabel *)registerTipsLb1 {
  225. if (!_registerTipsLb1) {
  226. _registerTipsLb1 = [[UILabel alloc]init];
  227. _registerTipsLb1.font = LCBoldFont(32);
  228. _registerTipsLb1.textColor = HexColorFromRGB(0x333333);
  229. _registerTipsLb1.textAlignment = NSTextAlignmentLeft;
  230. _registerTipsLb1.text = @"欢迎注册👏";
  231. _registerTipsLb1.numberOfLines = 0;
  232. }
  233. return _registerTipsLb1;
  234. }
  235. - (UILabel *)registerTipsLb2 {
  236. if (!_registerTipsLb2) {
  237. _registerTipsLb2 = [[UILabel alloc]init];
  238. _registerTipsLb2.font = LCBoldFont(15);
  239. _registerTipsLb2.textColor = HexColorFromRGB(0x545D79);
  240. _registerTipsLb2.textAlignment = NSTextAlignmentLeft;
  241. _registerTipsLb2.text = @"注册登录,开启精彩之旅";
  242. _registerTipsLb2.numberOfLines = 0;
  243. }
  244. return _registerTipsLb2;
  245. }
  246. - (UILabel *)titleLb {
  247. if (!_titleLb) {
  248. _titleLb = [[UILabel alloc] init];
  249. _titleLb.font = LCBoldFont(15);
  250. _titleLb.textColor = rgba(252, 94, 158, 1);
  251. _titleLb.textAlignment = NSTextAlignmentLeft;
  252. _titleLb.text = @"账号注册";
  253. }
  254. return _titleLb;
  255. }
  256. - (UILabel *)titleLine {
  257. if (!_titleLine) {
  258. _titleLine = [[UILabel alloc] init];
  259. [_titleLine ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  260. }
  261. return _titleLine;
  262. }
  263. - (UILabel *)mobileLb{
  264. if (!_mobileLb) {
  265. _mobileLb = [[UILabel alloc]init];
  266. _mobileLb.font = LCBoldFont(13);
  267. _mobileLb.textColor = HexColorFromRGB(0x333333);
  268. _mobileLb.textAlignment = NSTextAlignmentLeft;
  269. _mobileLb.text = @"手机号";
  270. }
  271. return _mobileLb;
  272. }
  273. - (UITextField *)mobileInputBox{
  274. if (!_mobileInputBox) {
  275. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  276. style.minimumLineHeight = 0;
  277. NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入手机号"];
  278. placeholderAttributed.yy_paragraphStyle = style;
  279. placeholderAttributed.yy_font = LCFont(14);
  280. placeholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  281. _mobileInputBox = [[UITextField alloc]init];
  282. _mobileInputBox.attributedPlaceholder = placeholderAttributed;
  283. _mobileInputBox.clearButtonMode = UITextFieldViewModeWhileEditing;
  284. _mobileInputBox.autocorrectionType = UITextAutocorrectionTypeDefault;
  285. _mobileInputBox.autocapitalizationType = UITextAutocapitalizationTypeNone;
  286. _mobileInputBox.keyboardType = UIKeyboardTypePhonePad;
  287. _mobileInputBox.ba_maxLength = 11;
  288. // @weakify(self)
  289. [[[_mobileInputBox rac_textSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  290. // @strongify(self)
  291. }];
  292. }
  293. return _mobileInputBox;
  294. }
  295. - (UIView *)verifyCodeView{
  296. if (!_verifyCodeView) {
  297. _verifyCodeView = [[UIView alloc]init];
  298. _verifyCodeView.backgroundColor = HexColorFromRGB(0xF2F5FF);
  299. _verifyCodeView.layer.masksToBounds = YES;
  300. _verifyCodeView.layer.cornerRadius = adapt(16);
  301. }
  302. return _verifyCodeView;
  303. }
  304. - (UILabel *)verifyCodeLb{
  305. if (!_verifyCodeLb) {
  306. _verifyCodeLb = [[UILabel alloc]init];
  307. _verifyCodeLb.font = LCBoldFont(13);
  308. _verifyCodeLb.textColor = HexColorFromRGB(0x333333);
  309. _verifyCodeLb.textAlignment = NSTextAlignmentLeft;
  310. _verifyCodeLb.text = @"验证码";
  311. }
  312. return _verifyCodeLb;
  313. }
  314. - (UITextField *)verifyCodeInputBox{
  315. if (!_verifyCodeInputBox) {
  316. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  317. style.minimumLineHeight = 0;
  318. NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入验证码"];
  319. placeholderAttributed.yy_paragraphStyle = style;
  320. placeholderAttributed.yy_font = LCFont(14);
  321. placeholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  322. _verifyCodeInputBox = [[UITextField alloc]init];
  323. _verifyCodeInputBox.attributedPlaceholder = placeholderAttributed;
  324. _verifyCodeInputBox.clearButtonMode = UITextFieldViewModeWhileEditing;
  325. _verifyCodeInputBox.autocorrectionType = UITextAutocorrectionTypeDefault;
  326. _verifyCodeInputBox.autocapitalizationType = UITextAutocapitalizationTypeNone;
  327. _verifyCodeInputBox.keyboardType = UIKeyboardTypeDecimalPad;
  328. // @weakify(self)
  329. [[[_verifyCodeInputBox rac_textSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  330. // @strongify(self)
  331. }];
  332. }
  333. return _verifyCodeInputBox;
  334. }
  335. - (YMCaptchaCountdownButton *)getVerifyCodeBtn{
  336. if (!_getVerifyCodeBtn) {
  337. _getVerifyCodeBtn = [YMCaptchaCountdownButton buttonWithType:UIButtonTypeCustom];
  338. _getVerifyCodeBtn.titleLabel.font = LCFont(14);
  339. [_getVerifyCodeBtn setTitleColor:HexColorFromRGB(0xFF6893) forState:UIControlStateNormal];
  340. [_getVerifyCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
  341. @weakify(self)
  342. [_getVerifyCodeBtn countDownButtonHandler:^(YMCaptchaCountdownButton *sender, NSInteger tag) {
  343. @strongify(self)
  344. if (OCStringIsEmpty(self.mobileInputBox.text)) {
  345. [ZCHUDHelper showTitle:@"请输入手机号"];
  346. return;
  347. }
  348. [self.mobileInputBox resignFirstResponder];
  349. [self.verifyCodeInputBox resignFirstResponder];
  350. [self.passwordInputBox resignFirstResponder];
  351. [CaptchaCenter.defaultCenter getCaptchaType:^(NSNumber * _Nullable type, NSError * _Nullable error) {
  352. if (error) {
  353. [ZCHUDHelper showTitle:@"获取验证码失败"];
  354. return;
  355. }
  356. if ([type isEqualToNumber:@1]) { // 原生
  357. YMCaptchaPopupView *view = [[YMCaptchaPopupView alloc] init];
  358. view.cancelButtonTappedBlock = ^{};
  359. @weakify(self)
  360. view.confirmButtonTappedBlock = ^(NSString * _Nonnull input) {
  361. @strongify(self)
  362. [self getVerifyCodeWithCaptcha:input sender:sender];
  363. };
  364. UIView *currentVCView = [LCTools getCurrentVC].view;
  365. if (currentVCView != nil && ![currentVCView isEqual:NSNull.null]) {
  366. [view showInView:currentVCView];
  367. }
  368. } else { // 阿里
  369. @weakify(self)
  370. [CaptchaCenter.defaultCenter verifyCompletion:^(NSString * _Nonnull status, NSDictionary * _Nonnull result) {
  371. @strongify(self)
  372. [self getVerifyCodeWithCaptcha:result sender:sender];
  373. }];
  374. }
  375. }];
  376. }];
  377. }
  378. return _getVerifyCodeBtn;
  379. }
  380. - (void)getVerifyCodeWithCaptcha:(id)captcha sender:(YMCaptchaCountdownButton *)sender {
  381. @weakify(self)
  382. [self.viewModel getVerifyCodeWithCaptcha:captcha handler:^(NSDictionary * _Nonnull dic, NSError * _Nullable error) {
  383. @strongify(self)
  384. sender.enabled = NO;
  385. [sender startCountDownWithSecond:59];
  386. [sender countDownChanging:^NSString *(YMCaptchaCountdownButton *countDownButton, NSUInteger second) {
  387. NSString *title = [NSString stringWithFormat:@"重新发送(%zds)",second];
  388. return title;
  389. }];
  390. [sender countDownFinished:^NSString *(YMCaptchaCountdownButton *countDownButton, NSUInteger second) {
  391. countDownButton.enabled = YES;
  392. return @"重新发送";
  393. }];
  394. }];
  395. }
  396. - (UIView *)passwordView{
  397. if (!_passwordView) {
  398. _passwordView = [[UIView alloc]init];
  399. _passwordView.backgroundColor = HexColorFromRGB(0xF2F5FF);
  400. _passwordView.layer.masksToBounds = YES;
  401. _passwordView.layer.cornerRadius = adapt(16);
  402. }
  403. return _passwordView;
  404. }
  405. - (UILabel *)passwordLb{
  406. if (!_passwordLb) {
  407. _passwordLb = [[UILabel alloc]init];
  408. _passwordLb.font = LCBoldFont(13);
  409. _passwordLb.textColor = HexColorFromRGB(0x333333);
  410. _passwordLb.textAlignment = NSTextAlignmentLeft;
  411. _passwordLb.text = @"密 码";
  412. }
  413. return _passwordLb;
  414. }
  415. - (UITextField *)passwordInputBox{
  416. if (!_passwordInputBox) {
  417. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  418. style.minimumLineHeight = 0;
  419. NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入密码"];
  420. placeholderAttributed.yy_paragraphStyle = style;
  421. placeholderAttributed.yy_font = LCFont(14);
  422. placeholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  423. _passwordInputBox = [[UITextField alloc]init];
  424. _passwordInputBox.attributedPlaceholder = placeholderAttributed;
  425. _passwordInputBox.clearButtonMode = UITextFieldViewModeWhileEditing;
  426. _passwordInputBox.autocorrectionType = UITextAutocorrectionTypeDefault;
  427. _passwordInputBox.autocapitalizationType = UITextAutocapitalizationTypeNone;
  428. _passwordInputBox.keyboardType = UIKeyboardTypeDefault;
  429. _passwordInputBox.secureTextEntry = YES;
  430. // @weakify(self)
  431. [[[_passwordInputBox rac_textSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  432. // @strongify(self)
  433. }];
  434. }
  435. return _passwordInputBox;
  436. }
  437. - (UIView *)agreementView{
  438. if (!_agreementView) {
  439. _agreementView = [[UIView alloc]init];
  440. }
  441. return _agreementView;
  442. }
  443. - (UIButton *)radioBtn{
  444. if (!_radioBtn) {
  445. _radioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  446. [_radioBtn setBackgroundImage:ImageByName(@"ym_login_auth_normal_icon") forState:UIControlStateNormal];
  447. [_radioBtn setBackgroundImage:ImageByName(@"ym_login_auth_selected_icon") forState:UIControlStateSelected];
  448. [[[_radioBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  449. sender.selected = !sender.selected;
  450. }];
  451. }
  452. return _radioBtn;
  453. }
  454. - (YYLabel *)agreementLb{
  455. if (!_agreementLb) {
  456. _agreementLb = [[YYLabel alloc] init];
  457. _agreementLb.numberOfLines = 0;
  458. _agreementLb.preferredMaxLayoutWidth = kFrameWidth - 55;
  459. NSString *agreementText = @"同意《用户协议》与《隐私政策》";
  460. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
  461. paragraphStyle.alignment = NSTextAlignmentLeft;
  462. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:agreementText];
  463. attributedString.yy_font = LCFont(12);
  464. attributedString.yy_color = HexColorFromRGBA(0x000000,0.65);
  465. attributedString.yy_paragraphStyle = paragraphStyle;
  466. //设置高亮色和点击事件
  467. [attributedString yy_setTextHighlightRange:[agreementText rangeOfString:@"《用户协议》"] color:AGREEMENTColor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  468. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  469. ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserProtocolH5]
  470. }];
  471. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  472. RouterViewModel:webArticleVM
  473. } completion:nil];
  474. }];
  475. //设置高亮色和点击事件
  476. [attributedString yy_setTextHighlightRange:[[attributedString string] rangeOfString:@"《隐私政策》"] color:AGREEMENTColor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  477. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  478. ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserPrivacyH5]
  479. }];
  480. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  481. RouterViewModel:webArticleVM
  482. } completion:nil];
  483. }];
  484. _agreementLb.attributedText = attributedString;
  485. }
  486. return _agreementLb;
  487. }
  488. - (UIButton *)registerBtn{
  489. if (!_registerBtn) {
  490. _registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  491. _registerBtn.titleLabel.font = LCBoldFont(15);
  492. [_registerBtn setTitle:@"注册" forState:UIControlStateNormal];
  493. [_registerBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal];
  494. [_registerBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  495. _registerBtn.layer.masksToBounds = YES;
  496. _registerBtn.layer.cornerRadius = adapt(16);
  497. WS(weakSelf)
  498. [[[_registerBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  499. if (OCStringIsEmpty(weakSelf.mobileInputBox.text)) {
  500. [ZCHUDHelper showTitle:@"请输入手机号"];
  501. return;
  502. }
  503. if (OCStringIsEmpty(weakSelf.verifyCodeInputBox.text)) {
  504. [ZCHUDHelper showTitle:@"请输入手机号"];
  505. return;
  506. }
  507. if (OCStringIsEmpty(weakSelf.passwordInputBox.text)) {
  508. [ZCHUDHelper showTitle:@"请输入密码"];
  509. return;
  510. }
  511. if (!weakSelf.radioBtn.selected) {
  512. YMLoginRegistrAgreementPopupView *customView = [[YMLoginRegistrAgreementPopupView alloc]init];
  513. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  514. popupView.priority = 999;
  515. popupView.cornerRadius = adapt(10);
  516. popupView.rectCorners = UIRectCornerAllCorners;
  517. popupView.positionStyle = YMPositionStyleCenter;
  518. popupView.isHideBg = NO;
  519. popupView.bgAlpha = 0.3;
  520. [popupView pop];
  521. @weakify(popupView)
  522. customView.buttonBlock = ^(BOOL isConfirm) {
  523. @strongify(popupView)
  524. if (isConfirm) {
  525. weakSelf.radioBtn.selected = YES;
  526. [weakSelf.viewModel registerRequest];
  527. }
  528. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  529. };
  530. customView.dismissBlock = ^{
  531. @strongify(popupView)
  532. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  533. };
  534. return;
  535. }
  536. [weakSelf.viewModel registerRequest];
  537. }];
  538. }
  539. return _registerBtn;
  540. }
  541. @end