YMPasswordLoginView.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. //
  2. // YMPasswordLoginView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/4.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMPasswordLoginView.h"
  9. #import "YMPasswordLoginViewModel.h"
  10. @interface YMPasswordLoginView ()
  11. /// 密码登录VM
  12. @property (nonatomic, strong) YMPasswordLoginViewModel *viewModel;
  13. @property (nonatomic, strong) UIView *topView;
  14. @property (nonatomic, strong) UILabel *topLb1;
  15. @property (nonatomic, strong) UILabel *topLb2;
  16. @property (nonatomic, strong) UILabel *titleLb;
  17. @property (nonatomic, strong) UILabel *titleLine;
  18. @property (nonatomic, strong) UIImageView *bgImgv;
  19. /// 手机视图
  20. @property (nonatomic, strong) UIView *mobileView;
  21. /// 手机号标签
  22. @property (nonatomic, strong) UILabel *mobileLb;
  23. /// 手机号输入框
  24. @property (nonatomic, strong) UITextField *mobileInputBox;
  25. /// 密码视图
  26. @property (nonatomic, strong) UIView *passwordView;
  27. /// 密码标签
  28. @property (nonatomic, strong) UILabel *passwordLb;
  29. /// 密码输入框
  30. @property (nonatomic, strong) UITextField *passwordInputBox;
  31. /// 登录按钮
  32. @property (nonatomic, strong) UIButton *loginBtn;
  33. /** 忘记密码按钮*/
  34. @property (nonatomic, strong) UIButton *forgotPasswordBtn;
  35. /** 注册按钮*/
  36. @property (nonatomic, strong) UIButton *registerBtn;
  37. /** 登录方式堆叠视图*/
  38. @property (nonatomic, strong) UIStackView *loginMethodStackView;
  39. /// 微信登录按钮
  40. @property (nonatomic, strong) UIButton *wechatLoginBtn;
  41. /// 协议视图
  42. @property (nonatomic, strong) UIView *agreementView;
  43. /// 单选按钮
  44. @property (nonatomic, strong) UIButton *radioBtn;
  45. /// 协议标签
  46. @property (nonatomic, strong) YYLabel *agreementLb;
  47. @end
  48. @implementation YMPasswordLoginView
  49. - (void)ym_setupViews{
  50. [self addSubview:self.topView];
  51. [self.topView addSubview:self.topLb1];
  52. [self.topView addSubview:self.topLb2];
  53. [self addSubview:self.bgImgv];
  54. [self addSubview:self.titleLb];
  55. [self addSubview:self.titleLine];
  56. [self addSubview:self.mobileLb];
  57. [self addSubview:self.mobileView];
  58. [self addSubview:self.mobileInputBox];
  59. [self addSubview:self.passwordView];
  60. [self addSubview:self.passwordLb];
  61. [self addSubview:self.passwordInputBox];
  62. [self addSubview:self.loginBtn];
  63. [self addSubview:self.forgotPasswordBtn];
  64. [self addSubview:self.registerBtn];
  65. [self addSubview:self.loginMethodStackView];
  66. [self.loginMethodStackView addArrangedSubview:self.wechatLoginBtn];
  67. [self addSubview:self.agreementView];
  68. [self.agreementView addSubview:self.radioBtn];
  69. [self.agreementView addSubview:self.agreementLb];
  70. [self setNeedsUpdateConstraints];
  71. [self updateConstraintsIfNeeded];
  72. }
  73. - (void)updateConstraints{
  74. [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.top.equalTo(self).offset(adapt(96));
  76. make.left.equalTo(self).offset(adapt(30));
  77. make.right.equalTo(self).offset(adapt(-30));
  78. make.height.mas_equalTo(adapt(85));
  79. }];
  80. [self.topLb1 mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.top.equalTo(self.topView);
  82. make.left.equalTo(self.topView);
  83. make.right.equalTo(self.topView);
  84. }];
  85. [self.topLb2 mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.top.equalTo(self.topLb1.mas_bottom).offset(5);
  87. make.left.equalTo(self.topView);
  88. make.right.equalTo(self.topView);
  89. }];
  90. [self.bgImgv mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.top.equalTo(self).offset(adapt(193));
  92. make.left.right.equalTo(self).inset(adapt(20));
  93. make.height.mas_equalTo(adapt(277));
  94. }];
  95. [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.top.equalTo(self.bgImgv).offset(adapt(10));
  97. make.centerX.equalTo(self.bgImgv);
  98. }];
  99. [self.titleLine mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.top.equalTo(self.titleLb.mas_bottom).offset(adapt(5));
  101. make.centerX.equalTo(self.bgImgv);
  102. make.width.mas_equalTo(adapt(28));
  103. make.height.mas_equalTo(adapt(2));
  104. }];
  105. [self.mobileLb mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.top.equalTo(self.bgImgv).offset(adapt(67));
  107. make.left.equalTo(self.bgImgv).offset(adapt(20));
  108. make.right.equalTo(self.bgImgv).offset(adapt(-20));
  109. }];
  110. [self.mobileView mas_makeConstraints:^(MASConstraintMaker *make) {
  111. make.top.equalTo(self.mobileLb.mas_bottom).offset(adapt(5));
  112. make.left.equalTo(self.bgImgv).offset(adapt(20));
  113. make.right.equalTo(self.bgImgv).offset(adapt(-20));
  114. make.height.mas_equalTo(adapt(48));
  115. }];
  116. [self.mobileInputBox mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.top.equalTo(self.mobileView);
  118. make.left.equalTo(self.mobileView).offset(adapt(30));
  119. make.right.equalTo(self.mobileView);
  120. make.bottom.equalTo(self.mobileView);
  121. }];
  122. [self.passwordLb mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.top.equalTo(self.mobileView.mas_bottom).offset(adapt(20));
  124. make.left.equalTo(self.mobileLb);
  125. }];
  126. [self.passwordView mas_makeConstraints:^(MASConstraintMaker *make) {
  127. make.top.equalTo(self.passwordLb.mas_bottom).offset(adapt(5));
  128. make.left.equalTo(self.bgImgv).offset(adapt(20));
  129. make.right.equalTo(self.bgImgv).offset(adapt(-20));
  130. make.height.mas_equalTo(adapt(48));
  131. }];
  132. [self.passwordInputBox mas_makeConstraints:^(MASConstraintMaker *make) {
  133. make.top.equalTo(self.passwordView);
  134. make.left.equalTo(self.passwordView).offset(adapt(30));
  135. make.right.equalTo(self.passwordView);
  136. make.bottom.equalTo(self.passwordView);
  137. }];
  138. [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  139. make.top.equalTo(self.passwordView.mas_bottom).offset(adapt(10));
  140. make.left.equalTo(self.bgImgv).offset(adapt(20));
  141. make.height.mas_equalTo(adapt(25));
  142. }];
  143. [self.forgotPasswordBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  144. make.top.equalTo(self.registerBtn);
  145. make.right.equalTo(self.bgImgv).offset(adapt(-20));
  146. make.height.mas_equalTo(adapt(25));
  147. }];
  148. [self.agreementView mas_makeConstraints:^(MASConstraintMaker *make) {
  149. make.centerX.equalTo(self.mas_centerX);
  150. make.bottom.equalTo(self).offset(Is_iPhoneX ? adapt(-32) : adapt(-12));
  151. }];
  152. [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  153. make.bottom.equalTo(self.agreementView.mas_top).offset(adapt(-15));
  154. make.left.equalTo(self).offset(adapt(40));
  155. make.right.equalTo(self).offset(adapt(-40));
  156. make.height.mas_equalTo(adapt(54));
  157. }];
  158. [self.loginMethodStackView mas_makeConstraints:^(MASConstraintMaker *make) {
  159. make.centerX.equalTo(self.mas_centerX);
  160. make.bottom.equalTo(self.loginBtn.mas_top).offset(adapt(-10));
  161. }];
  162. [self.wechatLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  163. make.width.height.mas_equalTo(53);
  164. make.bottom.equalTo(self.loginMethodStackView);
  165. }];
  166. [self.radioBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  167. make.centerY.equalTo(self.agreementLb.mas_centerY);
  168. make.left.equalTo(self.agreementView).offset(adapt(5));
  169. make.width.height.mas_equalTo(adapt(17));
  170. }];
  171. [self.agreementLb mas_makeConstraints:^(MASConstraintMaker *make) {
  172. make.top.equalTo(self.agreementView).offset(adapt(10));
  173. make.left.equalTo(self.radioBtn.mas_right).offset(adapt(5));
  174. make.right.equalTo(self.agreementView).offset(adapt(-5));
  175. make.bottom.equalTo(self.agreementView).offset(adapt(-10));
  176. }];
  177. [super updateConstraints];
  178. }
  179. - (void)ym_bindViewModel:(YMPasswordLoginViewModel *)viewModel{
  180. if (!viewModel) {
  181. return;
  182. }
  183. _viewModel = viewModel;
  184. RAC(self.viewModel , mobile) = [[RACSignal merge:@[RACObserve(self.mobileInputBox, text),self.mobileInputBox.rac_textSignal]] takeUntil:self.rac_willDeallocSignal];
  185. RAC(self.viewModel , password) = [[RACSignal merge:@[RACObserve(self.passwordInputBox, text),self.passwordInputBox.rac_textSignal]]takeUntil:self.rac_willDeallocSignal];
  186. RAC(self.loginBtn , enabled) = self.viewModel.validLoginSignal;
  187. [self.viewModel.validLoginSignal subscribeNext:^(id _Nullable value) {
  188. self.loginBtn.enabled = [value boolValue];
  189. if ([value boolValue]) {
  190. self.loginBtn.alpha = 1;
  191. } else {
  192. self.loginBtn.alpha = 0.5;
  193. }
  194. }];
  195. }
  196. - (UIImageView *)bgImgv {
  197. if (!_bgImgv) {
  198. _bgImgv = [[UIImageView alloc] init];
  199. _bgImgv.backgroundColor = HexColorFromRGB(0xFFFFFF);
  200. _bgImgv.layer.masksToBounds = YES;
  201. _bgImgv.layer.cornerRadius = adapt(20);
  202. }
  203. return _bgImgv;
  204. }
  205. - (UIView *)mobileView{
  206. if (!_mobileView) {
  207. _mobileView = [[UIView alloc]init];
  208. _mobileView.backgroundColor = HexColorFromRGB(0xF2F5FF);
  209. _mobileView.layer.masksToBounds = YES;
  210. _mobileView.layer.cornerRadius = adapt(16);
  211. }
  212. return _mobileView;
  213. }
  214. - (UIView *)topView{
  215. if (!_topView) {
  216. _topView = [[UIView alloc]init];
  217. _topView.hidden = NO;
  218. }
  219. return _topView;
  220. }
  221. - (UILabel *)mobileLb{
  222. if (!_mobileLb) {
  223. _mobileLb = [[UILabel alloc]init];
  224. _mobileLb.font = LCBoldFont(13);
  225. _mobileLb.textColor = HexColorFromRGB(0x333333);
  226. _mobileLb.textAlignment = NSTextAlignmentLeft;
  227. _mobileLb.text = @"账号";
  228. }
  229. return _mobileLb;
  230. }
  231. - (UILabel *)topLb1{
  232. if (!_topLb1) {
  233. _topLb1 = [[UILabel alloc]init];
  234. _topLb1.font = LCBoldFont(32);
  235. _topLb1.textColor = HexColorFromRGB(0x333333);
  236. _topLb1.textAlignment = NSTextAlignmentLeft;
  237. _topLb1.text = @"欢迎登录👏";
  238. }
  239. return _topLb1;
  240. }
  241. - (UILabel *)topLb2{
  242. if (!_topLb2) {
  243. _topLb2 = [[UILabel alloc]init];
  244. _topLb2.font = LCBoldFont(15);
  245. _topLb2.textColor = HexColorFromRGB(0x545D79);
  246. _topLb2.textAlignment = NSTextAlignmentLeft;
  247. _topLb2.text = @"注册登录,开启精彩之旅";
  248. }
  249. return _topLb2;
  250. }
  251. - (UILabel *)titleLb {
  252. if (!_titleLb) {
  253. _titleLb = [[UILabel alloc] init];
  254. _titleLb.font = LCBoldFont(15);
  255. _titleLb.textColor = rgba(252, 94, 158, 1);
  256. _titleLb.textAlignment = NSTextAlignmentLeft;
  257. _titleLb.text = @"账号登录";
  258. }
  259. return _titleLb;
  260. }
  261. - (UILabel *)titleLine {
  262. if (!_titleLine) {
  263. _titleLine = [[UILabel alloc] init];
  264. [_titleLine ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  265. }
  266. return _titleLine;
  267. }
  268. - (UITextField *)mobileInputBox{
  269. if (!_mobileInputBox) {
  270. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  271. style.minimumLineHeight = 0;
  272. NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入手机号"];
  273. placeholderAttributed.yy_paragraphStyle = style;
  274. placeholderAttributed.yy_font = LCFont(14);
  275. placeholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  276. _mobileInputBox = [[UITextField alloc]init];
  277. _mobileInputBox.attributedPlaceholder = placeholderAttributed;
  278. _mobileInputBox.clearButtonMode = UITextFieldViewModeWhileEditing;
  279. _mobileInputBox.autocorrectionType = UITextAutocorrectionTypeDefault;
  280. _mobileInputBox.autocapitalizationType = UITextAutocapitalizationTypeNone;
  281. _mobileInputBox.keyboardType = UIKeyboardTypePhonePad;
  282. _mobileInputBox.ba_maxLength = 11;
  283. }
  284. return _mobileInputBox;
  285. }
  286. - (UIView *)passwordView{
  287. if (!_passwordView) {
  288. _passwordView = [[UIView alloc]init];
  289. _passwordView.backgroundColor = HexColorFromRGB(0xF2F5FF);
  290. _passwordView.layer.masksToBounds = YES;
  291. _passwordView.layer.cornerRadius = adapt(16);
  292. }
  293. return _passwordView;
  294. }
  295. - (UILabel *)passwordLb{
  296. if (!_passwordLb) {
  297. _passwordLb = [[UILabel alloc]init];
  298. _passwordLb.font = LCBoldFont(13);
  299. _passwordLb.textColor = HexColorFromRGB(0x333333);
  300. _passwordLb.textAlignment = NSTextAlignmentCenter;
  301. _passwordLb.text = @"密码";
  302. }
  303. return _passwordLb;
  304. }
  305. - (UITextField *)passwordInputBox{
  306. if (!_passwordInputBox) {
  307. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  308. style.minimumLineHeight = 0;
  309. NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入密码"];
  310. placeholderAttributed.yy_paragraphStyle = style;
  311. placeholderAttributed.yy_font = LCFont(14);
  312. placeholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  313. _passwordInputBox = [[UITextField alloc]init];
  314. _passwordInputBox.attributedPlaceholder = placeholderAttributed;
  315. _passwordInputBox.clearButtonMode = UITextFieldViewModeWhileEditing;
  316. _passwordInputBox.autocorrectionType = UITextAutocorrectionTypeDefault;
  317. _passwordInputBox.autocapitalizationType = UITextAutocapitalizationTypeNone;
  318. _passwordInputBox.keyboardType = UIKeyboardTypeDefault;
  319. _passwordInputBox.secureTextEntry = YES;
  320. }
  321. return _passwordInputBox;
  322. }
  323. - (UIButton *)loginBtn{
  324. if (!_loginBtn) {
  325. _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  326. _loginBtn.titleLabel.font = LCBoldFont(19);
  327. [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
  328. [_loginBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal];
  329. [_loginBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  330. _loginBtn.layer.cornerRadius = adapt(16);
  331. _loginBtn.layer.masksToBounds = YES;
  332. WS(weakSelf)
  333. [[[_loginBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  334. if (OCStringIsEmpty(weakSelf.mobileInputBox.text)) {
  335. [ZCHUDHelper showTitle:@"请输入手机号"];
  336. return;
  337. }
  338. if (OCStringIsEmpty(weakSelf.passwordInputBox.text)) {
  339. [ZCHUDHelper showTitle:@"请输入密码"];
  340. return;
  341. }
  342. if (!weakSelf.radioBtn.selected) {
  343. YMLoginRegistrAgreementPopupView *customView = [[YMLoginRegistrAgreementPopupView alloc]init];
  344. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:[YMGlobalUtils getCurrentVC].view popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  345. popupView.priority = 999;
  346. popupView.cornerRadius = adapt(10);
  347. popupView.rectCorners = UIRectCornerAllCorners;
  348. popupView.positionStyle = YMPositionStyleCenter;
  349. popupView.isHideBg = NO;
  350. popupView.bgAlpha = 0.3;
  351. [popupView pop];
  352. @weakify(popupView)
  353. customView.buttonBlock = ^(BOOL isConfirm) {
  354. @strongify(popupView)
  355. if (isConfirm) {
  356. weakSelf.radioBtn.selected = YES;
  357. [weakSelf.viewModel accountPasswordLoginRequest];
  358. }
  359. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  360. };
  361. customView.dismissBlock = ^{
  362. @strongify(popupView)
  363. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  364. };
  365. return;
  366. }
  367. [weakSelf.viewModel accountPasswordLoginRequest];
  368. }];
  369. }
  370. return _loginBtn;
  371. }
  372. - (UIButton *)forgotPasswordBtn{
  373. if (!_forgotPasswordBtn) {
  374. _forgotPasswordBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  375. _forgotPasswordBtn.titleLabel.font = LCFont(12);
  376. [_forgotPasswordBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
  377. [_forgotPasswordBtn setTitleColor:HexColorFromRGB(0x8994B6) forState:UIControlStateNormal];
  378. WS(weakSelf)
  379. [[[_forgotPasswordBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  380. [weakSelf.viewModel gotoForgetPasswordVC];
  381. }];
  382. }
  383. return _forgotPasswordBtn;
  384. }
  385. - (UIButton *)registerBtn{
  386. if (!_registerBtn) {
  387. _registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  388. _registerBtn.titleLabel.font = LCFont(12);
  389. [_registerBtn setTitle:@"立即注册" forState:UIControlStateNormal];
  390. [_registerBtn setTitleColor:rgba(252, 94, 158, 1) forState:UIControlStateNormal];
  391. WS(weakSelf)
  392. [[[_registerBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  393. [weakSelf.viewModel gotoRegisterVC];
  394. }];
  395. }
  396. return _registerBtn;
  397. }
  398. - (UIStackView *)loginMethodStackView{
  399. if (!_loginMethodStackView) {
  400. _loginMethodStackView = [[UIStackView alloc]init];
  401. /**
  402. UILayoutConstraintAxisVertical 纵向
  403. UILayoutConstraintAxisHorizontal 横向
  404. */
  405. _loginMethodStackView.axis = UILayoutConstraintAxisHorizontal;
  406. /**
  407. UIStackViewAlignmentFill 将stackView充满
  408. 比如label,不管文字多少,将大小按照设置的非主轴方向充满
  409. ex: Vertical 就是水平铺满
  410. UIStackViewAlignmentLeading 在Vertical方向上生效,表示左对齐
  411. 比如label,文字自适应,如果小于非主轴方向的宽度,将不充满
  412. UIStackViewAlignmentTop 在Horizontal方向上生效,表示左对齐
  413. 比如label,文字自适应,如果小于非主轴方向的高度,将不充满
  414. 本质UIStackViewAlignmentTop = UIStackViewAlignmentLeading
  415. UIStackViewAlignmentTrailing 在Vertical方向上生效,表示右对齐
  416. 比如label,文字自适应,如果小于非主轴方向的宽度,将不充满
  417. UIStackViewAlignmentBottom 在Horizontal方向上生效,表示右对齐
  418. 比如label,文字自适应,如果小于非主轴方向的高度,将不充满
  419. 本质UIStackViewAlignmentBottom = UIStackViewAlignmentTrailing
  420. UIStackViewAlignmentLastBaseline 仅限于Horizontal
  421. 按照最高的一个视图的bottom对齐,最高的视图top对齐
  422. UIStackViewAlignmentCenter 中心对齐
  423. 不充满,沿主轴方向中心对齐
  424. */
  425. _loginMethodStackView.alignment = UIStackViewAlignmentCenter;
  426. _loginMethodStackView.spacing = adapt(10);
  427. }
  428. return _loginMethodStackView;
  429. }
  430. - (UIButton *)wechatLoginBtn{
  431. if (!_wechatLoginBtn) {
  432. _wechatLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  433. [_wechatLoginBtn setBackgroundImage:ImageByName(@"ym_login_wechat_login_icon") forState:UIControlStateNormal];
  434. _wechatLoginBtn.hidden = YES;
  435. WS(weakSelf)
  436. [[[_wechatLoginBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  437. if (!weakSelf.radioBtn.selected) {
  438. YMLoginRegistrAgreementPopupView *customView = [[YMLoginRegistrAgreementPopupView alloc]init];
  439. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  440. popupView.priority = 999;
  441. popupView.cornerRadius = adapt(10);
  442. popupView.rectCorners = UIRectCornerAllCorners;
  443. popupView.positionStyle = YMPositionStyleCenter;
  444. popupView.isHideBg = NO;
  445. popupView.bgAlpha = 0.3;
  446. [popupView pop];
  447. @weakify(popupView)
  448. customView.buttonBlock = ^(BOOL isConfirm) {
  449. @strongify(popupView)
  450. if (isConfirm) {
  451. weakSelf.radioBtn.selected = YES;
  452. [weakSelf.viewModel sendWechatAuth];
  453. }
  454. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  455. };
  456. customView.dismissBlock = ^{
  457. @strongify(popupView)
  458. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  459. };
  460. return;
  461. }
  462. [weakSelf.viewModel sendWechatAuth];
  463. }];
  464. }
  465. return _wechatLoginBtn;
  466. }
  467. - (UIView *)agreementView{
  468. if (!_agreementView) {
  469. _agreementView = [[UIView alloc]init];
  470. }
  471. return _agreementView;
  472. }
  473. - (UIButton *)radioBtn{
  474. if (!_radioBtn) {
  475. _radioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  476. [_radioBtn setBackgroundImage:ImageByName(@"ym_login_auth_normal_icon") forState:UIControlStateNormal];
  477. [_radioBtn setBackgroundImage:ImageByName(@"ym_login_auth_selected_icon") forState:UIControlStateSelected];
  478. [[[_radioBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(__kindof UIButton * _Nullable sender) {
  479. sender.selected = !sender.selected;
  480. }];
  481. }
  482. return _radioBtn;
  483. }
  484. - (YYLabel *)agreementLb{
  485. if (!_agreementLb) {
  486. _agreementLb = [[YYLabel alloc] init];
  487. _agreementLb.numberOfLines = 0;
  488. _agreementLb.preferredMaxLayoutWidth = kFrameWidth - adapt(55);
  489. NSString *agreementText = @"登录即代表同意《用户协议》与《隐私政策》";
  490. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
  491. paragraphStyle.alignment = NSTextAlignmentLeft;
  492. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:agreementText];
  493. attributedString.yy_font = LCFont(12);
  494. attributedString.yy_color = HexColorFromRGBA(0x000000,0.65);
  495. attributedString.yy_paragraphStyle = paragraphStyle;
  496. //设置高亮色和点击事件
  497. [attributedString yy_setTextHighlightRange:[agreementText rangeOfString:@"《用户协议》"] color:AGREEMENTColor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  498. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  499. ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserProtocolH5]
  500. }];
  501. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  502. RouterViewModel:webArticleVM
  503. } completion:nil];
  504. }];
  505. //设置高亮色和点击事件
  506. [attributedString yy_setTextHighlightRange:[[attributedString string] rangeOfString:@"《隐私政策》"] color:AGREEMENTColor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
  507. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  508. ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserPrivacyH5]
  509. }];
  510. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  511. RouterViewModel:webArticleVM
  512. } completion:nil];
  513. }];
  514. _agreementLb.attributedText = attributedString;
  515. }
  516. return _agreementLb;
  517. }
  518. @end