GCoverController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. //
  2. // GCoverController.m
  3. // aiim
  4. //
  5. // Created by gan on 2025/2/28.
  6. //
  7. #import "GCoverController.h"
  8. #import "UserNetApi.h"
  9. #import "UDManager.h"
  10. @interface GCoverController ()
  11. @property (nonatomic, strong) UILabel * titleLbl;
  12. @property (nonatomic, strong) UIButton * leftBtn;
  13. @property (nonatomic, strong) UIStackView * titleStackView;
  14. @property (nonatomic, strong) UILabel * nameTitleLbl;
  15. @property (nonatomic, strong) UILabel * resePwdTitleLbl;
  16. @property (nonatomic, strong) UILabel * confirmPwdTitleLbl;
  17. @property (nonatomic, strong) UILabel * codeTitleLbl;
  18. @property (nonatomic, strong) UITextField * nameTextfield;
  19. @property (nonatomic, strong) UITextField * resetPwdTextfield;
  20. @property (nonatomic, strong) UITextField * confirmPwdTextfield;
  21. @property (nonatomic, strong) UITextField * codeTextfield;
  22. @property (nonatomic, strong) UIButton * getCodeBtn;
  23. @property (nonatomic, strong) UIButton * saveBtn;
  24. @property (nonatomic, strong) NSMutableArray * titles;
  25. @property (nonatomic, strong) NSMutableDictionary * userInfo;
  26. @property (nonatomic, strong) NSTimer *timer;
  27. @property (nonatomic, assign) NSInteger remainingSeconds;
  28. @end
  29. @implementation GCoverController
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. // Do any additional setup after loading the view.
  33. NSLog(@"GCoverController viewDidLoad");
  34. [self configUI];
  35. }
  36. #pragma mark UI
  37. - (void)configUI{
  38. // self.view.backgroundColor = UIColor.blackColor;
  39. UIImageView * bgImageView = [[UIImageView alloc] initWithImage:kImageMake(@"loginBG")];
  40. [self.view addSubview:bgImageView];
  41. [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.right.top.bottom.mas_equalTo(0);
  43. }];
  44. if (self.isLogin) {
  45. [self.titles addObjectsFromArray:@[self.resePwdTitleLbl,self.confirmPwdTitleLbl,self.codeTitleLbl]];
  46. }else{
  47. [self.titles addObjectsFromArray:@[self.nameTitleLbl,self.resePwdTitleLbl,self.confirmPwdTitleLbl,self.codeTitleLbl]];
  48. }
  49. [self.view addSubview:self.titleLbl];
  50. [self.titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.height.mas_equalTo(16);
  52. make.centerX.mas_equalTo(self.view.mas_centerX);
  53. make.top.mas_equalTo(STATUS_Height+16);
  54. }];
  55. [self.view addSubview:self.leftBtn];
  56. [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.size.mas_equalTo(CGSizeMake(20, 20));
  58. make.left.mas_equalTo(20);
  59. make.centerY.mas_equalTo(self.titleLbl.mas_centerY);
  60. }];
  61. [self.view addSubview:self.titleStackView];
  62. [self.titleStackView mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.height.mas_equalTo(16*self.titles.count + 64*(self.titles.count-1) + 32);
  64. make.left.mas_equalTo(20);
  65. make.top.mas_equalTo(self.titleLbl.mas_bottom).offset(32);
  66. }];
  67. if (!self.isLogin) {
  68. [self.view addSubview:self.nameTextfield];
  69. [self.nameTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.height.mas_equalTo(50);
  71. make.left.mas_equalTo(104);
  72. make.right.mas_equalTo(-20);
  73. make.centerY.mas_equalTo(self.nameTitleLbl.mas_centerY);
  74. }];
  75. }
  76. [self.view addSubview:self.resetPwdTextfield];
  77. [self.resetPwdTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.height.mas_equalTo(50);
  79. make.left.mas_equalTo(104);
  80. make.right.mas_equalTo(-20);
  81. make.centerY.mas_equalTo(self.resePwdTitleLbl.mas_centerY);
  82. }];
  83. [self.view addSubview:self.confirmPwdTextfield];
  84. [self.confirmPwdTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.height.mas_equalTo(50);
  86. make.left.mas_equalTo(104);
  87. make.right.mas_equalTo(-20);
  88. make.centerY.mas_equalTo(self.confirmPwdTitleLbl.mas_centerY);
  89. }];
  90. [self.view addSubview:self.codeTextfield];
  91. [self.codeTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.height.mas_equalTo(50);
  93. make.left.mas_equalTo(104);
  94. make.right.mas_equalTo(-20);
  95. make.centerY.mas_equalTo(self.codeTitleLbl.mas_centerY);
  96. }];
  97. [self.view addSubview:self.getCodeBtn];
  98. [self.getCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  99. make.size.mas_equalTo(CGSizeMake(125, 46));
  100. make.right.mas_equalTo(-20);
  101. make.top.mas_equalTo(self.codeTextfield.mas_bottom).offset(30);
  102. }];
  103. [self.view addSubview:self.saveBtn];
  104. [self.saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.height.mas_equalTo(46);
  106. make.left.mas_equalTo(20);
  107. make.right.mas_equalTo(-20);
  108. make.top.mas_equalTo(self.getCodeBtn.mas_bottom).offset(30);
  109. }];
  110. }
  111. #pragma mark event
  112. - (void)leftButtonClicked{
  113. [self dismissViewControllerAnimated:YES completion:nil];
  114. }
  115. - (void)getCodeButtonClicked{
  116. if (self.nameTextfield.text.length == 0 && !self.isLogin) {
  117. [MBProgressHUD showWithText:NSLocalizedString(@"Sign-usernme-note", @"")];
  118. return;
  119. }
  120. //发送验证码
  121. [UserNetApi getEmailcodereset:self.isLogin ? self.userInfo[@"username"] : self.nameTextfield.text succ:^(int code, NSDictionary * _Nullable res) {
  122. NSLog(@"result:%@",res);
  123. if ([res jk_hasKey:@"code"] && [res[@"code"] isEqual: @200]) {
  124. // 开始倒计时
  125. self.remainingSeconds = 60;
  126. [self startTimer];
  127. // 禁用按钮并改变样式
  128. self.getCodeBtn.enabled = NO;
  129. [self.getCodeBtn setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled];
  130. [self.getCodeBtn setTitle:[NSString stringWithFormat:@"%@(%ld)",NSLocalizedString(@"Sign-wangjimm", @"验证码"), (long)self.remainingSeconds] forState:UIControlStateDisabled];
  131. // [AlertHelper showAlertWithTitle:@"" message:NSLocalizedString(@"Sign-yanzhengmts", @"") cancelButtonTitle:NSLocalizedString(@"Common_getIt", @"") confirmButtonTitle:nil completion:^(NSInteger buttonIndex) {
  132. // [self.codeTextfield becomeFirstResponder];
  133. // }];
  134. }else{
  135. [MBProgressHUD showWithText:res[@"msg"]];
  136. }
  137. } fail:^(NSError * _Nonnull error) {
  138. NSLog(@"error:%@",error);
  139. [MBProgressHUD showWithText:NSLocalizedString(@"Login_network_alter", @"")];
  140. }];
  141. }
  142. - (void)saveButtonClicked{
  143. if (self.nameTextfield.text.length == 0 && !self.isLogin) {
  144. [MBProgressHUD showWithText:NSLocalizedString(@"login-usernme-note", @"")];
  145. return;
  146. }
  147. if (self.resetPwdTextfield.text.length == 0) {
  148. [MBProgressHUD showWithText:NSLocalizedString(@"Security_newPassword_alter", @"")];
  149. return;
  150. }
  151. if (![self.confirmPwdTextfield.text isEqualToString:self.resetPwdTextfield.text]) {
  152. [MBProgressHUD showWithText:NSLocalizedString(@"PwdChange_passwordsDifferent_alter", @"")];
  153. return;
  154. }
  155. if (self.codeTextfield.text.length == 0) {
  156. [MBProgressHUD showWithText:NSLocalizedString(@"Sign-qingsryzm", @"")];
  157. return;
  158. }
  159. NSDictionary * param = @{
  160. @"username": self.isLogin ? self.userInfo[@"username"] : self.nameTextfield.text, //用户名
  161. @"password": self.resetPwdTextfield.text, //用户密码
  162. @"code": self.codeTextfield.text, //验证码
  163. @"uuid": @"" //唯一标识
  164. };
  165. [UserNetApi resetPassword:param succ:^(int code, NSDictionary * _Nullable res) {
  166. NSLog(@"result:%@",res);
  167. if ([res jk_hasKey:@"msg"]) {
  168. [MBProgressHUD showWithText:res[@"msg"]];
  169. }
  170. if ([res jk_hasKey:@"code"] && [res[@"code"] integerValue] == 200 && self.isLogin) {
  171. //退出登录
  172. //[[LoginStateManager sharedManager] logout];
  173. }
  174. } fail:^(NSError * _Nonnull error) {
  175. NSLog(@"error:%@",error);
  176. }];
  177. }
  178. #pragma mark timer
  179. - (void)startTimer {
  180. if (!self.timer) {
  181. self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0
  182. target:self
  183. selector:@selector(updateTimer:)
  184. userInfo:nil
  185. repeats:YES];
  186. [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
  187. }
  188. }
  189. - (void)updateTimer:(NSTimer *)timer {
  190. self.remainingSeconds--;
  191. if (self.remainingSeconds <= 0) {
  192. [self stopTimer];
  193. // 恢复按钮状态
  194. self.getCodeBtn.enabled = YES;
  195. [self.getCodeBtn setTitle:NSLocalizedString(@"Sign-huoquyzm", @"") forState:UIControlStateNormal];
  196. } else {
  197. [self.getCodeBtn setTitle:[NSString stringWithFormat:@"%@(%ld)",NSLocalizedString(@"Sign-wangjimm", @"验证码"), (long)self.remainingSeconds] forState:UIControlStateDisabled];
  198. }
  199. }
  200. - (void)stopTimer {
  201. if (self.timer) {
  202. [self.timer invalidate];
  203. self.timer = nil;
  204. }
  205. }
  206. - (void)dealloc {
  207. [self stopTimer];
  208. }
  209. #pragma mark lazy
  210. - (UILabel *)titleLbl{
  211. if (!_titleLbl) {
  212. _titleLbl = [[UILabel alloc] init];
  213. _titleLbl.text = NSLocalizedString(@"userCenter-chongzhimm", @"");
  214. _titleLbl.textColor = UIColor.whiteColor;
  215. _titleLbl.font = SYSMFONT(16);
  216. _titleLbl.textAlignment = NSTextAlignmentCenter;
  217. }
  218. return _titleLbl;
  219. }
  220. - (UIButton *)leftBtn{
  221. if (!_leftBtn) {
  222. _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  223. [_leftBtn setImage:kImageMake(@"fanhui") forState:UIControlStateNormal];
  224. [_leftBtn addTarget:nil action:@selector(leftButtonClicked) forControlEvents:UIControlEventTouchUpInside];
  225. // [_leftBtn jk_addActionHandler:^(NSInteger tag) {
  226. // [self leftButtonClicked];
  227. // }];
  228. }
  229. return _leftBtn;
  230. }
  231. - (UIStackView *)titleStackView{
  232. if (!_titleStackView) {
  233. _titleStackView = [[UIStackView alloc] initWithArrangedSubviews:self.titles];
  234. _titleStackView.axis = UILayoutConstraintAxisVertical;
  235. _titleStackView.alignment = UIStackViewAlignmentFill;
  236. _titleStackView.distribution = UIStackViewDistributionEqualSpacing;
  237. _titleStackView.spacing = 64;
  238. }
  239. return _titleStackView;
  240. }
  241. - (UILabel *)nameTitleLbl{
  242. if (!_nameTitleLbl) {
  243. _nameTitleLbl = [[UILabel alloc] init];
  244. _nameTitleLbl.text = NSLocalizedString(@"UserInfo_userName", @"");
  245. _nameTitleLbl.textColor = UIColor.whiteColor;
  246. _nameTitleLbl.font = SYSFONT(16);
  247. }
  248. return _nameTitleLbl;
  249. }
  250. - (UILabel *)resePwdTitleLbl{
  251. if (!_resePwdTitleLbl) {
  252. _resePwdTitleLbl = [[UILabel alloc] init];
  253. _resePwdTitleLbl.text = NSLocalizedString(@"PwdChange_newPassword", @"");
  254. _resePwdTitleLbl.textColor = UIColor.whiteColor;
  255. _resePwdTitleLbl.font = SYSFONT(16);
  256. }
  257. return _resePwdTitleLbl;
  258. }
  259. - (UILabel *)confirmPwdTitleLbl{
  260. if (!_confirmPwdTitleLbl) {
  261. _confirmPwdTitleLbl = [[UILabel alloc] init];
  262. _confirmPwdTitleLbl.text = NSLocalizedString(@"PwdChange_confirmPassword", @"");
  263. _confirmPwdTitleLbl.textColor = UIColor.whiteColor;
  264. _confirmPwdTitleLbl.font = SYSFONT(16);
  265. }
  266. return _confirmPwdTitleLbl;
  267. }
  268. - (UILabel *)codeTitleLbl{
  269. if (!_codeTitleLbl) {
  270. _codeTitleLbl = [[UILabel alloc] init];
  271. _codeTitleLbl.text = NSLocalizedString(@"Sign-wangjimm", @"");
  272. _codeTitleLbl.textColor = UIColor.whiteColor;
  273. _codeTitleLbl.font = SYSFONT(16);
  274. }
  275. return _codeTitleLbl;
  276. }
  277. - (NSMutableArray *)titles{
  278. if (!_titles) {
  279. _titles = [NSMutableArray array];
  280. }
  281. return _titles;
  282. }
  283. - (NSMutableDictionary *)userInfo{
  284. if (!_userInfo) {
  285. _userInfo = [NSMutableDictionary dictionaryWithDictionary:[UDManager.shareInstance getDDManager:dkuserinfo]];
  286. }
  287. return _userInfo;
  288. }
  289. - (UITextField *)nameTextfield{
  290. if (!_nameTextfield) {
  291. _nameTextfield = [[UITextField alloc] init];
  292. _nameTextfield.textColor = UIColor.whiteColor;
  293. _nameTextfield.borderStyle = UITextBorderStyleNone;
  294. _nameTextfield.layer.borderWidth = 1.f;
  295. _nameTextfield.layer.borderColor = globalColor(GCTypeDark2).CGColor;
  296. _nameTextfield.layer.cornerRadius = 5.f;
  297. _nameTextfield.leftViewMode = UITextFieldViewModeAlways;
  298. UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 50)];
  299. _nameTextfield.leftView = leftView;
  300. }
  301. return _nameTextfield;
  302. }
  303. - (UITextField *)resetPwdTextfield{
  304. if (!_resetPwdTextfield) {
  305. _resetPwdTextfield = [[UITextField alloc] init];
  306. _resetPwdTextfield.textColor = UIColor.whiteColor;
  307. _resetPwdTextfield.borderStyle = UITextBorderStyleNone;
  308. _resetPwdTextfield.layer.borderWidth = 1.f;
  309. _resetPwdTextfield.layer.borderColor = globalColor(GCTypeDark2).CGColor;
  310. _resetPwdTextfield.layer.cornerRadius = 5.f;
  311. _resetPwdTextfield.secureTextEntry = YES;
  312. _resetPwdTextfield.leftViewMode = UITextFieldViewModeAlways;
  313. UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 50)];
  314. _resetPwdTextfield.leftView = leftView;
  315. }
  316. return _resetPwdTextfield;
  317. }
  318. - (UITextField *)confirmPwdTextfield{
  319. if (!_confirmPwdTextfield) {
  320. _confirmPwdTextfield = [[UITextField alloc] init];
  321. _confirmPwdTextfield.textColor = UIColor.whiteColor;
  322. _confirmPwdTextfield.borderStyle = UITextBorderStyleNone;
  323. _confirmPwdTextfield.layer.borderWidth = 1.f;
  324. _confirmPwdTextfield.layer.borderColor = globalColor(GCTypeDark2).CGColor;
  325. _confirmPwdTextfield.layer.cornerRadius = 5.f;
  326. _confirmPwdTextfield.secureTextEntry = YES;
  327. _confirmPwdTextfield.leftViewMode = UITextFieldViewModeAlways;
  328. UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 50)];
  329. _confirmPwdTextfield.leftView = leftView;
  330. }
  331. return _confirmPwdTextfield;
  332. }
  333. - (UITextField *)codeTextfield{
  334. if (!_codeTextfield) {
  335. _codeTextfield = [[UITextField alloc] init];
  336. _codeTextfield.textColor = UIColor.whiteColor;
  337. _codeTextfield.borderStyle = UITextBorderStyleNone;
  338. _codeTextfield.layer.borderWidth = 1.f;
  339. _codeTextfield.layer.borderColor = globalColor(GCTypeDark2).CGColor;
  340. _codeTextfield.layer.cornerRadius = 5.f;
  341. _codeTextfield.leftViewMode = UITextFieldViewModeAlways;
  342. UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 50)];
  343. _codeTextfield.leftView = leftView;
  344. _codeTextfield.keyboardType = UIKeyboardTypeNumberPad;
  345. }
  346. return _codeTextfield;
  347. }
  348. - (UIButton *)getCodeBtn{
  349. if (!_getCodeBtn) {
  350. _getCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  351. [_getCodeBtn setBackgroundColor:globalColor(GCTypeGreen)];
  352. [_getCodeBtn setTitle:NSLocalizedString(@"Sign-huoquyzm", @"") forState:UIControlStateNormal];
  353. [_getCodeBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
  354. _getCodeBtn.titleLabel.font = SYSMFONT(14);
  355. _getCodeBtn.layer.cornerRadius = 5.f;
  356. _getCodeBtn.layer.masksToBounds = YES;
  357. [_getCodeBtn addTarget:nil action:@selector(getCodeButtonClicked) forControlEvents:UIControlEventTouchUpInside];
  358. // [_getCodeBtn jk_addActionHandler:^(NSInteger tag) {
  359. // [self getCodeButtonClicked];
  360. // }];
  361. }
  362. return _getCodeBtn;
  363. }
  364. - (UIButton *)saveBtn{
  365. if (!_saveBtn) {
  366. _saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  367. [_saveBtn setBackgroundColor:globalColor(GCTypeGreen)];
  368. [_saveBtn setTitle:NSLocalizedString(@"EGroupCtr-baocun", @"") forState:UIControlStateNormal];
  369. [_saveBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
  370. _saveBtn.titleLabel.font = SYSMFONT(16);
  371. _saveBtn.layer.cornerRadius = 5.f;
  372. _saveBtn.layer.masksToBounds = YES;
  373. [_saveBtn addTarget:nil action:@selector(saveButtonClicked) forControlEvents:UIControlEventTouchUpInside];
  374. }
  375. return _saveBtn;
  376. }
  377. #pragma mark statusBar
  378. - (UIStatusBarStyle)preferredStatusBarStyle{
  379. return UIStatusBarStyleLightContent;
  380. }
  381. @end