LoginBodyView.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // LoginBodyView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/17.
  6. //
  7. #import "LoginBodyView.h"
  8. #import "KeyChainTools.h"
  9. @interface LoginBodyView ()<UITextFieldDelegate>
  10. @property (weak, nonatomic) IBOutlet UILabel *registerProtocalLabel;
  11. @property (weak, nonatomic) IBOutlet UILabel *privacyLabel;
  12. @property (weak, nonatomic) IBOutlet UIButton *sureButton;
  13. @property (nonatomic, assign) BOOL isChooseProtocal;
  14. @property (nonatomic, copy) LoginAction callback;
  15. @property (weak, nonatomic) IBOutlet UILabel *deviceLabel;
  16. @property (nonatomic, assign) NSInteger clickCount;
  17. @end
  18. @implementation LoginBodyView
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. [self configSource];
  22. self.deviceLabel.text = [NSString stringWithFormat:@"本机设备号:%@",[KeyChainTools getUUID]];
  23. self.deviceLabel.hidden = YES;
  24. _clickCount = 0;
  25. }
  26. - (void)configSource {
  27. self.phoneField.delegate = self;
  28. [self.sureButton setImage:[UIImage imageNamed:@"login_unseleted"] forState:UIControlStateNormal];
  29. [self.sureButton setImage:[UIImage imageNamed:@"login_seleted"] forState:UIControlStateSelected];
  30. self.isChooseProtocal = NO;
  31. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"我已阅读并同意《用户注册协议》" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f], NSForegroundColorAttributeName:HexRGB(0x999999)}];
  32. [attr addAttributes:@{NSForegroundColorAttributeName:THEMECOLOR} range:NSMakeRange(7, 8)];
  33. [self.registerProtocalLabel setAttributedText:attr];
  34. NSMutableAttributedString *privacyAttr = [[NSMutableAttributedString alloc] initWithString:@"和《隐私政策》" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f], NSForegroundColorAttributeName:HexRGB(0x999999)}];
  35. [privacyAttr addAttributes:@{NSForegroundColorAttributeName:THEMECOLOR} range:NSMakeRange(1, 6)];
  36. [self.privacyLabel setAttributedText:privacyAttr];
  37. }
  38. + (instancetype)shareInstance {
  39. LoginBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"LoginBodyView" owner:nil options:nil] firstObject];
  40. return view;
  41. }
  42. - (void)loginActionCallback:(LoginAction)callback {
  43. if (callback) {
  44. self.callback = callback;
  45. }
  46. }
  47. - (IBAction)getVefiCode:(id)sender {
  48. [self endEditing:YES];
  49. if ([NSString isEmptyString:self.phoneField.text]) {
  50. // 请输入手机号
  51. [self MBPShow:@"请输入手机号"];
  52. return;
  53. }
  54. if (_isChooseProtocal == NO) {
  55. [self MBPShow:@"请勾选用户协议"];
  56. return;
  57. }
  58. if (self.callback) {
  59. self.callback(LOGINACTION_CODE, self.phoneField.text);
  60. }
  61. }
  62. - (IBAction)selectButtonAction:(id)sender {
  63. [self endEditing:YES];
  64. self.sureButton.selected = !self.sureButton.selected;
  65. _isChooseProtocal = self.sureButton.isSelected;
  66. }
  67. - (IBAction)passwordLogin:(id)sender {
  68. [self endEditing:YES];
  69. if (self.callback) {
  70. self.callback(LOGINACTION_PASSWORD, self.phoneField.text);
  71. }
  72. }
  73. - (IBAction)registerProtocal:(id)sender {
  74. [self endEditing:YES];
  75. if (self.callback) {
  76. self.callback(LOGINACTION_REGPROTOCAL, @"");
  77. }
  78. }
  79. - (IBAction)privacyAction:(id)sender {
  80. [self endEditing:YES];
  81. if (self.callback) {
  82. self.callback(LOGINACTION_PRIVACY, @"");
  83. }
  84. }
  85. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  86. if ([string isEqualToString:@"\n"]) {
  87. [self endEditing:YES];
  88. return YES;
  89. }
  90. // 输入控制
  91. NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  92. if (newString.length > 11) {
  93. return NO;
  94. }
  95. return YES;
  96. }
  97. - (IBAction)tapAction:(id)sender {
  98. _clickCount++;
  99. if (_clickCount == 5) {
  100. self.deviceLabel.text = [NSString stringWithFormat:@"本机设备号:%@",[KeyChainTools getUUID]];
  101. self.deviceLabel.hidden = NO;
  102. }
  103. }
  104. - (IBAction)copyAction:(id)sender {
  105. // 复制
  106. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  107. pasteboard.string = [KeyChainTools getUUID];
  108. [self MBPShow:@"复制成功"];
  109. }
  110. /*
  111. // Only override drawRect: if you perform custom drawing.
  112. // An empty implementation adversely affects performance during animation.
  113. - (void)drawRect:(CGRect)rect {
  114. // Drawing code
  115. }
  116. */
  117. @end